mirror of
https://github.com/vector-im/hydrogen-web.git
synced 2024-12-23 03:25:12 +01:00
handle prev_content location ambiguity
This commit is contained in:
parent
09cb39b553
commit
2e67b2b6b8
21
src/matrix/room/common.js
Normal file
21
src/matrix/room/common.js
Normal file
@ -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;
|
||||||
|
}
|
@ -1,5 +1,4 @@
|
|||||||
/*
|
/*
|
||||||
Copyright 2020 Bruno Windels <bruno@windels.cloud>
|
|
||||||
Copyright 2020 The Matrix.org Foundation C.I.C.
|
Copyright 2020 The Matrix.org Foundation C.I.C.
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
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.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import {getPrevContentFromStateEvent} from "../common.js";
|
||||||
|
|
||||||
export const EVENT_TYPE = "m.room.member";
|
export const EVENT_TYPE = "m.room.member";
|
||||||
|
|
||||||
export class RoomMember {
|
export class RoomMember {
|
||||||
@ -28,7 +29,7 @@ export class RoomMember {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const content = memberEvent.content;
|
const content = memberEvent.content;
|
||||||
const prevContent = memberEvent.unsigned?.prev_content;
|
const prevContent = getPrevContentFromStateEvent(memberEvent);
|
||||||
const membership = content?.membership;
|
const membership = content?.membership;
|
||||||
// fall back to prev_content for these as synapse doesn't (always?)
|
// fall back to prev_content for these as synapse doesn't (always?)
|
||||||
// put them on content for "leave" memberships
|
// put them on content for "leave" memberships
|
||||||
@ -45,7 +46,7 @@ export class RoomMember {
|
|||||||
if (typeof userId !== "string") {
|
if (typeof userId !== "string") {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const content = memberEvent.unsigned?.prev_content
|
const content = getPrevContentFromStateEvent(memberEvent);
|
||||||
return this._validateAndCreateMember(roomId, userId,
|
return this._validateAndCreateMember(roomId, userId,
|
||||||
content?.membership,
|
content?.membership,
|
||||||
content?.displayname,
|
content?.displayname,
|
||||||
@ -123,7 +124,7 @@ export class MemberChange {
|
|||||||
}
|
}
|
||||||
|
|
||||||
previousMembership() {
|
previousMembership() {
|
||||||
return this._memberEvent.unsigned?.prev_content?.membership;
|
return getPrevContentFromStateEvent(this._memberEvent)?.membership;
|
||||||
}
|
}
|
||||||
|
|
||||||
membership() {
|
membership() {
|
||||||
|
@ -15,6 +15,7 @@ limitations under the License.
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import {BaseEntry} from "./BaseEntry.js";
|
import {BaseEntry} from "./BaseEntry.js";
|
||||||
|
import {getPrevContentFromStateEvent} from "../../common.js";
|
||||||
|
|
||||||
export class EventEntry extends BaseEntry {
|
export class EventEntry extends BaseEntry {
|
||||||
constructor(eventEntry, fragmentIdComparer) {
|
constructor(eventEntry, fragmentIdComparer) {
|
||||||
@ -35,7 +36,7 @@ export class EventEntry extends BaseEntry {
|
|||||||
}
|
}
|
||||||
|
|
||||||
get prevContent() {
|
get prevContent() {
|
||||||
return this._eventEntry.event.unsigned?.prev_content;
|
return getPrevContentFromStateEvent(this._eventEntry.event);
|
||||||
}
|
}
|
||||||
|
|
||||||
get eventType() {
|
get eventType() {
|
||||||
|
Loading…
Reference in New Issue
Block a user