mirror of
https://git.sr.ht/~emerson/reflectionircd
synced 2025-04-13 09:59:52 +00:00
implement labeled-response
This commit is contained in:
parent
7cdba2c276
commit
f575b9f59a
3 changed files with 38 additions and 14 deletions
|
@ -6,6 +6,9 @@
|
||||||
- Typing notifications
|
- Typing notifications
|
||||||
- Sticker support (M->I only)
|
- Sticker support (M->I only)
|
||||||
|
|
||||||
|
## Fixed
|
||||||
|
- labeled-response is sent correctly for all commands
|
||||||
|
|
||||||
## v0.1.1 - 2022-02-09
|
## v0.1.1 - 2022-02-09
|
||||||
- Fix `DELETEMSG` being sent to unsupporting clients
|
- Fix `DELETEMSG` being sent to unsupporting clients
|
||||||
- Fix missing parameter in `900` numeric.
|
- Fix missing parameter in `900` numeric.
|
||||||
|
|
|
@ -202,9 +202,9 @@ export abstract class Client {
|
||||||
this.apiCall.put(`/presence/${this.user.mxid}/status`, data).then(r => {
|
this.apiCall.put(`/presence/${this.user.mxid}/status`, data).then(r => {
|
||||||
// Returning the IRC numerics here because most servers have presence disabled anyways
|
// Returning the IRC numerics here because most servers have presence disabled anyways
|
||||||
if (data.presence === 'online') {
|
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 {
|
} 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) {
|
}).catch(function (error) {
|
||||||
if (error.response) {
|
if (error.response) {
|
||||||
|
@ -314,7 +314,7 @@ export abstract class Client {
|
||||||
if (!this.user || !targetUser || !targetChannel) return;
|
if (!this.user || !targetUser || !targetChannel) return;
|
||||||
if (!this.checkIfInChannel(targetChannel, message)) return;
|
if (!this.checkIfInChannel(targetChannel, message)) return;
|
||||||
if (targetChannel.matrixUsers.has(targetUser.nick)) {
|
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;
|
return;
|
||||||
}
|
}
|
||||||
const reason = (message.params.length === 3) ? message.params[2] : "";
|
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.user || !targetUser || !targetChannel) return;
|
||||||
if (!this.checkIfInChannel(targetChannel, message)) return;
|
if (!this.checkIfInChannel(targetChannel, message)) return;
|
||||||
if (!targetChannel.matrixUsers.has(targetUser.nick)) {
|
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;
|
return;
|
||||||
}
|
}
|
||||||
const reason = (message.params.length === 3) ? message.params[2] : "";
|
const reason = (message.params.length === 3) ? message.params[2] : "";
|
||||||
|
@ -411,7 +416,7 @@ export abstract class Client {
|
||||||
if (!this.user || !targetChannel) return;
|
if (!this.user || !targetChannel) return;
|
||||||
if (!this.checkIfInChannel(targetChannel, message)) return;
|
if (!this.checkIfInChannel(targetChannel, message)) return;
|
||||||
if (targetChannel.roomType === "m.space") {
|
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;
|
return;
|
||||||
}
|
}
|
||||||
let msgtype = 'm.text';
|
let msgtype = 'm.text';
|
||||||
|
@ -522,7 +527,7 @@ export abstract class Client {
|
||||||
//@ts-ignore
|
//@ts-ignore
|
||||||
this.user.getClients().forEach(c => {
|
this.user.getClients().forEach(c => {
|
||||||
//@ts-ignore
|
//@ts-ignore
|
||||||
c.sendMessage(this.user.getMask(), "PART", [targetChannel.name, reason]);
|
c.sendMessage(this.user.getMask(), "PART", [targetChannel.name, reason], message.tags);
|
||||||
})
|
})
|
||||||
//@ts-ignore
|
//@ts-ignore
|
||||||
this.user.channels.delete(targetChannel.name);
|
this.user.channels.delete(targetChannel.name);
|
||||||
|
@ -531,7 +536,7 @@ export abstract class Client {
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
//@ts-ignore
|
//@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) {
|
}).catch(function (error) {
|
||||||
if (error.response) {
|
if (error.response) {
|
||||||
|
@ -602,17 +607,30 @@ export abstract class Client {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sendTOPIC(targetChannel: Channel) {
|
sendTOPIC(targetChannel: Channel, messageTags: Map<string, string>) {
|
||||||
if (!this.user) return;
|
if (!this.user) return;
|
||||||
const topicText = targetChannel.topic.get('text') || '';
|
const topicText = targetChannel.topic.get('text') || '';
|
||||||
const topicSetter = targetChannel.topic.get('setter') || 'matrix';
|
const topicSetter = targetChannel.topic.get('setter') || 'matrix';
|
||||||
const topicTimestamp = targetChannel.topic.get('timestamp') || '0';
|
const topicTimestamp = targetChannel.topic.get('timestamp') || '0';
|
||||||
if (topicText === '') {
|
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;
|
return;
|
||||||
}
|
}
|
||||||
this.sendMessage(this.server.name, '332', [this.user.nick, targetChannel.name, topicText]);
|
const messageLabel = messageTags.get('label') || "";
|
||||||
this.sendMessage(this.server.name, '333', [this.user.nick, targetChannel.name, topicSetter, topicTimestamp]);
|
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) {
|
doTOPIC(message: IRCMessage) {
|
||||||
|
@ -622,7 +640,7 @@ export abstract class Client {
|
||||||
if (!this.user || !targetChannel) return;
|
if (!this.user || !targetChannel) return;
|
||||||
if (!this.checkIfInChannel(targetChannel, message)) return;
|
if (!this.checkIfInChannel(targetChannel, message)) return;
|
||||||
if (message.params.length === 1) {
|
if (message.params.length === 1) {
|
||||||
this.sendTOPIC(targetChannel);
|
this.sendTOPIC(targetChannel, message.tags);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const topic = message.params[1];
|
const topic = message.params[1];
|
||||||
|
|
|
@ -190,7 +190,7 @@ export class Server {
|
||||||
client.sendMessage(this.getMask(), "JOIN", [targetChannel.name], new Map([['account', this.ourMatrixUser.realname]]));
|
client.sendMessage(this.getMask(), "JOIN", [targetChannel.name], new Map([['account', this.ourMatrixUser.realname]]));
|
||||||
}
|
}
|
||||||
client.sendNAMES(targetChannel);
|
client.sendNAMES(targetChannel);
|
||||||
client.sendTOPIC(targetChannel);
|
client.sendTOPIC(targetChannel, new Map());
|
||||||
}
|
}
|
||||||
|
|
||||||
checkForLazyJoin(event: any, sourceUser: MatrixUser, targetChannel: Channel) {
|
checkForLazyJoin(event: any, sourceUser: MatrixUser, targetChannel: Channel) {
|
||||||
|
@ -587,7 +587,10 @@ export class Server {
|
||||||
const messageTags = new Map();
|
const messageTags = new Map();
|
||||||
messageTags.set('msgid', event["event_id"]);
|
messageTags.set('msgid', event["event_id"]);
|
||||||
messageTags.set('account', topicSetter.accountName);
|
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) => {
|
this.clients.forEach((client) => {
|
||||||
client.sendMessage(topicSetter.getMask(), 'TOPIC', [targetChannel.name, topicText], messageTags);
|
client.sendMessage(topicSetter.getMask(), 'TOPIC', [targetChannel.name, topicText], messageTags);
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Reference in a new issue