add +typing support

This commit is contained in:
emerson 2022-10-14 09:39:52 -04:00
parent 37e12cba8d
commit 8c57b9231d
2 changed files with 45 additions and 0 deletions

View file

@ -580,6 +580,26 @@ export abstract class Client {
} }
}); });
} }
if (message.tags.has("+typing")) {
const data = {
"typing": false
}
if (message.tags.get("+typing") === "active") {
data.typing = true;
}
this.apiCall.put(`/rooms/${targetChannel.roomId}/typing/${this.user.mxid}`, data).then(r => {
// No response body for successful request
}).catch(function (error) {
if (error.response) {
console.log(error.response.data);
} else if (error.request) {
console.log(error.request);
} else {
console.log('Error', error.message);
console.log(error.config);
}
});
}
} }
sendTOPIC(targetChannel: Channel) { sendTOPIC(targetChannel: Channel) {

View file

@ -84,6 +84,10 @@ export class Server {
if (targetChannel.isSynced()) if (targetChannel.isSynced())
this.routeMatrixEvent(nextEvent, targetChannel); this.routeMatrixEvent(nextEvent, targetChannel);
}); });
rooms.join[roomId].ephemeral.events.forEach((nextEvent: any) => {
if (targetChannel.isSynced())
this.routeMatrixEvent(nextEvent, targetChannel);
});
} }
} }
if (rooms['invite']) { if (rooms['invite']) {
@ -247,7 +251,11 @@ export class Server {
case 'm.room.topic': case 'm.room.topic':
this.handleMatrixTopic(nextEvent, targetChannel); this.handleMatrixTopic(nextEvent, targetChannel);
break; break;
case 'm.typing':
this.handleMatrixTyping(nextEvent, targetChannel);
break;
// Add some events we aren't going to use now (or ever) // Add some events we aren't going to use now (or ever)
case 'm.receipt':
case 'm.room.name': case 'm.room.name':
case 'm.room.create': case 'm.room.create':
case 'uk.half-shot.bridge': case 'uk.half-shot.bridge':
@ -582,6 +590,23 @@ export class Server {
}); });
} }
handleMatrixTyping(event: any, targetChannel: Channel) {
const typingUsers = event["content"]?.["user_ids"];
if (!typingUsers) {
return;
}
typingUsers.forEach((mxid: string) => {
let matrixUser = this.matrixUsers.get(mxid);
// Don't bother sending if the user isn't joined to the channel yet
if (matrixUser !== undefined) {
const typingTags = new Map();
typingTags.set('+typing', 'active');
this.sendToAllWithCap('message-tags', matrixUser.getMask(), 'TAGMSG', [targetChannel.name], typingTags);
}
})
}
sendToAll(prefix: string, command: string, params: string[], tags: Map<string, string> = new Map(), skipClient: Client|null = null) { sendToAll(prefix: string, command: string, params: string[], tags: Map<string, string> = new Map(), skipClient: Client|null = null) {
this.clients.forEach(client => { this.clients.forEach(client => {
if (client !== skipClient) { if (client !== skipClient) {