fix typing indicators

This commit is contained in:
MathMan05 2024-09-07 18:00:54 -05:00
parent a4fbc0ca6a
commit dc5b38eb21
6 changed files with 127 additions and 107 deletions

View file

@ -9,6 +9,7 @@ import { RoleList } from "./role.js";
import { InfiniteScroller } from "./infiniteScroller.js";
import { SnowFlake } from "./snowflake.js";
import { MarkDown } from "./markdown.js";
import { Member } from "./member.js";
class Channel extends SnowFlake {
editing;
type;
@ -677,6 +678,7 @@ class Channel extends SnowFlake {
const loading = document.getElementById("loadingdiv");
Channel.regenLoadingMessages();
loading.classList.add("loading");
this.rendertyping();
await this.putmessages();
await prom;
if (id !== Channel.genid) {
@ -687,6 +689,61 @@ class Channel extends SnowFlake {
//loading.classList.remove("loading");
document.getElementById("typebox").contentEditable = "" + this.canMessage;
}
typingmap = new Map();
async typingStart(typing) {
const memb = await Member.new(typing.d.member, this.guild);
if (!memb)
return;
if (memb.id === this.localuser.user.id) {
console.log("you is typing");
return;
}
console.log("user is typing and you should see it");
this.typingmap.set(memb, Date.now());
setTimeout(this.rendertyping.bind(this), 10000);
this.rendertyping();
}
rendertyping() {
const typingtext = document.getElementById("typing");
let build = "";
let showing = false;
let i = 0;
const curtime = Date.now() - 5000;
for (const thing of this.typingmap.keys()) {
if (this.typingmap.get(thing) > curtime) {
if (i !== 0) {
build += ", ";
}
i++;
if (thing.nick) {
build += thing.nick;
}
else {
build += thing.user.username;
}
showing = true;
}
else {
this.typingmap.delete(thing);
}
}
if (i > 1) {
build += " are typing";
}
else {
build += " is typing";
}
if (this.localuser.channelfocus === this) {
if (showing) {
typingtext.classList.remove("hidden");
const typingtext2 = document.getElementById("typingtext");
typingtext2.textContent = build;
}
else {
typingtext.classList.add("hidden");
}
}
}
static regenLoadingMessages() {
const loading = document.getElementById("loadingdiv");
loading.innerHTML = "";

View file

@ -138,6 +138,7 @@ class Group extends Channel {
const loading = document.getElementById("loadingdiv");
Channel.regenLoadingMessages();
loading.classList.add("loading");
this.rendertyping();
await this.putmessages();
await prom;
if (id !== Channel.genid) {

View file

@ -28,7 +28,6 @@ class Localuser {
lookingguild;
guildhtml;
ws;
typing = new Map();
connectionSucceed = 0;
errorBackoff = 0;
userMap = new Map();
@ -787,22 +786,15 @@ class Localuser {
}
}
async typingStart(typing) {
if (this.channelfocus?.id === typing.d.channel_id) {
const guild = this.guildids.get(typing.d.guild_id);
if (!guild)
return;
const memb = await Member.new(typing.d.member, guild);
if (!memb)
return;
if (memb.id === this.user.id) {
console.log("you is typing");
return;
}
console.log("user is typing and you should see it");
this.typing.set(memb, Date.now());
setTimeout(this.rendertyping.bind(this), 10000);
this.rendertyping();
}
//
const guild = this.guildids.get(typing.d.guild_id);
if (!guild)
return;
const channel = guild.channelids[typing.d.channel_id];
if (!channel)
return;
channel.typingStart(typing);
//this.typing.set(memb,Date.now());
}
updatepfp(file) {
const reader = new FileReader();
@ -848,45 +840,6 @@ class Localuser {
body: JSON.stringify(json)
});
}
rendertyping() {
const typingtext = document.getElementById("typing");
let build = "";
let showing = false;
let i = 0;
const curtime = Date.now() - 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) {
build += " are typing";
}
else {
build += " is typing";
}
if (showing) {
typingtext.classList.remove("hidden");
const typingtext2 = document.getElementById("typingtext");
typingtext2.textContent = build;
}
else {
typingtext.classList.add("hidden");
}
}
async showusersettings() {
const settings = new Settings("Settings");
{