friend nicks

This commit is contained in:
MathMan05
2025-12-17 15:31:04 -06:00
parent 711d74e95e
commit e90488afa2
5 changed files with 72 additions and 10 deletions

View File

@@ -936,7 +936,7 @@ type wsjson =
}
| {
op: 0;
t: "RELATIONSHIP_MODIFY";
t: "RELATIONSHIP_UPDATE";
d: relationJson;
s: number;
}

View File

@@ -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": {

View File

@@ -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(

View File

@@ -38,6 +38,9 @@ class User extends SnowFlake {
members: WeakMap<Guild, Member | undefined | Promise<Member | undefined>> = new WeakMap();
status!: string;
resolving: false | Promise<any> = 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<Member | undefined> {
@@ -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);

View File

@@ -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": {