From 8d1265748348d90d673ecd4c4f5cf6cfc3b07d63 Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Wed, 29 Jan 2020 11:14:33 +0000 Subject: [PATCH] Filter event types when deciding on activity metrics for DM suggestions Fixes https://github.com/vector-im/riot-web/issues/12083 --- src/components/views/dialogs/InviteDialog.js | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/components/views/dialogs/InviteDialog.js b/src/components/views/dialogs/InviteDialog.js index de11dbf9fa..a911abbf76 100644 --- a/src/components/views/dialogs/InviteDialog.js +++ b/src/components/views/dialogs/InviteDialog.js @@ -351,9 +351,19 @@ export default class InviteDialog extends React.PureComponent { continue; } - const lastEventTs = room.timeline && room.timeline.length - ? room.timeline[room.timeline.length - 1].getTs() - : 0; + // Find the last timestamp for a message event + const searchTypes = ["m.room.message", "m.room.encrypted", "m.sticker"]; + const maxSearchEvents = 20; // to prevent traversing history + let lastEventTs = 0; + if (room.timeline && room.timeline.length) { + for (let i = room.timeline.length - 1; i >= 0; i--) { + const ev = room.timeline[i]; + if (searchTypes.includes(ev.getType())) { + lastEventTs = ev.getTs(); + } + if (room.timeline.length - i > maxSearchEvents) break; + } + } if (!lastEventTs) { // something weird is going on with this room console.warn(`[Invite:Recents] ${userId} (${room.roomId}) has a weird last timestamp: ${lastEventTs}`);