diff --git a/src/webpage/jsontypes.ts b/src/webpage/jsontypes.ts index 78c0892..b7d8bde 100644 --- a/src/webpage/jsontypes.ts +++ b/src/webpage/jsontypes.ts @@ -936,7 +936,7 @@ type wsjson = } | { op: 0; - t: "RELATIONSHIP_MODIFY"; + t: "RELATIONSHIP_UPDATE"; d: relationJson; s: number; } diff --git a/src/webpage/localuser.ts b/src/webpage/localuser.ts index 6c97a8d..0223132 100644 --- a/src/webpage/localuser.ts +++ b/src/webpage/localuser.ts @@ -908,14 +908,16 @@ class Localuser { guild.memberupdate(temp.d); break; } - case "RELATIONSHIP_MODIFY": + case "RELATIONSHIP_UPDATE": case "RELATIONSHIP_ADD": { - const user = new User(temp.d.user, this); - user.handleRelationship(temp.d); - this.relationshipsUpdate(); - const me = this.guildids.get("@me"); - if (!me) break; - me.unreads(); + (async () => { + const user = temp.d.user ? new User(temp.d.user, this) : await this.getUser(temp.d.id); + user.handleRelationship(temp.d); + this.relationshipsUpdate(); + const me = this.guildids.get("@me"); + if (!me) return; + me.unreads(); + })(); break; } case "RELATIONSHIP_REMOVE": { diff --git a/src/webpage/member.ts b/src/webpage/member.ts index 17340e4..496fa6b 100644 --- a/src/webpage/member.ts +++ b/src/webpage/member.ts @@ -172,6 +172,7 @@ class Member extends SnowFlake { this.editProfile(settings.addButton(I18n.user.editServerProfile(), {ltr: true})); settings.show(); } + showEditNick() { const dio = new Dialog(""); const form = dio.options.addForm( diff --git a/src/webpage/user.ts b/src/webpage/user.ts index 8bf9e0f..2efd360 100644 --- a/src/webpage/user.ts +++ b/src/webpage/user.ts @@ -38,6 +38,9 @@ class User extends SnowFlake { members: WeakMap> = new WeakMap(); status!: string; resolving: false | Promise = false; + get headers() { + return this.localuser.headers; + } constructor(userjson: userjson, owner: Localuser, dontclone: boolean = false) { super(userjson.id); @@ -341,6 +344,30 @@ class User extends SnowFlake { }, }, ); + this.contextmenu.addButton( + function () { + switch (this.relationshipType) { + case 1: + return I18n.user.nick.friend(); + case 2: + return I18n.user.nick.foe(); + case 3: + return I18n.user.nick.stalker(); + case 4: + return I18n.user.nick.stalking(); + default: + return "You shouldn't see this"; + } + }, + function (this: User) { + this.setFriendNick(); + }, + { + visable: function () { + return new Set([1, 2, 3, 4]).has(this.relationshipType); + }, + }, + ); this.contextmenu.addSeperator(); @@ -565,6 +592,24 @@ class User extends SnowFlake { ); console.warn("this ran"); } + setFriendNick() { + const dio = new Dialog(""); + const form = dio.options.addForm( + "", + () => { + dio.hide(); + }, + { + fetchURL: this.info.api + `/users/@me/relationships/${this.id}`, + method: "PATCH", + headers: this.headers, + }, + ); + form.addTextInput(I18n.member["nick:"](), "nickname", { + initText: this.nickname || "", + }); + dio.show(); + } getMembersSync() { return this.localuser.guilds .map((guild) => { @@ -616,7 +661,7 @@ class User extends SnowFlake { } get name() { - return this.relationshipType === 2 ? I18n.friends.bu() : this.username; + return this.nickname || (this.relationshipType === 2 ? I18n.friends.bu() : this.username); } async resolvemember(guild: Guild): Promise { @@ -994,14 +1039,22 @@ class User extends SnowFlake { ).json()) as highMemberJSON; } handleRelationship(relation: relationJson) { + const nickChange = this.nickname !== relation.nickname; this.nickname = relation.nickname; this.relationshipType = relation.type; this.localuser.inrelation.add(this); + if (nickChange) { + this.nameChange(); + } } removeRelation() { + const nickChange = this.nickname; this.nickname = null; this.relationshipType = 0; this.localuser.inrelation.delete(this); + if (nickChange) { + this.nameChange(); + } } async fullProfile(guild: Guild | null | Member = null) { console.log(guild); diff --git a/translations/en.json b/translations/en.json index ba9a857..dcd89b7 100644 --- a/translations/en.json +++ b/translations/en.json @@ -717,7 +717,13 @@ "instanceBan": "Instance ban", "confirmInstBan": "Are you sure you want to instance ban $1?", "unban": "Unban $1", - "remove":"Remove user" + "remove":"Remove user", + "nick":{ + "friend":"Set friend nickname", + "foe":"Set foe nickname", + "stalker":"Set nickname of requester", + "stalking":"Set nickname of requested" + } }, "loaded":"Loaded", "login": {