Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bridge Matrix threads #1503

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open

Bridge Matrix threads #1503

wants to merge 1 commit into from

Conversation

tadzik
Copy link
Contributor

@tadzik tadzik commented Jan 10, 2022

This treats each thread reply as an old message reply, as in: always quotes the previous message from a thread, regardless of how long ago it happened – with the possibility of multiple threads going on concurrently, short replies just turn into a mess.

image

It is quite noisy, but I think it's the best we can do to preserve the context. Replies from IRC won't work, obviously :(

@tadzik tadzik requested a review from a team January 10, 2022 14:25
Copy link
Contributor

@Half-Shot Half-Shot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code itself seems reasonable, I suppose the jury is out on whether it's useful to have this. I think on the whole it looks okay, but I am leaning towards disabling support in portal rooms because I think it could get messy if Matrix users start threading.

@@ -126,6 +129,9 @@ export class MatrixHandler {
// required because invites are processed asyncly, so you could get invite->msg
// and the message is processed before the room is created.
private readonly eventCache: Map<string, CachedEvent> = new Map();
// keep track of the last message sent to each thread
// so that we can form replies to the most recent one rather than the first one
private lastMessageInThreadCache: Map<string, string> = new Map();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to make this a LRU to avoid this growing ever larger, or nah?

let lastReplyId = this.lastMessageInThreadCache.get(threadId);
if (!lastReplyId) {
try {
const getThread = async (from?: string) => this.ircBridge.getAppServiceBridge().getIntent().matrixClient.doRequest(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be worth chucking a PR at the bot sdk too, even if it will come too late for this PR.

Comment on lines +1072 to +1096
let from: string|undefined;
// locate the message we're now formatting in the thread chain and find its predecessor
for (let i = 0; i < this.config.threadLookupRequestLimit; i++) {
let thread = await getThread(from);

const currentMessageIdx = thread['chunk'].findIndex((ev: any) => ev.event_id = event.event_id);
if (currentMessageIdx == -1) {
from = thread.next_batch;
if (!from) break;
continue;
} else {
if (currentMessageIdx === thread['chunk'].length) {
// we're at a chunk boundary, need to load one more
thread = await getThread(thread.next_batch);
lastReplyId = thread['chunk'][0].event_id;
} else {
lastReplyId = thread['chunk'][currentMessageIdx + 1].event_id;
}
break;
}
}
} catch (err) {
console.error('Error fetching thread from homeserver:', err);
}
lastReplyId ||= threadId; // fallback to the original message if we really have no better idea
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Personal feeling is this logic feels too complex to sit in this function. Should at least be it's own function, if not in the bot/bridge sdk itself.

@tadzik
Copy link
Contributor Author

tadzik commented Jan 10, 2022

I suppose the jury is out on whether it's useful to have this

This is what it goes down to, yeah. If it'll end up the giving the false impression that we can transparently bridge threads, and yet we can't bridge replies from IRC to Matrix it'll just become a mess. Perhaps it'd make more sense to do channels-as-threads on the IRC side?

@Mikaela
Copy link
Contributor

Mikaela commented Jan 10, 2022

It is quite noisy, but I think it's the best we can do to preserve the context. Replies from IRC won't work, obviously :(

Wouldn't it be best to just support IRCv3 reply client tag as per #1414?

@Half-Shot
Copy link
Contributor

It is quite noisy, but I think it's the best we can do to preserve the context. Replies from IRC won't work, obviously :(

Wouldn't it be best to just support IRCv3 reply client tag as per #1414?

I realise it's a bit chicken and egg, but atm only IRCCloud supports it...so we're unlikely to do the work to support it until Server/Client impls catch up.

@Mikaela
Copy link
Contributor

Mikaela commented Jan 12, 2022

It is quite noisy, but I think it's the best we can do to preserve the context. Replies from IRC won't work, obviously :(

Wouldn't it be best to just support IRCv3 reply client tag as per #1414?

I realise it's a bit chicken and egg, but atm only IRCCloud supports it...so we're unlikely to do the work to support it until Server/Client impls catch up.

It's also supported by Limnoria and Palaver has expressed interest towards implementing it. On servers at least Ergo has it and I would think InspIRCd to at least have it planned if not implemented already.

@progval
Copy link
Contributor

progval commented Jan 12, 2022

until Server/Client impls catch up.

Servers don't need to implement it. It's a client-tag, and servers just pass all client tags without explicitly implementing them. (Though UnrealIRCd has a whitelist, but it already has the tag on its whitelist.)

@Half-Shot
Copy link
Contributor

until Server/Client impls catch up.

Servers don't need to implement it. It's a client-tag, and servers just pass all client tags without explicitly implementing them. (Though UnrealIRCd has a whitelist, but it already has the tag on its whitelist.)

Mm, though client-tags is still lagging behind a bit as well (solanum-ircd/solanum#167). Granted, we could probably implement given enough servers do support it.

@Mikaela
Copy link
Contributor

Mikaela commented Jan 12, 2022

I am under impresson that Solanum is going to get a rewrite at some point and is not going to implement a lot of IRCv3 features before it happens, so I wouldn't include them in considerations how widely supported something is.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants