1
0
mirror of https://github.com/matrix-org/matrix-js-sdk.git synced 2025-07-31 15:24:23 +03:00

Remove extensible events v1 field population on legacy events (#3040)

* Remove extensible events v1 field population on legacy events

With extensible events v2, affected events are now gated by a room version, so we don't need this code anymore. 

The proposal has generally moved away from mixing m.room.message with extensible fields as well.

* Run prettier

* Remove unstable identifier from tests too

* Run prettier again
This commit is contained in:
Travis Ralston
2023-01-10 09:19:55 -07:00
committed by GitHub
parent 3564a3546f
commit 185ded4ebc
2 changed files with 11 additions and 49 deletions

View File

@ -1177,11 +1177,10 @@ describe("MatrixClient", function () {
.when("PUT", "/send") .when("PUT", "/send")
.check((req) => { .check((req) => {
expect(req.data).toStrictEqual({ expect(req.data).toStrictEqual({
"msgtype": "m.emote", msgtype: "m.emote",
"body": "Body", body: "Body",
"formatted_body": "<h1>Body</h1>", formatted_body: "<h1>Body</h1>",
"format": "org.matrix.custom.html", format: "org.matrix.custom.html",
"org.matrix.msc1767.message": expect.anything(),
}); });
}) })
.respond(200, { event_id: "$foobar" }); .respond(200, { event_id: "$foobar" });
@ -1197,11 +1196,10 @@ describe("MatrixClient", function () {
.when("PUT", "/send") .when("PUT", "/send")
.check((req) => { .check((req) => {
expect(req.data).toStrictEqual({ expect(req.data).toStrictEqual({
"msgtype": "m.text", msgtype: "m.text",
"body": "Body", body: "Body",
"formatted_body": "<h1>Body</h1>", formatted_body: "<h1>Body</h1>",
"format": "org.matrix.custom.html", format: "org.matrix.custom.html",
"org.matrix.msc1767.message": expect.anything(),
}); });
}) })
.respond(200, { event_id: "$foobar" }); .respond(200, { event_id: "$foobar" });

View File

@ -18,7 +18,7 @@ limitations under the License.
* This is an internal module. See {@link MatrixClient} for the public class. * This is an internal module. See {@link MatrixClient} for the public class.
*/ */
import { EmoteEvent, IPartialEvent, MessageEvent, NoticeEvent, Optional } from "matrix-events-sdk"; import { Optional } from "matrix-events-sdk";
import type { IMegolmSessionData } from "./@types/crypto"; import type { IMegolmSessionData } from "./@types/crypto";
import { ISyncStateData, SyncApi, SyncApiOptions, SyncState } from "./sync"; import { ISyncStateData, SyncApi, SyncApiOptions, SyncState } from "./sync";
@ -4541,44 +4541,8 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
threadId = null; threadId = null;
} }
// Populate all outbound events with Extensible Events metadata to ensure there's a const eventType: string = EventType.RoomMessage;
// reasonably large pool of messages to parse. const sendContent: IContent = content as IContent;
let eventType: string = EventType.RoomMessage;
let sendContent: IContent = content as IContent;
const makeContentExtensible = (content: IContent = {}, recurse = true): IPartialEvent<object> | undefined => {
let newEvent: IPartialEvent<IContent> | undefined;
if (content["msgtype"] === MsgType.Text) {
newEvent = MessageEvent.from(content["body"], content["formatted_body"]).serialize();
} else if (content["msgtype"] === MsgType.Emote) {
newEvent = EmoteEvent.from(content["body"], content["formatted_body"]).serialize();
} else if (content["msgtype"] === MsgType.Notice) {
newEvent = NoticeEvent.from(content["body"], content["formatted_body"]).serialize();
}
if (newEvent && content["m.new_content"] && recurse) {
const newContent = makeContentExtensible(content["m.new_content"], false);
if (newContent) {
newEvent.content["m.new_content"] = newContent.content;
}
}
if (newEvent) {
// copy over all other fields we don't know about
for (const [k, v] of Object.entries(content)) {
if (!newEvent.content.hasOwnProperty(k)) {
newEvent.content[k] = v;
}
}
}
return newEvent;
};
const result = makeContentExtensible(sendContent);
if (result) {
eventType = result.type;
sendContent = result.content;
}
return this.sendEvent(roomId, threadId as string | null, eventType, sendContent, txnId); return this.sendEvent(roomId, threadId as string | null, eventType, sendContent, txnId);
} }