diff --git a/src/matrix/room/common.js b/src/matrix/room/common.js new file mode 100644 index 00000000..922ca115 --- /dev/null +++ b/src/matrix/room/common.js @@ -0,0 +1,21 @@ +/* +Copyright 2020 The Matrix.org Foundation C.I.C. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +export function getPrevContentFromStateEvent(event) { + // where to look for prev_content is a bit of a mess, + // see https://matrix.to/#/!NasysSDfxKxZBzJJoE:matrix.org/$DvrAbZJiILkOmOIuRsNoHmh2v7UO5CWp_rYhlGk34fQ?via=matrix.org&via=pixie.town&via=amorgan.xyz + return event.unsigned?.prev_content || event.prev_content; +} diff --git a/src/matrix/room/members/RoomMember.js b/src/matrix/room/members/RoomMember.js index 0c05b4cb..c1c9f93b 100644 --- a/src/matrix/room/members/RoomMember.js +++ b/src/matrix/room/members/RoomMember.js @@ -1,5 +1,4 @@ /* -Copyright 2020 Bruno Windels Copyright 2020 The Matrix.org Foundation C.I.C. Licensed under the Apache License, Version 2.0 (the "License"); @@ -15,6 +14,8 @@ See the License for the specific language governing permissions and limitations under the License. */ +import {getPrevContentFromStateEvent} from "../common.js"; + export const EVENT_TYPE = "m.room.member"; export class RoomMember { @@ -28,7 +29,7 @@ export class RoomMember { return; } const content = memberEvent.content; - const prevContent = memberEvent.unsigned?.prev_content; + const prevContent = getPrevContentFromStateEvent(memberEvent); const membership = content?.membership; // fall back to prev_content for these as synapse doesn't (always?) // put them on content for "leave" memberships @@ -45,7 +46,7 @@ export class RoomMember { if (typeof userId !== "string") { return; } - const content = memberEvent.unsigned?.prev_content + const content = getPrevContentFromStateEvent(memberEvent); return this._validateAndCreateMember(roomId, userId, content?.membership, content?.displayname, @@ -123,7 +124,7 @@ export class MemberChange { } previousMembership() { - return this._memberEvent.unsigned?.prev_content?.membership; + return getPrevContentFromStateEvent(this._memberEvent)?.membership; } membership() { diff --git a/src/matrix/room/timeline/entries/EventEntry.js b/src/matrix/room/timeline/entries/EventEntry.js index d1d5b64c..4dce9834 100644 --- a/src/matrix/room/timeline/entries/EventEntry.js +++ b/src/matrix/room/timeline/entries/EventEntry.js @@ -15,6 +15,7 @@ limitations under the License. */ import {BaseEntry} from "./BaseEntry.js"; +import {getPrevContentFromStateEvent} from "../../common.js"; export class EventEntry extends BaseEntry { constructor(eventEntry, fragmentIdComparer) { @@ -35,7 +36,7 @@ export class EventEntry extends BaseEntry { } get prevContent() { - return this._eventEntry.event.unsigned?.prev_content; + return getPrevContentFromStateEvent(this._eventEntry.event); } get eventType() {