mirror of
https://git.sr.ht/~emerson/reflectionircd
synced 2025-04-13 09:59:52 +00:00
generalize lazy join logic into one function
This commit is contained in:
parent
8214668f14
commit
da1c006e69
1 changed files with 15 additions and 35 deletions
|
@ -179,6 +179,16 @@ export class Server {
|
|||
client.sendTOPIC(targetChannel);
|
||||
}
|
||||
|
||||
checkForLazyJoin(event: any, sourceUser: MatrixUser, targetChannel: Channel) {
|
||||
if (!targetChannel.matrixUsers.has(sourceUser.nick)) {
|
||||
targetChannel.matrixUsers.set(sourceUser.nick, sourceUser);
|
||||
const prefix = sourceUser.getMask();
|
||||
const joinTags = new Map([["account", sourceUser.accountName], ['time', new Date(event["origin_server_ts"]).toISOString()]])
|
||||
this.sendToAllWithCap('extended-join', prefix, "JOIN", [targetChannel.name, sourceUser.accountName, sourceUser.realname], joinTags);
|
||||
this.sendToAllWithoutCap('extended-join', prefix, "JOIN", [targetChannel.name], joinTags);
|
||||
}
|
||||
}
|
||||
|
||||
addClient(client: Client) {
|
||||
this.clients.add(client);
|
||||
if (this.initialSync) {
|
||||
|
@ -260,13 +270,7 @@ export class Server {
|
|||
|
||||
handleMatrixReaction(event: any, targetChannel: Channel) {
|
||||
const sourceUser = this.getOrCreateMatrixUser(event["sender"]);
|
||||
if (!targetChannel.matrixUsers.has(sourceUser.nick)) {
|
||||
targetChannel.matrixUsers.set(sourceUser.nick, sourceUser);
|
||||
const prefix = sourceUser.getMask();
|
||||
const joinTags = new Map([["account", sourceUser.accountName], ['time', new Date(event["origin_server_ts"]).toISOString()]])
|
||||
this.sendToAllWithCap('extended-join', prefix, "JOIN", [targetChannel.name, sourceUser.accountName, sourceUser.realname], joinTags);
|
||||
this.sendToAllWithoutCap('extended-join', prefix, "JOIN", [targetChannel.name], joinTags);
|
||||
}
|
||||
this.checkForLazyJoin(event, sourceUser, targetChannel);
|
||||
const tags: Map<string, string> = new Map();
|
||||
tags.set('msgid', event["event_id"]);
|
||||
tags.set('account', sourceUser.accountName);
|
||||
|
@ -308,13 +312,7 @@ export class Server {
|
|||
|
||||
handleEncryptedMessage(event: any, targetChannel: Channel) {
|
||||
const sourceUser = this.getOrCreateMatrixUser(event["sender"]);
|
||||
if (!targetChannel.matrixUsers.has(sourceUser.nick)) {
|
||||
targetChannel.matrixUsers.set(sourceUser.nick, sourceUser);
|
||||
const prefix = sourceUser.getMask();
|
||||
const joinTags = new Map([["account", sourceUser.accountName], ['time', new Date(event["origin_server_ts"]).toISOString()]])
|
||||
this.sendToAllWithCap('extended-join', prefix, "JOIN", [targetChannel.name, sourceUser.accountName, sourceUser.realname], joinTags);
|
||||
this.sendToAllWithoutCap('extended-join', prefix, "JOIN", [targetChannel.name], joinTags);
|
||||
}
|
||||
this.checkForLazyJoin(event, sourceUser, targetChannel);
|
||||
const messageTags = new Map();
|
||||
messageTags.set('msgid', event["event_id"]);
|
||||
messageTags.set('time', new Date(event["origin_server_ts"]).toISOString());
|
||||
|
@ -375,13 +373,7 @@ export class Server {
|
|||
});
|
||||
}
|
||||
else if (membershipStatus === "join") {
|
||||
if (!targetChannel.matrixUsers.has(targetUser.nick)) {
|
||||
targetChannel.matrixUsers.set(targetUser.nick, targetUser);
|
||||
const prefix = targetUser.getMask();
|
||||
const joinTags = new Map([["account", targetUser.accountName], ['time', new Date(event["origin_server_ts"]).toISOString()]])
|
||||
this.sendToAllWithCap('extended-join', prefix, "JOIN", [targetChannel.name, targetUser.accountName, targetUser.realname], joinTags);
|
||||
this.sendToAllWithoutCap('extended-join', prefix, "JOIN", [targetChannel.name], joinTags);
|
||||
}
|
||||
this.checkForLazyJoin(event, sourceUser, targetChannel);
|
||||
}
|
||||
else if (membershipStatus === "leave") {
|
||||
if (!targetChannel.matrixUsers.has(targetUser.nick))
|
||||
|
@ -416,13 +408,7 @@ export class Server {
|
|||
|
||||
handleMatrixMessage(event: any, targetChannel: Channel) {
|
||||
const sourceUser = this.getOrCreateMatrixUser(event["sender"]);
|
||||
if (!targetChannel.matrixUsers.has(sourceUser.nick)) {
|
||||
targetChannel.matrixUsers.set(sourceUser.nick, sourceUser);
|
||||
const prefix = sourceUser.getMask();
|
||||
const joinTags = new Map([["account", sourceUser.accountName], ['time', new Date(event["origin_server_ts"]).toISOString()]])
|
||||
this.sendToAllWithCap('extended-join', prefix, "JOIN", [targetChannel.name, sourceUser.accountName, sourceUser.realname], joinTags);
|
||||
this.sendToAllWithoutCap('extended-join', prefix, "JOIN", [targetChannel.name], joinTags);
|
||||
}
|
||||
this.checkForLazyJoin(event, sourceUser, targetChannel);
|
||||
const content = event["content"];
|
||||
const msgtype = content["msgtype"];
|
||||
let messageContent = content["body"];
|
||||
|
@ -526,13 +512,7 @@ export class Server {
|
|||
|
||||
handleMatrixRedaction(event: any, targetChannel: Channel) {
|
||||
const sourceUser = this.getOrCreateMatrixUser(event["sender"]);
|
||||
if (!targetChannel.matrixUsers.has(sourceUser.nick)) {
|
||||
targetChannel.matrixUsers.set(sourceUser.nick, sourceUser);
|
||||
const prefix = sourceUser.getMask();
|
||||
const joinTags = new Map([["account", sourceUser.accountName], ['time', new Date(event["origin_server_ts"]).toISOString()]])
|
||||
this.sendToAllWithCap('extended-join', prefix, "JOIN", [targetChannel.name, sourceUser.accountName, sourceUser.realname], joinTags);
|
||||
this.sendToAllWithoutCap('extended-join', prefix, "JOIN", [targetChannel.name], joinTags);
|
||||
}
|
||||
this.checkForLazyJoin(event, sourceUser, targetChannel);
|
||||
const reason = event["content"]?.["reason"] || "";
|
||||
const tags: Map<string, string> = new Map();
|
||||
tags.set('reflectionircd.chat/delete-message', event["redacts"]);
|
||||
|
|
Loading…
Add table
Reference in a new issue