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

Commit 392cde7

Browse files
authored
Merge pull request #5940 from DantrazTrev/err
Fix the two todays problem
2 parents 70d7a59 + beef07b commit 392cde7

File tree

2 files changed

+45
-16
lines changed

2 files changed

+45
-16
lines changed

src/components/structures/MessagePanel.js

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -544,11 +544,13 @@ export default class MessagePanel extends React.Component {
544544
}
545545
if (!grouper) {
546546
const wantTile = this._shouldShowEvent(mxEv);
547+
const isGrouped = false;
547548
if (wantTile) {
548549
// make sure we unpack the array returned by _getTilesForEvent,
549550
// otherwise react will auto-generate keys and we will end up
550551
// replacing all of the DOM elements every time we paginate.
551-
ret.push(...this._getTilesForEvent(prevEvent, mxEv, last, nextEvent, nextTile));
552+
ret.push(...this._getTilesForEvent(prevEvent, mxEv, last, isGrouped,
553+
nextEvent, nextTile));
552554
prevEvent = mxEv;
553555
}
554556

@@ -564,7 +566,7 @@ export default class MessagePanel extends React.Component {
564566
return ret;
565567
}
566568

567-
_getTilesForEvent(prevEvent, mxEv, last, nextEvent, nextEventWithTile) {
569+
_getTilesForEvent(prevEvent, mxEv, last, isGrouped=false, nextEvent, nextEventWithTile) {
568570
const TileErrorBoundary = sdk.getComponent('messages.TileErrorBoundary');
569571
const EventTile = sdk.getComponent('rooms.EventTile');
570572
const DateSeparator = sdk.getComponent('messages.DateSeparator');
@@ -584,7 +586,7 @@ export default class MessagePanel extends React.Component {
584586

585587
// do we need a date separator since the last event?
586588
const wantsDateSeparator = this._wantsDateSeparator(prevEvent, eventDate);
587-
if (wantsDateSeparator) {
589+
if (wantsDateSeparator && !isGrouped) {
588590
const dateSeparator = <li key={ts1}><DateSeparator key={ts1} ts={ts1} /></li>;
589591
ret.push(dateSeparator);
590592
}
@@ -968,9 +970,9 @@ class CreationGrouper {
968970

969971
const DateSeparator = sdk.getComponent('messages.DateSeparator');
970972
const EventListSummary = sdk.getComponent('views.elements.EventListSummary');
971-
972973
const panel = this.panel;
973974
const ret = [];
975+
const isGrouped = true;
974976
const createEvent = this.createEvent;
975977
const lastShownEvent = this.lastShownEvent;
976978

@@ -984,12 +986,12 @@ class CreationGrouper {
984986
// If this m.room.create event should be shown (room upgrade) then show it before the summary
985987
if (panel._shouldShowEvent(createEvent)) {
986988
// pass in the createEvent as prevEvent as well so no extra DateSeparator is rendered
987-
ret.push(...panel._getTilesForEvent(createEvent, createEvent, false));
989+
ret.push(...panel._getTilesForEvent(createEvent, createEvent));
988990
}
989991

990992
for (const ejected of this.ejectedEvents) {
991993
ret.push(...panel._getTilesForEvent(
992-
createEvent, ejected, createEvent === lastShownEvent,
994+
createEvent, ejected, createEvent === lastShownEvent, isGrouped,
993995
));
994996
}
995997

@@ -998,7 +1000,7 @@ class CreationGrouper {
9981000
// of EventListSummary, render each member event as if the previous
9991001
// one was itself. This way, the timestamp of the previous event === the
10001002
// timestamp of the current event, and no DateSeparator is inserted.
1001-
return panel._getTilesForEvent(e, e, e === lastShownEvent);
1003+
return panel._getTilesForEvent(e, e, e === lastShownEvent, isGrouped);
10021004
}).reduce((a, b) => a.concat(b), []);
10031005
// Get sender profile from the latest event in the summary as the m.room.create doesn't contain one
10041006
const ev = this.events[this.events.length - 1];
@@ -1083,7 +1085,7 @@ class RedactionGrouper {
10831085

10841086
const DateSeparator = sdk.getComponent('messages.DateSeparator');
10851087
const EventListSummary = sdk.getComponent('views.elements.EventListSummary');
1086-
1088+
const isGrouped = true;
10871089
const panel = this.panel;
10881090
const ret = [];
10891091
const lastShownEvent = this.lastShownEvent;
@@ -1103,7 +1105,8 @@ class RedactionGrouper {
11031105
let eventTiles = this.events.map((e, i) => {
11041106
senders.add(e.sender);
11051107
const prevEvent = i === 0 ? this.prevEvent : this.events[i - 1];
1106-
return panel._getTilesForEvent(prevEvent, e, e === lastShownEvent, this.nextEvent, this.nextEventTile);
1108+
return panel._getTilesForEvent(
1109+
prevEvent, e, e === lastShownEvent, isGrouped, this.nextEvent, this.nextEventTile);
11071110
}).reduce((a, b) => a.concat(b), []);
11081111

11091112
if (eventTiles.length === 0) {
@@ -1182,7 +1185,7 @@ class MemberGrouper {
11821185

11831186
const DateSeparator = sdk.getComponent('messages.DateSeparator');
11841187
const MemberEventListSummary = sdk.getComponent('views.elements.MemberEventListSummary');
1185-
1188+
const isGrouped = true;
11861189
const panel = this.panel;
11871190
const lastShownEvent = this.lastShownEvent;
11881191
const ret = [];
@@ -1215,7 +1218,7 @@ class MemberGrouper {
12151218
// of MemberEventListSummary, render each member event as if the previous
12161219
// one was itself. This way, the timestamp of the previous event === the
12171220
// timestamp of the current event, and no DateSeparator is inserted.
1218-
return panel._getTilesForEvent(e, e, e === lastShownEvent);
1221+
return panel._getTilesForEvent(e, e, e === lastShownEvent, isGrouped);
12191222
}).reduce((a, b) => a.concat(b), []);
12201223

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

test/components/structures/MessagePanel-test.js

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ describe('MessagePanel', function() {
7777
DMRoomMap.makeShared();
7878
});
7979

80-
afterEach(function() {
80+
afterEach(function () {
8181
clock.uninstall();
8282
});
8383

@@ -88,7 +88,21 @@ describe('MessagePanel', function() {
8888
events.push(test_utils.mkMessage(
8989
{
9090
event: true, room: "!room:id", user: "@user:id",
91-
ts: ts0 + i*1000,
91+
ts: ts0 + i * 1000,
92+
}));
93+
}
94+
return events;
95+
}
96+
97+
// Just to avoid breaking Dateseparator tests that might run at 00hrs
98+
function mkOneDayEvents() {
99+
const events = [];
100+
const ts0 = Date.parse('09 May 2004 00:12:00 GMT');
101+
for (let i = 0; i < 10; i++) {
102+
events.push(test_utils.mkMessage(
103+
{
104+
event: true, room: "!room:id", user: "@user:id",
105+
ts: ts0 + i * 1000,
92106
}));
93107
}
94108
return events;
@@ -104,7 +118,7 @@ describe('MessagePanel', function() {
104118
let i = 0;
105119
events.push(test_utils.mkMessage({
106120
event: true, room: "!room:id", user: "@user:id",
107-
ts: ts0 + ++i*1000,
121+
ts: ts0 + ++i * 1000,
108122
}));
109123

110124
for (i = 0; i < 10; i++) {
@@ -151,7 +165,7 @@ describe('MessagePanel', function() {
151165
},
152166
getMxcAvatarUrl: () => 'mxc://avatar.url/image.png',
153167
},
154-
ts: ts0 + i*1000,
168+
ts: ts0 + i * 1000,
155169
mship: 'join',
156170
prevMship: 'join',
157171
name: 'A user',
@@ -250,7 +264,6 @@ describe('MessagePanel', function() {
250264
}),
251265
];
252266
}
253-
254267
function isReadMarkerVisible(rmContainer) {
255268
return rmContainer && rmContainer.children.length > 0;
256269
}
@@ -437,4 +450,17 @@ describe('MessagePanel', function() {
437450
// read marker should be hidden given props and at the last event
438451
expect(isReadMarkerVisible(rm)).toBeFalsy();
439452
});
453+
454+
it('should render Date separators for the events', function () {
455+
const events = mkOneDayEvents();
456+
const res = mount(
457+
<WrappedMessagePanel
458+
className="cls"
459+
events={events}
460+
/>,
461+
);
462+
const Dates = res.find(sdk.getComponent('messages.DateSeparator'));
463+
464+
expect(Dates.length).toEqual(1);
465+
});
440466
});

0 commit comments

Comments
 (0)