MCPcopy Create free account
hub / github.com/ChatLab/ChatLab / deduplicateAndSortMessages

Function deduplicateAndSortMessages

packages/core/src/merger/algorithms.ts:219–246  ·  view source on GitHub ↗
(
  sources: Array<{ platform: string; messages: MergerMessage[] }>,
  collidingIds: Set<string>
)

Source from the content-addressed store, hash-verified

217// ==================== Message dedup + sort ====================
218
219export function deduplicateAndSortMessages(
220 sources: Array<{ platform: string; messages: MergerMessage[] }>,
221 collidingIds: Set<string>
222): MergedMessage[] {
223 const seen = new Set<string>()
224 const merged: MergedMessage[] = []
225
226 for (const { platform, messages } of sources) {
227 const p = platform || 'unknown'
228 for (const msg of messages) {
229 const nid = normalizePlatformId(msg.senderPlatformId, p, collidingIds)
230 const key = getMessageKey(msg, nid)
231 if (seen.has(key)) continue
232 seen.add(key)
233 merged.push({
234 sender: nid,
235 accountName: msg.senderAccountName,
236 groupNickname: msg.senderGroupNickname,
237 timestamp: msg.timestamp,
238 type: msg.type,
239 content: msg.content,
240 })
241 }
242 }
243
244 merged.sort((a, b) => a.timestamp - b.timestamp)
245 return merged
246}

Callers 1

algorithms.test.tsFile · 0.90

Calls 3

normalizePlatformIdFunction · 0.85
getMessageKeyFunction · 0.85
addMethod · 0.45

Tested by

no test coverage detected