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

Commit 78b1f6c

Browse files
authored
Merge pull request #5784 from matrix-org/travis/sr-groups
Track next event [tile] over group boundaries
2 parents fe71106 + 2f2bb94 commit 78b1f6c

File tree

1 file changed

+21
-13
lines changed

1 file changed

+21
-13
lines changed

src/components/structures/MessagePanel.js

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,20 @@ export default class MessagePanel extends React.Component {
452452
});
453453
};
454454

455+
_getNextEventInfo(arr, i) {
456+
const nextEvent = i < arr.length - 1
457+
? arr[i + 1]
458+
: null;
459+
460+
// The next event with tile is used to to determine the 'last successful' flag
461+
// when rendering the tile. The shouldShowEvent function is pretty quick at what
462+
// it does, so this should have no significant cost even when a room is used for
463+
// not-chat purposes.
464+
const nextTile = arr.slice(i + 1).find(e => this._shouldShowEvent(e));
465+
466+
return {nextEvent, nextTile};
467+
}
468+
455469
_getEventTiles() {
456470
this.eventNodes = {};
457471

@@ -503,6 +517,7 @@ export default class MessagePanel extends React.Component {
503517
const mxEv = this.props.events[i];
504518
const eventId = mxEv.getId();
505519
const last = (mxEv === lastShownEvent);
520+
const {nextEvent, nextTile} = this._getNextEventInfo(this.props.events, i);
506521

507522
if (grouper) {
508523
if (grouper.shouldGroup(mxEv)) {
@@ -519,22 +534,12 @@ export default class MessagePanel extends React.Component {
519534

520535
for (const Grouper of groupers) {
521536
if (Grouper.canStartGroup(this, mxEv)) {
522-
grouper = new Grouper(this, mxEv, prevEvent, lastShownEvent);
537+
grouper = new Grouper(this, mxEv, prevEvent, lastShownEvent, nextEvent, nextTile);
523538
}
524539
}
525540
if (!grouper) {
526541
const wantTile = this._shouldShowEvent(mxEv);
527542
if (wantTile) {
528-
const nextEvent = i < this.props.events.length - 1
529-
? this.props.events[i + 1]
530-
: null;
531-
532-
// The next event with tile is used to to determine the 'last successful' flag
533-
// when rendering the tile. The shouldShowEvent function is pretty quick at what
534-
// it does, so this should have no significant cost even when a room is used for
535-
// not-chat purposes.
536-
const nextTile = this.props.events.slice(i + 1).find(e => this._shouldShowEvent(e));
537-
538543
// make sure we unpack the array returned by _getTilesForEvent,
539544
// otherwise react will auto-generate keys and we will end up
540545
// replacing all of the DOM elements every time we paginate.
@@ -1032,7 +1037,7 @@ class RedactionGrouper {
10321037
return panel._shouldShowEvent(ev) && ev.isRedacted();
10331038
}
10341039

1035-
constructor(panel, ev, prevEvent, lastShownEvent) {
1040+
constructor(panel, ev, prevEvent, lastShownEvent, nextEvent, nextEventTile) {
10361041
this.panel = panel;
10371042
this.readMarker = panel._readMarkerForEvent(
10381043
ev.getId(),
@@ -1041,6 +1046,8 @@ class RedactionGrouper {
10411046
this.events = [ev];
10421047
this.prevEvent = prevEvent;
10431048
this.lastShownEvent = lastShownEvent;
1049+
this.nextEvent = nextEvent;
1050+
this.nextEventTile = nextEventTile;
10441051
}
10451052

10461053
shouldGroup(ev) {
@@ -1089,7 +1096,8 @@ class RedactionGrouper {
10891096
const senders = new Set();
10901097
let eventTiles = this.events.map((e, i) => {
10911098
senders.add(e.sender);
1092-
return panel._getTilesForEvent(i === 0 ? this.prevEvent : this.events[i - 1], e, e === lastShownEvent);
1099+
const prevEvent = i === 0 ? this.prevEvent : this.events[i - 1];
1100+
return panel._getTilesForEvent(prevEvent, e, e === lastShownEvent, this.nextEvent, this.nextEventTile);
10931101
}).reduce((a, b) => a.concat(b), []);
10941102

10951103
if (eventTiles.length === 0) {

0 commit comments

Comments
 (0)