improve editing profiles

This commit is contained in:
MathMan05 committed 2026-05-10 15:21:47 -05:00
1 parent eedffa0ad5
commit c6b444c4fd
4 files changed
+46 -19

No files matched your search

+1
View File
@@ -3974,3 +3974,4 @@ class Channel extends SnowFlake {
}
Channel.setupcontextmenu();
export {Channel};
+17 -7
View File
@@ -2351,18 +2351,28 @@ class Localuser {
if (!channel) return;
channel.typingStart(typing);
}
updatepfp(file: Blob): void {
const reader = new FileReader();
reader.readAsDataURL(file);
reader.onload = () => {
updatepfp(file: Blob | null): void {
if (file) {
const reader = new FileReader();
reader.readAsDataURL(file);
reader.onload = () => {
fetch(this.info.api + "/users/@me", {
method: "PATCH",
headers: this.headers,
body: JSON.stringify({
avatar: reader.result,
}),
});
};
} else {
fetch(this.info.api + "/users/@me", {
method: "PATCH",
headers: this.headers,
body: JSON.stringify({
avatar: reader.result,
avatar: null,
}),
});
};
}
}
updatebanner(file: Blob | null): void {
if (file) {
@@ -2437,7 +2447,7 @@ class Localuser {
const finput = settingsLeft.addImageInput(
I18n.uploadPfp(),
(_) => {
if (file) {
if (file !== undefined) {
this.updatepfp(file);
}
},
+27 -11
View File
@@ -118,18 +118,28 @@ class Member extends SnowFlake {
return this.owner.headers;
}
updatepfp(file: Blob): void {
updatepfp(file: Blob | null): void {
const reader = new FileReader();
reader.readAsDataURL(file);
reader.onload = () => {
if (file) {
reader.readAsDataURL(file);
reader.onload = () => {
fetch(this.info.api + `/guilds/${this.guild.id}/members/${this.id}/`, {
method: "PATCH",
headers: this.headers,
body: JSON.stringify({
avatar: reader.result,
}),
});
};
} else {
fetch(this.info.api + `/guilds/${this.guild.id}/members/${this.id}/`, {
method: "PATCH",
headers: this.headers,
body: JSON.stringify({
avatar: reader.result,
avatar: null,
}),
});
};
}
}
updatebanner(file: Blob | null): void {
if (file) {
@@ -201,7 +211,7 @@ class Member extends SnowFlake {
editProfile(options: Options) {
if (this.hasPermission("CHANGE_NICKNAME")) {
const hypotheticalProfile = document.createElement("div");
let file: undefined | File | null;
let file: undefined | File | null = undefined;
let newpronouns: string | undefined;
let newbio: string | undefined;
let nick: string | undefined;
@@ -228,14 +238,14 @@ class Member extends SnowFlake {
regen();
});
const finput = settingsLeft.addFileInput(
const finput = settingsLeft.addImageInput(
I18n.uploadPfp(),
(_) => {
if (file) {
if (file !== undefined) {
this.updatepfp(file);
}
},
{clear: true},
{clear: true, initImg: this.avatar ? this.getpfpsrc() : undefined},
);
finput.watchForChange((_) => {
if (!_) {
@@ -250,18 +260,24 @@ class Member extends SnowFlake {
const blob = URL.createObjectURL(file);
hypomember.avatar = blob;
hypomember.hypotheticalpfp = true;
console.log(hypomember.getpfpsrc());
regen();
}
});
let bfile: undefined | File | null;
const binput = settingsLeft.addFileInput(
const binput = settingsLeft.addImageInput(
I18n.uploadBanner(),
(_) => {
if (bfile !== undefined) {
this.updatebanner(bfile);
}
},
{clear: true},
{
clear: true,
width: 96 * 3,
initImg: this.banner ? this.getBannerUrl() : "",
objectFit: "cover",
},
);
binput.watchForChange((_) => {
if (!_) {
+1 -1
View File
@@ -896,7 +896,7 @@ class User extends SnowFlake {
return has;
}
buildstatuspfp(guild: Guild | void | Member | null | Channel): HTMLDivElement {
const isChannel = !!(guild && "guild" in guild);
const isChannel = !!(guild && "guild" in guild && !(guild instanceof Member));
const div = this.buildpfp(isChannel ? guild.guild : guild);
const status = document.createElement("div");