forked from mystiq/hydrogen-web
fix ll events being duplicated in the timeline preventing name changes
This commit is contained in:
parent
b37a586094
commit
cfb521ef10
1 changed files with 29 additions and 6 deletions
|
@ -56,10 +56,20 @@ export class MemberWriter {
|
||||||
if (!existingMember || !existingMember.equals(member)) {
|
if (!existingMember || !existingMember.equals(member)) {
|
||||||
txn.roomMembers.set(member.serialize());
|
txn.roomMembers.set(member.serialize());
|
||||||
this._cache.set(member);
|
this._cache.set(member);
|
||||||
|
// we also return a member change for lazy loading members if something changed,
|
||||||
if (!isLazyLoadingMember) {
|
// so when the dupe timeline event comes and it doesn't see a diff
|
||||||
return new MemberChange(member, existingMember?.membership);
|
// with the cache, we already returned the event here.
|
||||||
|
//
|
||||||
|
// it's just important that we don't consider the first LL event
|
||||||
|
// for a user we see as a membership change, or we'll share keys with
|
||||||
|
// them, etc...
|
||||||
|
if (isLazyLoadingMember && !existingMember) {
|
||||||
|
// we don't have a previous member, but we know this is not a
|
||||||
|
// membership change as it's a lazy loaded
|
||||||
|
// member so take the membership from the member
|
||||||
|
return new MemberChange(member, member.membership);
|
||||||
}
|
}
|
||||||
|
return new MemberChange(member, existingMember?.membership);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -191,13 +201,26 @@ export function tests() {
|
||||||
assert(!change.hasLeft);
|
assert(!change.hasLeft);
|
||||||
assert(!change.hasJoined);
|
assert(!change.hasJoined);
|
||||||
},
|
},
|
||||||
"lazy loaded member is written but no change returned": async assert => {
|
"lazy loaded member we already know about doens't return change": async assert => {
|
||||||
|
const writer = new MemberWriter(roomId);
|
||||||
|
const txn = createStorage([member("join", alice, "Alice")]);
|
||||||
|
const change = await writer.writeStateMemberEvent(createMemberEvent("join", alice, "Alice"), false, txn);
|
||||||
|
assert(!change);
|
||||||
|
},
|
||||||
|
"lazy loaded member we already know about changes display name": async assert => {
|
||||||
|
const writer = new MemberWriter(roomId);
|
||||||
|
const txn = createStorage([member("join", alice, "Alice")]);
|
||||||
|
const change = await writer.writeStateMemberEvent(createMemberEvent("join", alice, "Alies"), false, txn);
|
||||||
|
assert.equal(change.member.displayName, "Alies");
|
||||||
|
},
|
||||||
|
"unknown lazy loaded member returns change, but not considered a membership change": async assert => {
|
||||||
const writer = new MemberWriter(roomId);
|
const writer = new MemberWriter(roomId);
|
||||||
const txn = createStorage();
|
const txn = createStorage();
|
||||||
const change = await writer.writeStateMemberEvent(createMemberEvent("join", alice, "Alice"), false, txn);
|
const change = await writer.writeStateMemberEvent(createMemberEvent("join", alice, "Alice"), false, txn);
|
||||||
assert(!change);
|
assert(!change.hasJoined);
|
||||||
|
assert(!change.hasLeft);
|
||||||
|
assert.equal(change.member.membership, "join");
|
||||||
assert.equal(txn.members.get(alice).displayName, "Alice");
|
assert.equal(txn.members.get(alice).displayName, "Alice");
|
||||||
},
|
},
|
||||||
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue