Fix wrongly grouping 3pid invites into a single repeated transition (#10087)

This commit is contained in:
Michael Telatynski 2023-02-07 10:09:46 +00:00 committed by GitHub
parent 35d222bac6
commit 54a6ce589f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 70 additions and 20 deletions

View file

@ -507,39 +507,36 @@ export default class EventListSummary extends React.Component<IProps> {
eventsToRender.forEach((e, index) => { eventsToRender.forEach((e, index) => {
const type = e.getType(); const type = e.getType();
let userId = e.getSender(); let userKey = e.getSender()!;
if (type === EventType.RoomMember) { if (type === EventType.RoomThirdPartyInvite) {
userId = e.getStateKey(); userKey = e.getContent().display_name;
} else if (type === EventType.RoomMember) {
userKey = e.getStateKey();
} else if (e.isRedacted()) { } else if (e.isRedacted()) {
userId = e.getUnsigned()?.redacted_because?.sender; userKey = e.getUnsigned()?.redacted_because?.sender;
} }
// Initialise a user's events // Initialise a user's events
if (!userEvents[userId]) { if (!userEvents[userKey]) {
userEvents[userId] = []; userEvents[userKey] = [];
} }
let displayName = userId; let displayName = userKey;
if (type === EventType.RoomThirdPartyInvite) { if (e.isRedacted()) {
displayName = e.getContent().display_name; const sender = this.context?.room?.getMember(userKey);
if (e.sender) {
latestUserAvatarMember.set(userId, e.sender);
}
} else if (e.isRedacted()) {
const sender = this.context?.room.getMember(userId);
if (sender) { if (sender) {
displayName = sender.name; displayName = sender.name;
latestUserAvatarMember.set(userId, sender); latestUserAvatarMember.set(userKey, sender);
} }
} else if (e.target && TARGET_AS_DISPLAY_NAME_EVENTS.includes(type as EventType)) { } else if (e.target && TARGET_AS_DISPLAY_NAME_EVENTS.includes(type as EventType)) {
displayName = e.target.name; displayName = e.target.name;
latestUserAvatarMember.set(userId, e.target); latestUserAvatarMember.set(userKey, e.target);
} else if (e.sender) { } else if (e.sender && type !== EventType.RoomThirdPartyInvite) {
displayName = e.sender.name; displayName = e.sender.name;
latestUserAvatarMember.set(userId, e.sender); latestUserAvatarMember.set(userKey, e.sender);
} }
userEvents[userId].push({ userEvents[userKey].push({
mxEvent: e, mxEvent: e,
displayName, displayName,
index: index, index: index,

View file

@ -21,6 +21,7 @@ import { MatrixEvent, RoomMember } from "matrix-js-sdk/src/matrix";
import { import {
getMockClientWithEventEmitter, getMockClientWithEventEmitter,
mkEvent,
mkMembership, mkMembership,
mockClientMethodsUser, mockClientMethodsUser,
unmockClientPeg, unmockClientPeg,
@ -100,7 +101,7 @@ describe("EventListSummary", function () {
// is created by replacing the first "$" in userIdTemplate with `i` for // is created by replacing the first "$" in userIdTemplate with `i` for
// `i = 0 .. n`. // `i = 0 .. n`.
const generateEventsForUsers = (userIdTemplate, n, events) => { const generateEventsForUsers = (userIdTemplate, n, events) => {
let eventsForUsers = []; let eventsForUsers: MatrixEvent[] = [];
let userId = ""; let userId = "";
for (let i = 0; i < n; i++) { for (let i = 0; i < n; i++) {
userId = userIdTemplate.replace("$", i); userId = userIdTemplate.replace("$", i);
@ -656,4 +657,56 @@ describe("EventListSummary", function () {
expect(summaryText).toBe("user_0, user_1 and 18 others joined"); expect(summaryText).toBe("user_0, user_1 and 18 others joined");
}); });
it("should not blindly group 3pid invites and treat them as distinct users instead", () => {
const events = [
mkEvent({
event: true,
skey: "randomstring1",
user: "@user1:server",
type: "m.room.third_party_invite",
content: {
display_name: "n...@d...",
key_validity_url: "https://blah",
public_key: "public_key",
},
}),
mkEvent({
event: true,
skey: "randomstring2",
user: "@user1:server",
type: "m.room.third_party_invite",
content: {
display_name: "n...@d...",
key_validity_url: "https://blah",
public_key: "public_key",
},
}),
mkEvent({
event: true,
skey: "randomstring3",
user: "@user1:server",
type: "m.room.third_party_invite",
content: {
display_name: "d...@w...",
key_validity_url: "https://blah",
public_key: "public_key",
},
}),
];
const props = {
events: events,
children: generateTiles(events),
summaryLength: 2,
avatarsMaxLength: 5,
threshold: 3,
};
const wrapper = renderComponent(props);
const summary = wrapper.find(".mx_GenericEventListSummary_summary");
const summaryText = summary.text();
expect(summaryText).toBe("n...@d... was invited 2 times, d...@w... was invited");
});
}); });