Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit 2f209c4

Browse files
authored
Add grouper for hidden events (#7649)
1 parent 00e868f commit 2f209c4

File tree

2 files changed

+92
-4
lines changed

2 files changed

+92
-4
lines changed

src/components/structures/MessagePanel.tsx

Lines changed: 90 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -462,17 +462,17 @@ export default class MessagePanel extends React.Component<IProps, IState> {
462462
return !this.isMounted;
463463
};
464464

465-
private get showHiddenEvents(): boolean {
465+
public get showHiddenEvents(): boolean {
466466
return this.context?.showHiddenEventsInTimeline ?? this.showHiddenEventsInTimeline;
467467
}
468468

469469
// TODO: Implement granular (per-room) hide options
470-
public shouldShowEvent(mxEv: MatrixEvent): boolean {
470+
public shouldShowEvent(mxEv: MatrixEvent, forceHideEvents = false): boolean {
471471
if (MatrixClientPeg.get().isUserIgnored(mxEv.getSender())) {
472472
return false; // ignored = no show (only happens if the ignore happens after an event was received)
473473
}
474474

475-
if (this.showHiddenEvents) {
475+
if (this.showHiddenEvents && !forceHideEvents) {
476476
return true;
477477
}
478478

@@ -1403,5 +1403,91 @@ class MemberGrouper extends BaseGrouper {
14031403
}
14041404
}
14051405

1406+
// Wrap consecutive hidden events in a ListSummary, ignore if redacted
1407+
class HiddenEventGrouper extends BaseGrouper {
1408+
static canStartGroup = function(panel: MessagePanel, ev: MatrixEvent): boolean {
1409+
return !panel.shouldShowEvent(ev, true) && panel.showHiddenEvents;
1410+
};
1411+
1412+
constructor(
1413+
public readonly panel: MessagePanel,
1414+
public readonly event: MatrixEvent,
1415+
public readonly prevEvent: MatrixEvent,
1416+
public readonly lastShownEvent: MatrixEvent,
1417+
protected readonly layout: Layout,
1418+
) {
1419+
super(panel, event, prevEvent, lastShownEvent, layout);
1420+
this.events = [event];
1421+
}
1422+
1423+
public shouldGroup(ev: MatrixEvent): boolean {
1424+
if (this.panel.wantsDateSeparator(this.events[0], ev.getDate())) {
1425+
return false;
1426+
}
1427+
return !this.panel.shouldShowEvent(ev, true);
1428+
}
1429+
1430+
public add(ev: MatrixEvent, showHiddenEvents?: boolean): void {
1431+
this.readMarker = this.readMarker || this.panel.readMarkerForEvent(ev.getId(), ev === this.lastShownEvent);
1432+
this.events.push(ev);
1433+
}
1434+
1435+
public getTiles(): ReactNode[] {
1436+
if (!this.events || !this.events.length) return [];
1437+
1438+
const isGrouped = true;
1439+
const panel = this.panel;
1440+
const ret = [];
1441+
const lastShownEvent = this.lastShownEvent;
1442+
1443+
if (panel.wantsDateSeparator(this.prevEvent, this.events[0].getDate())) {
1444+
const ts = this.events[0].getTs();
1445+
ret.push(
1446+
<li key={ts+'~'}><DateSeparator key={ts+'~'} ts={ts} /></li>,
1447+
);
1448+
}
1449+
1450+
const key = "hiddeneventlistsummary-" + (
1451+
this.prevEvent ? this.events[0].getId() : "initial"
1452+
);
1453+
1454+
const senders = new Set<RoomMember>();
1455+
let eventTiles = this.events.map((e, i) => {
1456+
senders.add(e.sender);
1457+
const prevEvent = i === 0 ? this.prevEvent : this.events[i - 1];
1458+
return panel.getTilesForEvent(
1459+
prevEvent, e, e === lastShownEvent, isGrouped, this.nextEvent, this.nextEventTile);
1460+
}).reduce((a, b) => a.concat(b), []);
1461+
1462+
if (eventTiles.length === 0) {
1463+
eventTiles = null;
1464+
}
1465+
1466+
ret.push(
1467+
<EventListSummary
1468+
key={key}
1469+
threshold={2}
1470+
events={this.events}
1471+
onToggle={panel.onHeightChanged} // Update scroll state
1472+
summaryMembers={Array.from(senders)}
1473+
summaryText={_t("%(count)s hidden messages.", { count: eventTiles.length })}
1474+
layout={this.layout}
1475+
>
1476+
{ eventTiles }
1477+
</EventListSummary>,
1478+
);
1479+
1480+
if (this.readMarker) {
1481+
ret.push(this.readMarker);
1482+
}
1483+
1484+
return ret;
1485+
}
1486+
1487+
public getNewPrevEvent(): MatrixEvent {
1488+
return this.events[this.events.length - 1];
1489+
}
1490+
}
1491+
14061492
// all the grouper classes that we use
1407-
const groupers = [CreationGrouper, MemberGrouper, RedactionGrouper];
1493+
const groupers = [CreationGrouper, MemberGrouper, RedactionGrouper, HiddenEventGrouper];

src/i18n/strings/en_EN.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3047,6 +3047,8 @@
30473047
"%(creator)s created and configured the room.": "%(creator)s created and configured the room.",
30483048
"%(count)s messages deleted.|other": "%(count)s messages deleted.",
30493049
"%(count)s messages deleted.|one": "%(count)s message deleted.",
3050+
"%(count)s hidden messages.|other": "%(count)s hidden messages.",
3051+
"%(count)s hidden messages.|one": "%(count)s hidden message.",
30503052
"Your Communities": "Your Communities",
30513053
"Did you know: you can use communities to filter your %(brand)s experience!": "Did you know: you can use communities to filter your %(brand)s experience!",
30523054
"You can click on an avatar in the filter panel at any time to see only the rooms and people associated with that community.": "You can click on an avatar in the filter panel at any time to see only the rooms and people associated with that community.",

0 commit comments

Comments
 (0)