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

Handle edits which are bundled with an event, per MSC3925 #3045

Merged
merged 1 commit into from
Jan 12, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/event-mapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ limitations under the License.

import { MatrixClient } from "./client";
import { IEvent, MatrixEvent, MatrixEventEvent } from "./models/event";
import { RelationType } from "./@types/event";

export type EventMapper = (obj: Partial<IEvent>) => MatrixEvent;

Expand Down Expand Up @@ -55,6 +56,19 @@ export function eventMapperFor(client: MatrixClient, options: MapperOpts): Event
preventReEmit = true;
}

// if there is a complete edit bundled alongside the event, perform the replacement.
// (prior to MSC3925, events were automatically replaced on the server-side. MSC3925 proposes that that doesn't
// happen automatically but the server does provide us with the whole content of the edit event.)
const bundledEdit = event.getServerAggregatedRelation<Partial<IEvent>>(RelationType.Replace);
if (bundledEdit?.content) {
const replacement = mapper(bundledEdit);
// XXX: it's worth noting that the spec says we should only respect encrypted edits if, once decrypted, the
// replacement has a `m.new_content` property. The problem is that we haven't yet decrypted the replacement
// (it should be happening in the background), so we can't enforce this. Possibly we should for decryption
// to complete, but that sounds a bit racy. For now, we just assume it's ok.
event.makeReplaced(replacement);
}

const thread = room?.findThreadForEvent(event);
if (thread) {
event.setThread(thread);
Expand Down