clean up relationships

This commit is contained in:
MathMan05 committed 2025-12-17 15:12:11 -06:00
1 parent 4129d259c6
commit 711d74e95e
3 files changed
+32 -28

No files matched your search

+15 -16
View File
@@ -46,12 +46,7 @@ interface readyjson {
};
auth_token?: string;
guilds: guildjson[];
relationships: {
id: string;
type: 0 | 1 | 2 | 3 | 4;
nickname: string | null;
user: userjson;
}[];
relationships: relationJson[];
read_state: {
entries: {
id: string;
@@ -798,6 +793,12 @@ type messageCreateJson = {
s: number;
t: "MESSAGE_CREATE";
};
export interface relationJson {
id: string;
type: 0 | 1 | 2 | 3 | 4;
nickname: string | null;
user: userjson;
}
type roleCreate = {
op: 0;
t: "GUILD_ROLE_CREATE";
@@ -924,21 +925,19 @@ type wsjson =
| {
op: 0;
t: "RELATIONSHIP_ADD";
d: {
id: string;
type: 0 | 1 | 2 | 3 | 4 | 5 | 6;
user: userjson;
};
d: relationJson;
s: number;
}
| {
op: 0;
t: "RELATIONSHIP_REMOVE";
d: {
id: string;
type: number;
nickname: null;
};
d: relationJson;
s: number;
}
| {
op: 0;
t: "RELATIONSHIP_MODIFY";
d: relationJson;
s: number;
}
| {
+6 -11
View File
@@ -400,11 +400,9 @@ class Localuser {
channel.readStateInfo(thing);
}
}
for (const thing of ready.d.relationships) {
const user = new User(thing.user, this);
user.nickname = thing.nickname;
user.relationshipType = thing.type;
this.inrelation.add(user);
for (const relationship of ready.d.relationships) {
const user = new User(relationship.user, this);
user.handleRelationship(relationship);
}
this.pingEndpoint();
@@ -910,11 +908,10 @@ class Localuser {
guild.memberupdate(temp.d);
break;
}
case "RELATIONSHIP_MODIFY":
case "RELATIONSHIP_ADD": {
const user = new User(temp.d.user, this);
user.nickname = null;
user.relationshipType = temp.d.type;
this.inrelation.add(user);
user.handleRelationship(temp.d);
this.relationshipsUpdate();
const me = this.guildids.get("@me");
if (!me) break;
@@ -924,9 +921,7 @@ class Localuser {
case "RELATIONSHIP_REMOVE": {
const user = this.userMap.get(temp.d.id);
if (!user) return;
user.nickname = null;
user.relationshipType = 0;
this.inrelation.delete(user);
user.removeRelation();
this.relationshipsUpdate();
break;
}
+11 -1
View File
@@ -4,7 +4,7 @@ import {Contextmenu} from "./contextmenu.js";
import {Localuser} from "./localuser.js";
import {Guild} from "./guild.js";
import {SnowFlake} from "./snowflake.js";
import {highMemberJSON, presencejson, userjson, webhookInfo} from "./jsontypes.js";
import {highMemberJSON, presencejson, relationJson, userjson, webhookInfo} from "./jsontypes.js";
import {Role} from "./role.js";
import {Search} from "./search.js";
import {I18n} from "./i18n.js";
@@ -993,6 +993,16 @@ class User extends SnowFlake {
)
).json()) as highMemberJSON;
}
handleRelationship(relation: relationJson) {
this.nickname = relation.nickname;
this.relationshipType = relation.type;
this.localuser.inrelation.add(this);
}
removeRelation() {
this.nickname = null;
this.relationshipType = 0;
this.localuser.inrelation.delete(this);
}
async fullProfile(guild: Guild | null | Member = null) {
console.log(guild);
const membres = (async () => {