diff --git a/CHANGELOG.md b/CHANGELOG.md index f0d8d0e..aee2185 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,9 @@ - Typing notifications - Sticker support (M->I only) +## Fixed +- labeled-response is sent correctly for all commands + ## v0.1.1 - 2022-02-09 - Fix `DELETEMSG` being sent to unsupporting clients - Fix missing parameter in `900` numeric. diff --git a/src/Client.ts b/src/Client.ts index 0eece86..153dd03 100644 --- a/src/Client.ts +++ b/src/Client.ts @@ -202,9 +202,9 @@ export abstract class Client { this.apiCall.put(`/presence/${this.user.mxid}/status`, data).then(r => { // Returning the IRC numerics here because most servers have presence disabled anyways if (data.presence === 'online') { - this.sendMessage(this.server.name, "305", [this.user.nick, "You are no longer marked as being away"]); + this.sendMessage(this.server.name, "305", [this.user.nick, "You are no longer marked as being away"], message.tags); } else { - this.sendMessage(this.server.name, "306", [this.user.nick, "You have been marked as being away"]); + this.sendMessage(this.server.name, "306", [this.user.nick, "You have been marked as being away"], message.tags); } }).catch(function (error) { if (error.response) { @@ -314,7 +314,7 @@ export abstract class Client { if (!this.user || !targetUser || !targetChannel) return; if (!this.checkIfInChannel(targetChannel, message)) return; if (targetChannel.matrixUsers.has(targetUser.nick)) { - this.sendMessage(this.server.name, "443", [this.user.nick, targetUser.nick, "is already on channel"]); + this.sendMessage(this.server.name, "443", [this.user.nick, targetUser.nick, "is already on channel"], message.tags); return; } const reason = (message.params.length === 3) ? message.params[2] : ""; @@ -351,7 +351,12 @@ export abstract class Client { if (!this.user || !targetUser || !targetChannel) return; if (!this.checkIfInChannel(targetChannel, message)) return; if (!targetChannel.matrixUsers.has(targetUser.nick)) { - this.sendMessage(this.server.name, "441", [this.user.nick, targetUser.nick, targetChannel.name, "They aren't on that channel"]); + this.sendMessage( + this.server.name, + "441", + [this.user.nick, targetUser.nick, targetChannel.name, "They aren't on that channel"], + message.tags + ); return; } const reason = (message.params.length === 3) ? message.params[2] : ""; @@ -411,7 +416,7 @@ export abstract class Client { if (!this.user || !targetChannel) return; if (!this.checkIfInChannel(targetChannel, message)) return; if (targetChannel.roomType === "m.space") { - this.sendMessage(this.server.name, "NOTICE", [targetChannel.name, "Sending messages to spaces is not allowed"], new Map()); + this.sendMessage(this.server.name, "NOTICE", [targetChannel.name, "Sending messages to spaces is not allowed"], message.tags); return; } let msgtype = 'm.text'; @@ -522,7 +527,7 @@ export abstract class Client { //@ts-ignore this.user.getClients().forEach(c => { //@ts-ignore - c.sendMessage(this.user.getMask(), "PART", [targetChannel.name, reason]); + c.sendMessage(this.user.getMask(), "PART", [targetChannel.name, reason], message.tags); }) //@ts-ignore this.user.channels.delete(targetChannel.name); @@ -531,7 +536,7 @@ export abstract class Client { } else { //@ts-ignore - this.sendMessage(this.server.name, "NOTICE", [this.user.nick, JSON.stringify(response.data)]); + this.sendMessage(this.server.name, "NOTICE", [this.user.nick, JSON.stringify(response.data)], message.tags); } }).catch(function (error) { if (error.response) { @@ -602,17 +607,30 @@ export abstract class Client { } } - sendTOPIC(targetChannel: Channel) { + sendTOPIC(targetChannel: Channel, messageTags: Map) { if (!this.user) return; const topicText = targetChannel.topic.get('text') || ''; const topicSetter = targetChannel.topic.get('setter') || 'matrix'; const topicTimestamp = targetChannel.topic.get('timestamp') || '0'; if (topicText === '') { - this.sendMessage(this.server.name, '331', [this.user.nick, targetChannel.name, 'No topic is set']); + this.sendMessage(this.server.name, '331', [this.user.nick, targetChannel.name, 'No topic is set'], messageTags); return; } - this.sendMessage(this.server.name, '332', [this.user.nick, targetChannel.name, topicText]); - this.sendMessage(this.server.name, '333', [this.user.nick, targetChannel.name, topicSetter, topicTimestamp]); + const messageLabel = messageTags.get('label') || ""; + let batchLabel = ""; + if (messageLabel) { + batchLabel = Math.random().toString(36).substring(2,7); + this.sendMessage(this.server.name, 'BATCH', [`+${batchLabel}`, 'labeled-response'], messageTags); + } + const newTag = new Map(); + if (batchLabel) { + newTag.set('batch', batchLabel); + } + this.sendMessage(this.server.name, '332', [this.user.nick, targetChannel.name, topicText], newTag); + this.sendMessage(this.server.name, '333', [this.user.nick, targetChannel.name, topicSetter, topicTimestamp], newTag); + if (messageLabel) { + this.sendMessage(this.server.name, 'BATCH', [`-${batchLabel}`]); + } } doTOPIC(message: IRCMessage) { @@ -622,7 +640,7 @@ export abstract class Client { if (!this.user || !targetChannel) return; if (!this.checkIfInChannel(targetChannel, message)) return; if (message.params.length === 1) { - this.sendTOPIC(targetChannel); + this.sendTOPIC(targetChannel, message.tags); return; } const topic = message.params[1]; diff --git a/src/Server.ts b/src/Server.ts index 6fea2f8..89ed2ec 100644 --- a/src/Server.ts +++ b/src/Server.ts @@ -190,7 +190,7 @@ export class Server { client.sendMessage(this.getMask(), "JOIN", [targetChannel.name], new Map([['account', this.ourMatrixUser.realname]])); } client.sendNAMES(targetChannel); - client.sendTOPIC(targetChannel); + client.sendTOPIC(targetChannel, new Map()); } checkForLazyJoin(event: any, sourceUser: MatrixUser, targetChannel: Channel) { @@ -587,7 +587,10 @@ export class Server { const messageTags = new Map(); messageTags.set('msgid', event["event_id"]); messageTags.set('account', topicSetter.accountName); - messageTags.set('time', new Date(event["origin_server_ts"]).toISOString()) + messageTags.set('time', new Date(event["origin_server_ts"]).toISOString()); + if (this.eventIDToLabel.has(event["event_id"])) { + messageTags.set("label", this.eventIDToLabel.get(event["event_id"]) || "") + } this.clients.forEach((client) => { client.sendMessage(topicSetter.getMask(), 'TOPIC', [targetChannel.name, topicText], messageTags); });