no need to update members, as all the info is in the member event

as we won't store deviceTrackingStatus in the member
This commit is contained in:
Bruno Windels 2020-08-19 16:10:07 +02:00
parent 5ad7b74b2b
commit 2ad9b17ad7
2 changed files with 19 additions and 68 deletions

View file

@ -5,44 +5,25 @@ export class RoomMember {
this._data = data; this._data = data;
} }
static async updateOrCreateMember(roomId, memberData, memberEvent) {
if (!memberEvent) {
return;
}
const userId = memberEvent.state_key;
const {content} = memberEvent;
if (!userId || !content) {
return;
}
let member;
if (memberData) {
member = new RoomMember(memberData);
member.updateWithMemberEvent(memberEvent);
} else {
member = RoomMember.fromMemberEvent(this._roomId, memberEvent);
}
return member;
}
static fromMemberEvent(roomId, memberEvent) { static fromMemberEvent(roomId, memberEvent) {
const userId = memberEvent && memberEvent.state_key; const userId = memberEvent && memberEvent.state_key;
if (!userId) { if (!userId) {
return; return;
} }
const {content} = memberEvent;
const member = new RoomMember({ const membership = content?.membership;
roomId: roomId, const avatarUrl = content?.avatar_url;
userId: userId, const displayName = content?.displayname;
avatarUrl: null, if (typeof membership !== "string") {
displayName: null, return;
membership: null, }
deviceTrackingStatus: 0, return new RoomMember({
roomId,
userId,
membership,
avatarUrl,
displayName,
}); });
member.updateWithMemberEvent(memberEvent);
return member;
} }
get roomId() { get roomId() {
@ -53,17 +34,7 @@ export class RoomMember {
return this._data.userId; return this._data.userId;
} }
updateWithMemberEvent(event) {
if (!event || !event.content) {
return;
}
const {content} = event;
this._data.membership = content.membership;
this._data.avatarUrl = content.avatar_url;
this._data.displayName = content.displayname;
}
serialize() { serialize() {
return this.data; return this._data;
} }
} }

View file

@ -98,34 +98,14 @@ export class SyncWriter {
return {oldFragment, newFragment}; return {oldFragment, newFragment};
} }
async _writeMember(event, txn) { _writeStateEvent(event, txn) {
if (!event) {
return;
}
const userId = event.state_key;
const {content} = event;
if (!userId || !content) {
return;
}
let member;
if (memberData) {
member = new RoomMember(memberData);
member.updateWithMemberEvent(event);
} else {
member = RoomMember.fromMemberEvent(this._roomId, event);
}
}
async _writeStateEvent(event, txn) {
if (event.type === MEMBER_EVENT_TYPE) { if (event.type === MEMBER_EVENT_TYPE) {
const userId = event && event.state_key; const userId = event.state_key;
if (userId) { if (userId) {
const memberData = await txn.roomMembers.get(this._roomId, userId); const member = RoomMember.fromMemberEvent(this._roomId, event);
const member = updateOrCreateMember(this._roomId, memberData, event);
if (member) { if (member) {
// as this is sync, we can just replace the member
// if it is there already
txn.roomMembers.set(member.serialize()); txn.roomMembers.set(member.serialize());
} }
} }