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:
parent
5ad7b74b2b
commit
2ad9b17ad7
2 changed files with 19 additions and 68 deletions
|
@ -5,44 +5,25 @@ export class RoomMember {
|
|||
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) {
|
||||
const userId = memberEvent && memberEvent.state_key;
|
||||
if (!userId) {
|
||||
return;
|
||||
}
|
||||
|
||||
const member = new RoomMember({
|
||||
roomId: roomId,
|
||||
userId: userId,
|
||||
avatarUrl: null,
|
||||
displayName: null,
|
||||
membership: null,
|
||||
deviceTrackingStatus: 0,
|
||||
const {content} = memberEvent;
|
||||
const membership = content?.membership;
|
||||
const avatarUrl = content?.avatar_url;
|
||||
const displayName = content?.displayname;
|
||||
if (typeof membership !== "string") {
|
||||
return;
|
||||
}
|
||||
return new RoomMember({
|
||||
roomId,
|
||||
userId,
|
||||
membership,
|
||||
avatarUrl,
|
||||
displayName,
|
||||
});
|
||||
member.updateWithMemberEvent(memberEvent);
|
||||
return member;
|
||||
}
|
||||
|
||||
get roomId() {
|
||||
|
@ -53,17 +34,7 @@ export class RoomMember {
|
|||
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() {
|
||||
return this.data;
|
||||
return this._data;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -98,34 +98,14 @@ export class SyncWriter {
|
|||
return {oldFragment, newFragment};
|
||||
}
|
||||
|
||||
async _writeMember(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) {
|
||||
_writeStateEvent(event, txn) {
|
||||
if (event.type === MEMBER_EVENT_TYPE) {
|
||||
const userId = event && event.state_key;
|
||||
const userId = event.state_key;
|
||||
if (userId) {
|
||||
const memberData = await txn.roomMembers.get(this._roomId, userId);
|
||||
const member = updateOrCreateMember(this._roomId, memberData, event);
|
||||
const member = RoomMember.fromMemberEvent(this._roomId, event);
|
||||
if (member) {
|
||||
// as this is sync, we can just replace the member
|
||||
// if it is there already
|
||||
txn.roomMembers.set(member.serialize());
|
||||
}
|
||||
}
|
||||
|
|
Reference in a new issue