mirror of
https://github.com/signalapp/Signal-Desktop.git
synced 2025-12-25 04:36:46 +00:00
ducks/conversations: Ensure metrics agree with in-memory messages
* ducks/conversations: Ensure metrics agree with in-memory messages * Clean up logic cleaning up metrics
This commit is contained in:
committed by
Ken Powers
parent
7aaee0cb64
commit
4af7a9ae2c
@@ -736,6 +736,21 @@ export function reducer(
|
||||
|
||||
const lookup = fromPairs(messages.map(message => [message.id, message]));
|
||||
|
||||
let { newest, oldest } = metrics;
|
||||
|
||||
// If our metrics are a little out of date, we'll fix them up
|
||||
if (messages.length > 0) {
|
||||
const first = messages[0];
|
||||
if (first && (!oldest || first.received_at < oldest.received_at)) {
|
||||
oldest = pick(first, ['id', 'received_at']);
|
||||
}
|
||||
|
||||
const last = messages[messages.length - 1];
|
||||
if (last && (!newest || last.received_at > newest.received_at)) {
|
||||
newest = pick(last, ['id', 'received_at']);
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
...state,
|
||||
selectedMessage: scrollToMessageId,
|
||||
@@ -753,7 +768,11 @@ export function reducer(
|
||||
? existingConversation.scrollToMessageCounter + 1
|
||||
: 0,
|
||||
messageIds,
|
||||
metrics,
|
||||
metrics: {
|
||||
...metrics,
|
||||
newest,
|
||||
oldest,
|
||||
},
|
||||
resetCounter,
|
||||
heightChangeMessageIds: [],
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user