Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3369935
D9881.id33207.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
3 KB
Referenced Files
None
Subscribers
None
D9881.id33207.diff
View Options
diff --git a/lib/shared/message-utils.js b/lib/shared/message-utils.js
--- a/lib/shared/message-utils.js
+++ b/lib/shared/message-utils.js
@@ -43,6 +43,7 @@
} from '../types/messages/reaction.js';
import type { RawThreadInfo, ThreadInfo } from '../types/thread-types.js';
import type { UserInfos } from '../types/user-types.js';
+import { extractKeyserverIDFromID } from '../utils/action-utils.js';
import {
type EntityText,
ET,
@@ -691,6 +692,25 @@
return !messageSpecs[message.type].canBeRenderedIndependently;
}
+function findNewestMessageTimePerKeyserver(
+ messageInfos: $ReadOnlyArray<RawMessageInfo>,
+): { [keyserverID: string]: number } {
+ const timePerKeyserver: { [keyserverID: string]: number } = {};
+
+ for (const messageInfo of messageInfos) {
+ const keyserverID = extractKeyserverIDFromID(messageInfo.threadID);
+
+ if (
+ !timePerKeyserver[keyserverID] ||
+ timePerKeyserver[keyserverID] < messageInfo.time
+ ) {
+ timePerKeyserver[keyserverID] = messageInfo.time;
+ }
+ }
+
+ return timePerKeyserver;
+}
+
export {
localIDPrefix,
messageKey,
@@ -724,4 +744,5 @@
isInvalidPinSource,
isInvalidPinSourceForThread,
isUnableToBeRenderedIndependently,
+ findNewestMessageTimePerKeyserver,
};
diff --git a/lib/shared/message-utils.test.js b/lib/shared/message-utils.test.js
--- a/lib/shared/message-utils.test.js
+++ b/lib/shared/message-utils.test.js
@@ -4,10 +4,14 @@
isInvalidSidebarSource,
isInvalidPinSource,
isUnableToBeRenderedIndependently,
+ findNewestMessageTimePerKeyserver,
} from './message-utils.js';
import { messageSpecs } from '../shared/messages/message-specs.js';
+import type {
+ RawMessageInfo,
+ RawSidebarSourceMessageInfo,
+} from '../types/message-types';
import { messageTypes } from '../types/message-types-enum.js';
-import type { RawSidebarSourceMessageInfo } from '../types/message-types.js';
import type { RawAddMembersMessageInfo } from '../types/messages/add-members.js';
import type { RawChangeRoleMessageInfo } from '../types/messages/change-role.js';
import type { RawChangeSettingsMessageInfo } from '../types/messages/change-settings.js';
@@ -758,3 +762,41 @@
});
});
});
+
+describe('findNewestMessageTimePerKeyserver', () => {
+ it('should return the time of the newest message for every keyserver', () => {
+ const messages: $ReadOnlyArray<RawMessageInfo> = [
+ {
+ type: 0,
+ threadID: '256|100',
+ creatorID: '256',
+ time: 4,
+ text: 'test',
+ },
+ {
+ type: 0,
+ threadID: '1|100',
+ creatorID: '256',
+ time: 2,
+ text: 'test',
+ },
+ {
+ type: 0,
+ threadID: '1|100',
+ creatorID: '256',
+ time: 3,
+ text: 'test',
+ },
+ {
+ type: 0,
+ threadID: '256|100',
+ creatorID: '256',
+ time: 1,
+ text: 'test',
+ },
+ ];
+
+ const result = { ['256']: 4, ['1']: 3 };
+ expect(findNewestMessageTimePerKeyserver(messages)).toEqual(result);
+ });
+});
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Wed, Nov 27, 12:12 AM (20 h, 38 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2587013
Default Alt Text
D9881.id33207.diff (3 KB)
Attached To
Mode
D9881: [lib] Add function for finding the time of the newest message per keyserver
Attached
Detach File
Event Timeline
Log In to Comment