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

@@ -12,6 +12,7 @@ import{InfiniteScroller}from"./infiniteScroller.js";
import{ SnowFlake }from"./snowflake.js";
import{ channeljson, messageCreateJson, messagejson, readyjson }from"./jsontypes.js";
import{ MarkDown }from"./markdown.js";
import { Member } from "./member.js";
declare global {
interface NotificationOptions {
@@ -688,6 +689,7 @@ class Channel extends SnowFlake{
const loading=document.getElementById("loadingdiv") as HTMLDivElement;
Channel.regenLoadingMessages();
loading.classList.add("loading");
this.rendertyping();
await this.putmessages();
await prom;
if(id!==Channel.genid){
@@ -699,6 +701,56 @@ class Channel extends SnowFlake{
//loading.classList.remove("loading");
(document.getElementById("typebox") as HTMLDivElement).contentEditable=""+this.canMessage;
}
typingmap:Map<Member,number>=new Map();
async typingStart(typing):Promise<void>{
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():void{
const typingtext=document.getElementById("typing") as HTMLDivElement;
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) as number>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") as HTMLDivElement;
typingtext2.textContent=build;
}else{
typingtext.classList.add("hidden");
}
}
}
static regenLoadingMessages(){
const loading=document.getElementById("loadingdiv") as HTMLDivElement;
loading.innerHTML="";