diff --git a/src/webpage/jsontypes.ts b/src/webpage/jsontypes.ts index 20d48e0..78c0892 100644 --- a/src/webpage/jsontypes.ts +++ b/src/webpage/jsontypes.ts @@ -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; } | { diff --git a/src/webpage/localuser.ts b/src/webpage/localuser.ts index 9160cf4..6c97a8d 100644 --- a/src/webpage/localuser.ts +++ b/src/webpage/localuser.ts @@ -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; } diff --git a/src/webpage/user.ts b/src/webpage/user.ts index 99b3c2b..8bf9e0f 100644 --- a/src/webpage/user.ts +++ b/src/webpage/user.ts @@ -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 () => {