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

Use sender instead of content.creator field on m.room.create events #3675

Merged
merged 3 commits into from
Aug 24, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
4 changes: 1 addition & 3 deletions spec/integ/matrix-client-event-emitter.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,7 @@ describe("MatrixClient events", function () {
type: "m.room.create",
room: "!erufh:bar",
user: "@foo:bar",
content: {
creator: "@foo:bar",
},
content: {},
Johennes marked this conversation as resolved.
Show resolved Hide resolved
}),
],
},
Expand Down
4 changes: 1 addition & 3 deletions spec/integ/matrix-client-event-timeline.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,7 @@ const INITIAL_SYNC_DATA = {
utils.mkEvent({
type: "m.room.create",
user: userId,
content: {
creator: userId,
},
content: {},
event: false,
}),
],
Expand Down
1 change: 0 additions & 1 deletion spec/integ/matrix-client-methods.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1989,7 +1989,6 @@ const buildEventCreate = () =>
new MatrixEvent({
age: 80126105,
content: {
creator: "@andybalaam-test1:matrix.org",
room_version: "6",
Johennes marked this conversation as resolved.
Show resolved Hide resolved
},
event_id: "$e7j2Gt37k5NPwB6lz2N3V9lO5pUdNK8Ai7i2FPEK-oI",
Expand Down
4 changes: 1 addition & 3 deletions spec/integ/matrix-client-opts.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,7 @@ describe("MatrixClient opts", function () {
type: "m.room.create",
room: roomId,
user: userId,
content: {
creator: userId,
},
content: {},
}),
],
},
Expand Down
4 changes: 1 addition & 3 deletions spec/integ/matrix-client-room-timeline.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,7 @@ describe("MatrixClient room timelines", function () {
type: "m.room.create",
room: roomId,
user: userId,
content: {
creator: userId,
},
content: {},
}),
],
},
Expand Down
26 changes: 6 additions & 20 deletions spec/integ/matrix-client-syncing.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -389,9 +389,7 @@ describe("MatrixClient syncing", () => {
type: "m.room.create",
room: roomOne,
user: selfUserId,
content: {
creator: selfUserId,
},
content: {},
}),
],
},
Expand Down Expand Up @@ -577,9 +575,7 @@ describe("MatrixClient syncing", () => {
type: "m.room.create",
room: roomOne,
user: selfUserId,
content: {
creator: selfUserId,
},
content: {},
}),
],
},
Expand Down Expand Up @@ -611,9 +607,7 @@ describe("MatrixClient syncing", () => {
type: "m.room.create",
room: roomTwo,
user: selfUserId,
content: {
creator: selfUserId,
},
content: {},
}),
],
},
Expand Down Expand Up @@ -758,7 +752,6 @@ describe("MatrixClient syncing", () => {
room: roomOne,
user: otherUserId,
content: {
creator: otherUserId,
room_version: "9",
Johennes marked this conversation as resolved.
Show resolved Hide resolved
},
});
Expand Down Expand Up @@ -844,7 +837,6 @@ describe("MatrixClient syncing", () => {
room: roomOne,
user: otherUserId,
content: {
creator: otherUserId,
room_version: testMeta.roomVersion,
Johennes marked this conversation as resolved.
Show resolved Hide resolved
},
});
Expand Down Expand Up @@ -1372,9 +1364,7 @@ describe("MatrixClient syncing", () => {
type: "m.room.create",
room: roomOne,
user: selfUserId,
content: {
creator: selfUserId,
},
content: {},
}),
],
} as Partial<IJoinedRoom>,
Expand Down Expand Up @@ -1471,9 +1461,7 @@ describe("MatrixClient syncing", () => {
type: "m.room.create",
room: roomOne,
user: selfUserId,
content: {
creator: selfUserId,
},
content: {},
}),
],
},
Expand Down Expand Up @@ -1629,9 +1617,7 @@ describe("MatrixClient syncing", () => {
type: "m.room.create",
room: roomId,
user: selfUserId,
content: {
creator: selfUserId,
},
content: {},
}),
],
},
Expand Down
1 change: 0 additions & 1 deletion spec/integ/matrix-client-unread-notifications.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,6 @@ describe("MatrixClient syncing", () => {
events: [
{
content: {
creator: userB,
room_version: "9",
Johennes marked this conversation as resolved.
Show resolved Hide resolved
},
origin_server_ts: 1,
Expand Down
24 changes: 12 additions & 12 deletions spec/integ/sliding-sync-sdk.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ describe("SlidingSyncSdk", () => {
[roomA]: {
name: "A",
required_state: [
mkOwnStateEvent(EventType.RoomCreate, { creator: selfUserId }, ""),
mkOwnStateEvent(EventType.RoomCreate, {}, ""),
mkOwnStateEvent(EventType.RoomMember, { membership: "join" }, selfUserId),
mkOwnStateEvent(EventType.RoomPowerLevels, { users: { [selfUserId]: 100 } }, ""),
mkOwnStateEvent(EventType.RoomName, { name: "A" }, ""),
Expand All @@ -203,7 +203,7 @@ describe("SlidingSyncSdk", () => {
name: "B",
required_state: [],
timeline: [
mkOwnStateEvent(EventType.RoomCreate, { creator: selfUserId }, ""),
mkOwnStateEvent(EventType.RoomCreate, {}, ""),
mkOwnStateEvent(EventType.RoomMember, { membership: "join" }, selfUserId),
mkOwnStateEvent(EventType.RoomPowerLevels, { users: { [selfUserId]: 100 } }, ""),
mkOwnEvent(EventType.RoomMessage, { body: "hello B" }),
Expand All @@ -215,7 +215,7 @@ describe("SlidingSyncSdk", () => {
name: "C",
required_state: [],
timeline: [
mkOwnStateEvent(EventType.RoomCreate, { creator: selfUserId }, ""),
mkOwnStateEvent(EventType.RoomCreate, {}, ""),
mkOwnStateEvent(EventType.RoomMember, { membership: "join" }, selfUserId),
mkOwnStateEvent(EventType.RoomPowerLevels, { users: { [selfUserId]: 100 } }, ""),
mkOwnEvent(EventType.RoomMessage, { body: "hello C" }),
Expand All @@ -228,7 +228,7 @@ describe("SlidingSyncSdk", () => {
name: "D",
required_state: [],
timeline: [
mkOwnStateEvent(EventType.RoomCreate, { creator: selfUserId }, ""),
mkOwnStateEvent(EventType.RoomCreate, {}, ""),
mkOwnStateEvent(EventType.RoomMember, { membership: "join" }, selfUserId),
mkOwnStateEvent(EventType.RoomPowerLevels, { users: { [selfUserId]: 100 } }, ""),
mkOwnEvent(EventType.RoomMessage, { body: "hello D" }),
Expand Down Expand Up @@ -264,7 +264,7 @@ describe("SlidingSyncSdk", () => {
[roomF]: {
name: "#foo:localhost",
required_state: [
mkOwnStateEvent(EventType.RoomCreate, { creator: selfUserId }, ""),
mkOwnStateEvent(EventType.RoomCreate, {}, ""),
mkOwnStateEvent(EventType.RoomMember, { membership: "join" }, selfUserId),
mkOwnStateEvent(EventType.RoomPowerLevels, { users: { [selfUserId]: 100 } }, ""),
mkOwnStateEvent(EventType.RoomCanonicalAlias, { alias: "#foo:localhost" }, ""),
Expand All @@ -280,7 +280,7 @@ describe("SlidingSyncSdk", () => {
name: "G",
required_state: [],
timeline: [
mkOwnStateEvent(EventType.RoomCreate, { creator: selfUserId }, ""),
mkOwnStateEvent(EventType.RoomCreate, {}, ""),
mkOwnStateEvent(EventType.RoomMember, { membership: "join" }, selfUserId),
mkOwnStateEvent(EventType.RoomPowerLevels, { users: { [selfUserId]: 100 } }, ""),
],
Expand All @@ -292,7 +292,7 @@ describe("SlidingSyncSdk", () => {
name: "H",
required_state: [],
timeline: [
mkOwnStateEvent(EventType.RoomCreate, { creator: selfUserId }, ""),
mkOwnStateEvent(EventType.RoomCreate, {}, ""),
mkOwnStateEvent(EventType.RoomMember, { membership: "join" }, selfUserId),
mkOwnStateEvent(EventType.RoomPowerLevels, { users: { [selfUserId]: 100 } }, ""),
mkOwnEvent(EventType.RoomMessage, { body: "live event" }),
Expand Down Expand Up @@ -602,7 +602,7 @@ describe("SlidingSyncSdk", () => {
name: "Room with Invite",
required_state: [],
timeline: [
mkOwnStateEvent(EventType.RoomCreate, { creator: selfUserId }, ""),
mkOwnStateEvent(EventType.RoomCreate, {}, ""),
mkOwnStateEvent(EventType.RoomMember, { membership: "join" }, selfUserId),
mkOwnStateEvent(EventType.RoomPowerLevels, { users: { [selfUserId]: 100 } }, ""),
mkOwnStateEvent(EventType.RoomMember, { membership: "invite" }, invitee),
Expand Down Expand Up @@ -718,7 +718,7 @@ describe("SlidingSyncSdk", () => {
name: "Room with account data",
required_state: [],
timeline: [
mkOwnStateEvent(EventType.RoomCreate, { creator: selfUserId }, ""),
mkOwnStateEvent(EventType.RoomCreate, {}, ""),
mkOwnStateEvent(EventType.RoomMember, { membership: "join" }, selfUserId),
mkOwnStateEvent(EventType.RoomPowerLevels, { users: { [selfUserId]: 100 } }, ""),
mkOwnEvent(EventType.RoomMessage, { body: "hello" }),
Expand Down Expand Up @@ -922,7 +922,7 @@ describe("SlidingSyncSdk", () => {
name: "Room with typing",
required_state: [],
timeline: [
mkOwnStateEvent(EventType.RoomCreate, { creator: selfUserId }, ""),
mkOwnStateEvent(EventType.RoomCreate, {}, ""),
mkOwnStateEvent(EventType.RoomMember, { membership: "join" }, selfUserId),
mkOwnStateEvent(EventType.RoomPowerLevels, { users: { [selfUserId]: 100 } }, ""),
mkOwnEvent(EventType.RoomMessage, { body: "hello" }),
Expand Down Expand Up @@ -963,7 +963,7 @@ describe("SlidingSyncSdk", () => {
name: "Room with typing",
required_state: [],
timeline: [
mkOwnStateEvent(EventType.RoomCreate, { creator: selfUserId }, ""),
mkOwnStateEvent(EventType.RoomCreate, {}, ""),
mkOwnStateEvent(EventType.RoomMember, { membership: "join" }, selfUserId),
mkOwnStateEvent(EventType.RoomPowerLevels, { users: { [selfUserId]: 100 } }, ""),
mkOwnEvent(EventType.RoomMessage, { body: "hello" }),
Expand Down Expand Up @@ -1049,7 +1049,7 @@ describe("SlidingSyncSdk", () => {
name: "Room with receipts",
required_state: [],
timeline: [
mkOwnStateEvent(EventType.RoomCreate, { creator: selfUserId }, ""),
mkOwnStateEvent(EventType.RoomCreate, {}, ""),
mkOwnStateEvent(EventType.RoomMember, { membership: "join" }, selfUserId),
mkOwnStateEvent(EventType.RoomPowerLevels, { users: { [selfUserId]: 100 } }, ""),
{
Expand Down
1 change: 0 additions & 1 deletion spec/unit/matrix-client.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2266,7 +2266,6 @@ describe("MatrixClient", function () {
function roomCreateEvent(newRoomId: string, predecessorRoomId: string): MatrixEvent {
return new MatrixEvent({
content: {
"creator": "@daryl:alexandria.example.com",
"m.federate": true,
"predecessor": {
event_id: "id_of_last_event",
Expand Down
4 changes: 1 addition & 3 deletions spec/unit/room-state.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,7 @@ describe("RoomState", function () {
user: userA,
room: roomId,
event: true,
content: {
creator: userA,
},
content: {},
}),
]);
});
Expand Down
6 changes: 2 additions & 4 deletions spec/unit/room.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ describe("Room", function () {
});

describe("getCreator", () => {
it("should return the creator from m.room.create", function () {
it("should return the sender from m.room.create", function () {
// @ts-ignore - mocked doesn't handle overloads sanely
mocked(room.currentState.getStateEvents).mockImplementation(function (type, key) {
if (type === EventType.RoomCreate && key === "") {
Expand All @@ -239,7 +239,7 @@ describe("Room", function () {
room: roomId,
user: userA,
content: {
creator: userA,
creator: userB, // The creator field was dropped in room version 11 but a malicious client might still send it
},
});
}
Expand Down Expand Up @@ -3471,12 +3471,10 @@ describe("Room", function () {

function roomCreateEvent(newRoomId: string, predecessorRoomId: string | null): MatrixEvent {
const content: {
creator: string;
["m.federate"]: boolean;
room_version: string;
predecessor: { event_id: string; room_id: string } | undefined;
} = {
"creator": "@daryl:alexandria.example.com",
"predecessor": undefined,
"m.federate": true,
"room_version": "9",
Expand Down
1 change: 0 additions & 1 deletion src/models/event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1684,7 +1684,6 @@ const REDACT_KEEP_KEYS = new Set([
// a map from state event type to the .content keys we keep when an event is redacted
const REDACT_KEEP_CONTENT_MAP: Record<string, Record<string, 1>> = {
[EventType.RoomMember]: { membership: 1 },
[EventType.RoomCreate]: { creator: 1 },
[EventType.RoomJoinRules]: { join_rule: 1 },
[EventType.RoomPowerLevels]: {
ban: 1,
Expand Down
2 changes: 1 addition & 1 deletion src/models/room.ts
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,7 @@ export class Room extends ReadReceipt<RoomEmittedEvents, RoomEventHandlerMap> {
*/
public getCreator(): string | null {
const createEvent = this.currentState.getStateEvents(EventType.RoomCreate, "");
return createEvent?.getContent()["creator"] ?? null;
return createEvent?.getSender() ?? null;
}

/**
Expand Down
Loading