fixed the typing indicator

This commit is contained in:
MathMan05 2024-08-14 17:00:56 -05:00
parent 1f8e173e76
commit b43c9e7f4f
6 changed files with 63 additions and 46 deletions

View file

@ -30,7 +30,7 @@ class Localuser {
lookingguild;
guildhtml;
ws;
typing;
typing = new Map();
connectionSucceed = 0;
errorBackoff = 0;
mfa_enabled;
@ -89,7 +89,6 @@ class Localuser {
const guildid = guild.snowflake;
this.guildids.get(guildid.id).channelids[thing.channel_id].readStateInfo(thing);
}
this.typing = [];
}
outoffocus() {
document.getElementById("servers").innerHTML = "";
@ -583,11 +582,12 @@ class Localuser {
thing.unreads(html);
}
}
typingStart(typing) {
if (this.channelfocus.snowflake === typing.d.channel_id) {
const memb = typing.d.member;
async typingStart(typing) {
if (this.channelfocus.id === typing.d.channel_id) {
const guild = SnowFlake.getSnowFlakeFromID(typing.d.guild_id, Guild).getObject();
const memb = await Member.new(typing.d.member, guild);
let name;
if (memb.id === this.user.snowflake) {
if (memb.id === this.user.id) {
console.log("you is typing");
return;
}
@ -607,7 +607,7 @@ class Localuser {
}
}
if (!already) {
this.typing.push([name, new Date().getTime()]);
this.typing.set(memb, new Date().getTime());
}
setTimeout(this.rendertyping.bind(this), 10000);
this.rendertyping();
@ -636,18 +636,25 @@ class Localuser {
rendertyping() {
const typingtext = document.getElementById("typing");
let build = "";
const array2 = [];
let showing = false;
let i = 0;
for (const thing of this.typing) {
i++;
if (thing[1] > new Date().getTime() - 5000) {
build += thing[0];
array2.push(thing);
showing = true;
if (i !== this.typing.length) {
build += ",";
const curtime = new Date().getTime() - 5000;
for (const thing of this.typing.keys()) {
if (this.typing.get(thing) > curtime) {
if (i !== 0) {
build += ", ";
}
i++;
if (thing.nick) {
build += thing.nick;
}
else {
build += thing.user.username;
}
showing = true;
}
else {
this.typing.delete(thing);
}
}
if (i > 1) {