Closed NathanC closed 2 years ago
Hacky temporary solutions for edits are very unlikely to happen at this point since the bridge already has native edits implemented. I'd expect WhatsApp to ship them in some months too, they'll be enabled by default on the bridge as soon as official apps start rendering them. For reactions, the protobuf stuff appeared a few months in advance and official clients started rendering them around a month before release.
It might make sense for Signal, so I'd accept a PR that's sufficiently separated from the rest of the code (i.e. making minimal changes to the message handling code and having all the diffing logic neatly in a separate file). I probably won't implement it myself there either though. The proper solution is just not sending edits, and at some point I want to make the bridges signal what features they support so clients can appropriately discourage users from doing unsupported things.
There are a few closed issues about improving editing, but those are mainly about deleting messages and altering the timeline, this is different. Instead of showing the full new message with a *, I suggest to just show the inner substring change (expanded to a word as the smallest unit).
For example "how are you doing tdry", when edited, should result in the message "* today". This would match the standard pattern humans use when editing on chat platforms that don't support edit, like SMS and WhatsApp.
In terms of implementation/algorithm, I think it would be a lot easier than a generic diff algorithm. We could just detect if some contiguous substring is changed, and then greedily expand that substring on both edges until we find whitespace.
For example changing "foo bar baz" to "foo bAr baz" would detect the change in A, and search in both directions unti it finds whitespace.
We have options after that-- if there are two different internal edits, we could do it like foo, bar", or we could disallow multiple edits. If there are more that two edits, or maybe if the total edits compromise more than say 60% of the original text, we could fall back to the original pattern of followed by the whole new message. Or perhaps "edit: ", since people generally wouldn't use for a full rewrite.
Some examples:
I just ate a toad
->* taco
I just ate a toad
->* taco, it was delicious!
I just fate a toad
->* ate, * beef taco
I just fate a toad
->edit: I had some really good Mexican food just now
This is just off the cuff, I'd have to do some thinking about the details of it (maybe using the Levenshtein Distance), but you get the picture.
If you're interested in this idea, I can write up some psudocode. It could be ported to other bridges as well, like Signal (which currently doesn't even add a *, just posts a new message). We could also potentially make a matrix spec for this about bridging to networks that don't support editing.