From 4a5eeec29181bc4f5d398440d9e9acd8bb91ff5f Mon Sep 17 00:00:00 2001 From: Hamish Peebles Date: Tue, 7 Nov 2023 09:18:01 +0000 Subject: [PATCH] Display placeholder message if latest message has expired (#4710) --- .../app/src/components/home/ChatSummary.svelte | 12 +++++++++++- .../home/DisappearingMessageTimeUpdated.svelte | 4 ++-- frontend/app/src/i18n/cn.json | 10 ++++++---- frontend/app/src/i18n/de.json | 10 ++++++---- frontend/app/src/i18n/en.json | 8 +++++--- frontend/app/src/i18n/es.json | 10 ++++++---- frontend/app/src/i18n/fr.json | 10 ++++++---- frontend/app/src/i18n/it.json | 10 ++++++---- frontend/app/src/i18n/iw.json | 10 ++++++---- frontend/app/src/i18n/jp.json | 10 ++++++---- frontend/app/src/i18n/ru.json | 10 ++++++---- frontend/app/src/i18n/vi.json | 10 ++++++---- .../src/services/common/chatMappers.ts | 3 +++ .../src/services/common/publicSummaryMapper.ts | 8 +++++--- .../src/services/community/mappers.ts | 1 + .../openchat-agent/src/services/group/mappers.ts | 2 ++ .../openchat-agent/src/services/openchatAgent.ts | 15 +++++++++++++++ .../openchat-agent/src/services/user/mappers.ts | 6 ++++++ frontend/openchat-agent/src/utils/caching.ts | 2 +- frontend/openchat-agent/src/utils/chat.ts | 4 ++++ frontend/openchat-agent/src/utils/community.ts | 5 +++-- frontend/openchat-client/src/stores/chat.ts | 2 ++ frontend/openchat-client/src/utils/chat.spec.ts | 6 ++++-- frontend/openchat-shared/src/domain/chat/chat.ts | 12 ++++++++---- .../openchat-shared/src/domain/community/index.ts | 1 + 25 files changed, 127 insertions(+), 54 deletions(-) diff --git a/frontend/app/src/components/home/ChatSummary.svelte b/frontend/app/src/components/home/ChatSummary.svelte index 804dc560a4..2a00df6e53 100644 --- a/frontend/app/src/components/home/ChatSummary.svelte +++ b/frontend/app/src/components/home/ChatSummary.svelte @@ -100,10 +100,20 @@ } function formatLatestMessage(chatSummary: ChatSummary, users: UserLookup): string { - if (chatSummary.latestMessage === undefined) { + if (chatSummary.latestMessageIndex === undefined) { return ""; } + if (chatSummary.latestMessage === undefined) { + return chatSummary.eventsTTL !== undefined + ? $_("disappearingMessages.timeUpdated", { + values: { + duration: client.formatDuration(Number(chatSummary.eventsTTL)), + }, + }) + : $_("disappearingMessages.disabled"); + } + const latestMessageText = client.getContentAsText( $_, chatSummary.latestMessage.event.content diff --git a/frontend/app/src/components/home/DisappearingMessageTimeUpdated.svelte b/frontend/app/src/components/home/DisappearingMessageTimeUpdated.svelte index 7283b2edb4..5b3bccf821 100644 --- a/frontend/app/src/components/home/DisappearingMessageTimeUpdated.svelte +++ b/frontend/app/src/components/home/DisappearingMessageTimeUpdated.svelte @@ -19,13 +19,13 @@ $: changedByStr = buildDisplayName($userStore, changedBy, me); $: text = newTimeToLive !== undefined - ? $_("disappearingMessages.timeUpdated", { + ? $_("disappearingMessages.timeUpdatedBy", { values: { changedBy: changedByStr, duration: client.formatDuration(Number(newTimeToLive)), }, }) - : $_("disappearingMessages.disabled", { + : $_("disappearingMessages.disabledBy", { values: { changedBy: changedByStr, }, diff --git a/frontend/app/src/i18n/cn.json b/frontend/app/src/i18n/cn.json index 6e47f6a416..8a0b24c538 100644 --- a/frontend/app/src/i18n/cn.json +++ b/frontend/app/src/i18n/cn.json @@ -1143,9 +1143,11 @@ "minutes": "分钟)", "days": "天)", "summary": "消息将在 {duration} 之后消失", - "timeUpdated": "{changedBy} 将消息消失时间设置为 {duration}", - "disabled": "{changedBy} 禁用消失消息", + "timeUpdatedBy": "{changedBy} 将消息消失时间设置为 {duration}", + "disabledBy": "{changedBy} 禁用消失消息", "durationMinutes": "{duration} 分钟", - "oneMinute": "1分钟" + "oneMinute": "1分钟", + "timeUpdated": "消息消失时间设置为 {duration}", + "disabled": "消息消失已禁用" } -} +} \ No newline at end of file diff --git a/frontend/app/src/i18n/de.json b/frontend/app/src/i18n/de.json index 20c7c747a9..bdfb9df178 100644 --- a/frontend/app/src/i18n/de.json +++ b/frontend/app/src/i18n/de.json @@ -1144,9 +1144,11 @@ "minutes": "Protokoll)", "days": "Tage)", "summary": "Nachrichten verschwinden nach {duration}", - "timeUpdated": "{changedBy} setzt die Zeit für das Verschwinden der Nachricht auf {duration}", - "disabled": "{changedBy} hat das Verschwinden von Nachrichten deaktiviert", + "timeUpdatedBy": "{changedBy} setzt die Zeit für das Verschwinden der Nachricht auf {duration}", + "disabledBy": "{changedBy} hat das Verschwinden von Nachrichten deaktiviert", "durationMinutes": "{duration} Minuten", - "oneMinute": "1 Minute" + "oneMinute": "1 Minute", + "timeUpdated": "Die Zeit für das Verschwinden der Nachricht wurde auf {duration} festgelegt.", + "disabled": "Verschwindende Nachrichten deaktiviert" } -} +} \ No newline at end of file diff --git a/frontend/app/src/i18n/en.json b/frontend/app/src/i18n/en.json index ad5d06e2ef..752bd919df 100644 --- a/frontend/app/src/i18n/en.json +++ b/frontend/app/src/i18n/en.json @@ -1134,9 +1134,11 @@ "minutes": "Minute(s)", "days": "Day(s)", "summary": "Messages will disappear after {duration}", - "timeUpdated": "{changedBy} set the disappearing message time to {duration}", - "disabled": "{changedBy} disabled disappearing messages", + "timeUpdatedBy": "{changedBy} set the disappearing message time to {duration}", + "disabledBy": "{changedBy} disabled disappearing messages", "durationMinutes": "{duration} minutes", - "oneMinute": "1 minute" + "oneMinute": "1 minute", + "timeUpdated": "Disappearing message time set to {duration}", + "disabled": "Disappearing messages disabled" } } diff --git a/frontend/app/src/i18n/es.json b/frontend/app/src/i18n/es.json index e3a2f95844..3d97b0667e 100644 --- a/frontend/app/src/i18n/es.json +++ b/frontend/app/src/i18n/es.json @@ -1144,9 +1144,11 @@ "minutes": "Minutos)", "days": "Días)", "summary": "Los mensajes desaparecerán después de {duration}", - "timeUpdated": "{changedBy} establece el tiempo de desaparición del mensaje en {duration}", - "disabled": "{changedBy} deshabilitó los mensajes que desaparecen", + "timeUpdatedBy": "{changedBy} establece el tiempo de desaparición del mensaje en {duration}", + "disabledBy": "{changedBy} deshabilitó los mensajes que desaparecen", "durationMinutes": "{duration} minutos", - "oneMinute": "1 minuto" + "oneMinute": "1 minuto", + "timeUpdated": "Tiempo de desaparición del mensaje establecido en {duration}", + "disabled": "Mensajes que desaparecen desactivados" } -} +} \ No newline at end of file diff --git a/frontend/app/src/i18n/fr.json b/frontend/app/src/i18n/fr.json index 42a84331c9..9eb00650ba 100644 --- a/frontend/app/src/i18n/fr.json +++ b/frontend/app/src/i18n/fr.json @@ -1142,9 +1142,11 @@ "minutes": "Minutes)", "days": "Jours)", "summary": "Les messages disparaîtront après {duration}", - "timeUpdated": "{changedBy} définit l'heure de disparition du message sur {duration}", - "disabled": "{changedBy} a désactivé les messages qui disparaissent", + "timeUpdatedBy": "{changedBy} définit l'heure de disparition du message sur {duration}", + "disabledBy": "{changedBy} a désactivé les messages qui disparaissent", "durationMinutes": "{duration} minutes", - "oneMinute": "1 minute" + "oneMinute": "1 minute", + "timeUpdated": "Heure de disparition du message définie sur {duration}", + "disabled": "Messages qui disparaissent désactivés" } -} +} \ No newline at end of file diff --git a/frontend/app/src/i18n/it.json b/frontend/app/src/i18n/it.json index e09176d1ec..8577bdccdb 100644 --- a/frontend/app/src/i18n/it.json +++ b/frontend/app/src/i18n/it.json @@ -1142,9 +1142,11 @@ "minutes": "Minuti)", "days": "Giorno(i)", "summary": "I messaggi scompariranno dopo le ore {duration}", - "timeUpdated": "{changedBy} imposta l'ora del messaggio a scomparsa su {duration}", - "disabled": "{changedBy} ha disabilitato i messaggi a scomparsa", + "timeUpdatedBy": "{changedBy} imposta l'ora del messaggio a scomparsa su {duration}", + "disabledBy": "{changedBy} ha disabilitato i messaggi a scomparsa", "durationMinutes": "{duration} minuti", - "oneMinute": "1 minuto" + "oneMinute": "1 minuto", + "timeUpdated": "Orario di scomparsa del messaggio impostato su {duration}", + "disabled": "Messaggi a scomparsa disabilitati" } -} +} \ No newline at end of file diff --git a/frontend/app/src/i18n/iw.json b/frontend/app/src/i18n/iw.json index 36b2bc5d6a..6d13b992a4 100644 --- a/frontend/app/src/i18n/iw.json +++ b/frontend/app/src/i18n/iw.json @@ -1140,9 +1140,11 @@ "minutes": "דקות)", "days": "ימים", "summary": "ההודעות ייעלמו לאחר {duration}", - "timeUpdated": "{changedBy} הגדר את זמן ההודעה הנעלמת ל-{duration}", - "disabled": "{changedBy} השבית הודעות נעלמות", + "timeUpdatedBy": "{changedBy} הגדר את זמן ההודעה הנעלמת ל-{duration}", + "disabledBy": "{changedBy} השבית הודעות נעלמות", "durationMinutes": "{duration} דקות", - "oneMinute": "דקה 1" + "oneMinute": "דקה 1", + "timeUpdated": "זמן ההודעה הנעלמת מוגדר ל-{duration}", + "disabled": "הודעות נעלמות מושבתות" } -} +} \ No newline at end of file diff --git a/frontend/app/src/i18n/jp.json b/frontend/app/src/i18n/jp.json index 2f943ea1b0..f1412e4525 100644 --- a/frontend/app/src/i18n/jp.json +++ b/frontend/app/src/i18n/jp.json @@ -1143,9 +1143,11 @@ "minutes": "分)", "days": "日々)", "summary": "メッセージは {duration} 後に消えます", - "timeUpdated": "{changedBy} はメッセージが消える時間を {duration} に設定します", - "disabled": "{changedBy} は消えるメッセージを無効にしました", + "timeUpdatedBy": "{changedBy} はメッセージが消える時間を {duration} に設定します", + "disabledBy": "{changedBy} は消えるメッセージを無効にしました", "durationMinutes": "{duration}分", - "oneMinute": "1分" + "oneMinute": "1分", + "timeUpdated": "メッセージが消える時間を {duration} に設定しました", + "disabled": "消えるメッセージの無効化" } -} +} \ No newline at end of file diff --git a/frontend/app/src/i18n/ru.json b/frontend/app/src/i18n/ru.json index 34721c3246..bc7a86e64b 100644 --- a/frontend/app/src/i18n/ru.json +++ b/frontend/app/src/i18n/ru.json @@ -1142,9 +1142,11 @@ "minutes": "Минута(ы)", "days": "День(а)", "summary": "Сообщения исчезнут после {duration}", - "timeUpdated": "{changedBy} устанавливает время исчезновения сообщения на {duration}", - "disabled": "{changedBy} отключил исчезающие сообщения", + "timeUpdatedBy": "{changedBy} устанавливает время исчезновения сообщения на {duration}", + "disabledBy": "{changedBy} отключил исчезающие сообщения", "durationMinutes": "{duration} минут", - "oneMinute": "1 минута" + "oneMinute": "1 минута", + "timeUpdated": "Время исчезновения сообщения установлено на {duration}.", + "disabled": "Исчезающие сообщения отключены" } -} +} \ No newline at end of file diff --git a/frontend/app/src/i18n/vi.json b/frontend/app/src/i18n/vi.json index 70054ff796..a1fe261119 100644 --- a/frontend/app/src/i18n/vi.json +++ b/frontend/app/src/i18n/vi.json @@ -1143,9 +1143,11 @@ "minutes": "Phút)", "days": "(Các) ngày", "summary": "Tin nhắn sẽ biến mất sau {duration}", - "timeUpdated": "{changedBy} đặt thời gian tin nhắn biến mất thành {duration}", - "disabled": "{changedBy} đã vô hiệu hóa các tin nhắn biến mất", + "timeUpdatedBy": "{changedBy} đặt thời gian tin nhắn biến mất thành {duration}", + "disabledBy": "{changedBy} đã vô hiệu hóa các tin nhắn biến mất", "durationMinutes": "{duration} phút", - "oneMinute": "1 phút" + "oneMinute": "1 phút", + "timeUpdated": "Thời gian tin nhắn biến mất được đặt thành {duration}", + "disabled": "Tin nhắn biến mất bị vô hiệu hóa" } -} +} \ No newline at end of file diff --git a/frontend/openchat-agent/src/services/common/chatMappers.ts b/frontend/openchat-agent/src/services/common/chatMappers.ts index 33b444b910..aa5da20234 100644 --- a/frontend/openchat-agent/src/services/common/chatMappers.ts +++ b/frontend/openchat-agent/src/services/common/chatMappers.ts @@ -1486,6 +1486,7 @@ export function groupChatSummary(candid: ApiGroupCanisterGroupChatSummary): Grou minVisibleEventIndex: candid.min_visible_event_index, minVisibleMessageIndex: candid.min_visible_message_index, latestEventIndex: candid.latest_event_index, + latestMessageIndex: optional(candid.latest_message_index, identity), lastUpdated: candid.last_updated, blobReference: optional(candid.avatar_id, (blobId) => ({ blobId, @@ -1501,6 +1502,7 @@ export function groupChatSummary(candid: ApiGroupCanisterGroupChatSummary): Grou dateReadPinned: undefined, gate: optional(candid.gate, accessGate) ?? { kind: "no_gate" }, level: "group", + eventsTTL: optional(candid.events_ttl, identity), membership: { joined: candid.joined, role: memberRole(candid.role), @@ -1587,6 +1589,7 @@ export function communityChannelSummary( minVisibleEventIndex: candid.min_visible_event_index, minVisibleMessageIndex: candid.min_visible_message_index, latestEventIndex: candid.latest_event_index, + latestMessageIndex: optional(candid.latest_message_index, identity), lastUpdated: candid.last_updated, blobReference: optional(candid.avatar_id, (blobId) => ({ blobId, diff --git a/frontend/openchat-agent/src/services/common/publicSummaryMapper.ts b/frontend/openchat-agent/src/services/common/publicSummaryMapper.ts index 7f14912e8e..f78a868716 100644 --- a/frontend/openchat-agent/src/services/common/publicSummaryMapper.ts +++ b/frontend/openchat-agent/src/services/common/publicSummaryMapper.ts @@ -3,7 +3,7 @@ import type { ApiPublicGroupSummary, ApiPublicSummaryResponse, } from "../../services/group/candid/idl"; -import { optional } from "../../utils/mapping"; +import { identity, optional } from "../../utils/mapping"; import { apiGroupSubtype, accessGate, messageEvent } from "./chatMappers"; import { nullMembership, @@ -17,6 +17,7 @@ export function publicGroupSummary(candid: ApiPublicGroupSummary): GroupChatSumm kind: "group_chat", id: { kind: "group_chat", groupId: candid.chat_id.toString() }, latestEventIndex: candid.latest_event_index, + latestMessageIndex: optional(candid.latest_message_index, identity), latestMessage: optional(candid.latest_message, messageEvent), name: candid.name, description: candid.description, @@ -40,10 +41,11 @@ export function publicGroupSummary(candid: ApiPublicGroupSummary): GroupChatSumm reactToMessages: "none", mentionAllMembers: "none", messagePermissions: { - default: "none" + default: "none", }, - threadPermissions: undefined + threadPermissions: undefined, }, + eventsTTL: optional(candid.events_ttl, identity), metrics: emptyChatMetrics(), subtype: optional(candid.subtype, apiGroupSubtype), previewed: true, diff --git a/frontend/openchat-agent/src/services/community/mappers.ts b/frontend/openchat-agent/src/services/community/mappers.ts index 48a5eef32a..de9c3e4637 100644 --- a/frontend/openchat-agent/src/services/community/mappers.ts +++ b/frontend/openchat-agent/src/services/community/mappers.ts @@ -461,6 +461,7 @@ export function communityChannelUpdates( membership: optional(candid.membership, channelMembershipUpdates), updatedEvents: candid.updated_events.map(updatedEvent), latestEventIndex: optional(candid.latest_event_index, identity), + latestMessageIndex: optional(candid.latest_message_index, identity), memberCount: optional(candid.member_count, identity), latestMessage: optional(candid.latest_message, messageEvent), eventsTTL: optionUpdate(candid.events_ttl, identity), diff --git a/frontend/openchat-agent/src/services/group/mappers.ts b/frontend/openchat-agent/src/services/group/mappers.ts index bb2a694aa3..2c93c5843a 100644 --- a/frontend/openchat-agent/src/services/group/mappers.ts +++ b/frontend/openchat-agent/src/services/group/mappers.ts @@ -113,6 +113,7 @@ function groupChatSummary(candid: ApiGroupCanisterGroupChatSummary): GroupCanist minVisibleMessageIndex: candid.min_visible_message_index, latestMessage: optional(candid.latest_message, messageEvent), latestEventIndex: candid.latest_event_index, + latestMessageIndex: optional(candid.latest_message_index, identity), joined: candid.joined, memberCount: candid.participant_count, myRole: memberRole(candid.role), @@ -163,6 +164,7 @@ function groupChatSummaryUpdates( public: optional(candid.is_public, identity), latestMessage: optional(candid.latest_message, messageEvent), latestEventIndex: optional(candid.latest_event_index, identity), + latestMessageIndex: optional(candid.latest_message_index, identity), memberCount: optional(candid.participant_count, identity), myRole: optional(candid.role, memberRole), mentions: candid.mentions diff --git a/frontend/openchat-agent/src/services/openchatAgent.ts b/frontend/openchat-agent/src/services/openchatAgent.ts index 17d8cf4f5d..1b74cf1bc6 100644 --- a/frontend/openchat-agent/src/services/openchatAgent.ts +++ b/frontend/openchat-agent/src/services/openchatAgent.ts @@ -1365,6 +1365,10 @@ export class OpenChatAgent extends EventTarget { latestUserCanisterUpdates = userResponse.timestamp; anyUpdates = true; } else { + this.removeExpiredLatestMessages(current.directChats, start); + this.removeExpiredLatestMessages(current.groupChats, start); + current.communities.forEach((c) => this.removeExpiredLatestMessages(c.channels, start)); + directChats = current.directChats; currentGroups = current.groupChats; currentCommunities = current.communities; @@ -1537,6 +1541,17 @@ export class OpenChatAgent extends EventTarget { }; } + private removeExpiredLatestMessages( + chats: { latestMessage?: EventWrapper }[], + now: number, + ) { + for (const chat of chats) { + if (chat.latestMessage?.expiresAt !== undefined && chat.latestMessage.expiresAt < now) { + chat.latestMessage = undefined; + } + } + } + async getCommunitySummary(communityId: string): Promise { const resp = await this.communityClient(communityId).summary(); if (isSuccessfulCommunitySummaryResponse(resp)) { diff --git a/frontend/openchat-agent/src/services/user/mappers.ts b/frontend/openchat-agent/src/services/user/mappers.ts index e879a56b7f..6e4050d2a8 100644 --- a/frontend/openchat-agent/src/services/user/mappers.ts +++ b/frontend/openchat-agent/src/services/user/mappers.ts @@ -775,8 +775,10 @@ function directChatSummaryUpdates(candid: ApiDirectChatSummaryUpdates): DirectCh lastUpdated: candid.last_updated, latestMessage: optional(candid.latest_message, messageEvent), latestEventIndex: optional(candid.latest_event_index, identity), + latestMessageIndex: optional(candid.latest_message_index, identity), notificationsMuted: optional(candid.notifications_muted, identity), updatedEvents: candid.updated_events.map(updatedEvent), + eventsTTL: optionUpdate(candid.events_ttl, identity), metrics: optional(candid.metrics, chatMetrics), myMetrics: optional(candid.my_metrics, chatMetrics), archived: optional(candid.archived, identity), @@ -828,6 +830,7 @@ function groupChatSummary(candid: ApiGroupChatSummary): GroupChatSummary { minVisibleEventIndex: candid.min_visible_event_index, minVisibleMessageIndex: candid.min_visible_message_index, latestEventIndex: candid.latest_event_index, + latestMessageIndex: optional(candid.latest_message_index, identity), lastUpdated: candid.last_updated, blobReference: optional(candid.avatar_id, (blobId) => ({ blobId, @@ -843,6 +846,7 @@ function groupChatSummary(candid: ApiGroupChatSummary): GroupChatSummary { dateReadPinned: optional(candid.date_read_pinned, identity), gate: optional(candid.gate, accessGate) ?? { kind: "no_gate" }, level: "group", + eventsTTL: undefined, membership: { joined: candid.joined, role: memberRole(candid.role), @@ -876,9 +880,11 @@ function directChatSummary(candid: ApiDirectChatSummary): DirectChatSummary { latestMessage: messageEvent(candid.latest_message), them: { kind: "direct_chat", userId: candid.them.toString() }, latestEventIndex: candid.latest_event_index, + latestMessageIndex: candid.latest_message_index, lastUpdated: candid.last_updated, readByThemUpTo: optional(candid.read_by_them_up_to, identity), dateCreated: candid.date_created, + eventsTTL: undefined, metrics: chatMetrics(candid.metrics), membership: { ...nullMembership(), diff --git a/frontend/openchat-agent/src/utils/caching.ts b/frontend/openchat-agent/src/utils/caching.ts index 8e0dd7a5e2..798d4c788e 100644 --- a/frontend/openchat-agent/src/utils/caching.ts +++ b/frontend/openchat-agent/src/utils/caching.ts @@ -38,7 +38,7 @@ import { } from "openchat-shared"; import type { Principal } from "@dfinity/principal"; -const CACHE_VERSION = 87; +const CACHE_VERSION = 88; const MAX_INDEX = 9999999999; export type Database = Promise>; diff --git a/frontend/openchat-agent/src/utils/chat.ts b/frontend/openchat-agent/src/utils/chat.ts index 7e6d31e809..e26a5d07e5 100644 --- a/frontend/openchat-agent/src/utils/chat.ts +++ b/frontend/openchat-agent/src/utils/chat.ts @@ -165,7 +165,9 @@ export function mergeDirectChatUpdates( lastUpdated: u.lastUpdated, latestEventIndex: u.latestEventIndex ?? c.latestEventIndex, latestMessage: u.latestMessage ?? c.latestMessage, + latestMessageIndex: u.latestMessageIndex ?? c.latestMessageIndex, metrics: u.metrics ?? c.metrics, + eventsTTL: applyOptionUpdate(c.eventsTTL, u.eventsTTL), membership: { ...c.membership, readByMeUpTo: u.readByMeUpTo ?? c.membership.readByMeUpTo, @@ -217,6 +219,7 @@ export function mergeGroupChatUpdates( frozen: applyOptionUpdate(c.frozen, g?.frozen) ?? false, latestEventIndex: g?.latestEventIndex ?? c.latestEventIndex, latestMessage, + latestMessageIndex: g?.latestMessageIndex ?? c.latestMessageIndex, metrics: g?.metrics ?? c.metrics, blobReference: applyOptionUpdate(c.blobReference, blobReferenceUpdate), dateLastPinned: g?.dateLastPinned ?? c.dateLastPinned, @@ -276,6 +279,7 @@ export function mergeGroupChats( frozen: g.frozen, latestEventIndex: g.latestEventIndex, latestMessage: g.latestMessage, + latestMessageIndex: g.latestMessageIndex, metrics: g.metrics, blobReference: g.avatarId !== undefined diff --git a/frontend/openchat-agent/src/utils/community.ts b/frontend/openchat-agent/src/utils/community.ts index 25752915b5..5613075761 100644 --- a/frontend/openchat-agent/src/utils/community.ts +++ b/frontend/openchat-agent/src/utils/community.ts @@ -161,11 +161,11 @@ function mergeChannelUpdates( communityCanisterUpdates: CommunityCanisterChannelSummaryUpdates[], ): ChannelSummary[] { const userLookup = ChatMap.fromList(userCanisterUpdates); - const communityLookup = ChatMap.fromList(communityCanisterUpdates); + const channelLookup = ChatMap.fromList(communityCanisterUpdates); return channels.map((channel) => { const u = userLookup.get(channel.id); - const c = communityLookup.get(channel.id); + const c = channelLookup.get(channel.id); if (u === undefined && c === undefined) return channel; @@ -193,6 +193,7 @@ function mergeChannelUpdates( previewed: false, frozen: channel.frozen, // frozen doesn't exist on CommunityCanisterChannelSummaryUpdates latestEventIndex: c?.latestEventIndex ?? channel.latestEventIndex, + latestMessageIndex: c?.latestMessageIndex ?? channel.latestMessageIndex, latestMessage, metrics: c?.metrics ?? channel.metrics, blobReference: applyOptionUpdate(channel.blobReference, blobReferenceUpdate), diff --git a/frontend/openchat-client/src/stores/chat.ts b/frontend/openchat-client/src/stores/chat.ts index 6ebcf94b1e..f86b9a62c0 100644 --- a/frontend/openchat-client/src/stores/chat.ts +++ b/frontend/openchat-client/src/stores/chat.ts @@ -592,9 +592,11 @@ export function createDirectChat(chatId: DirectChatIdentifier): void { readByThemUpTo: undefined, latestMessage: undefined, latestEventIndex: 0, + latestMessageIndex: undefined, lastUpdated: BigInt(Date.now()), dateCreated: BigInt(Date.now()), metrics: emptyChatMetrics(), + eventsTTL: undefined, membership: { ...nullMembership(), role: "owner", diff --git a/frontend/openchat-client/src/utils/chat.spec.ts b/frontend/openchat-client/src/utils/chat.spec.ts index 80ace49be0..bc8d5be8c9 100644 --- a/frontend/openchat-client/src/utils/chat.spec.ts +++ b/frontend/openchat-client/src/utils/chat.spec.ts @@ -34,6 +34,7 @@ const defaultGroupChat: GroupChatSummary = { minVisibleEventIndex: 0, minVisibleMessageIndex: 0, latestEventIndex: 0, + latestMessageIndex: undefined, memberCount: 10, permissions: { changeRoles: "admin", @@ -45,9 +46,9 @@ const defaultGroupChat: GroupChatSummary = { reactToMessages: "member", mentionAllMembers: "member", messagePermissions: { - default: "member" + default: "member", }, - threadPermissions: undefined + threadPermissions: undefined, }, metrics: emptyChatMetrics(), subtype: undefined, @@ -57,6 +58,7 @@ const defaultGroupChat: GroupChatSummary = { dateReadPinned: undefined, gate: { kind: "no_gate" }, level: "group", + eventsTTL: undefined, membership: { archived: false, mentions: [], diff --git a/frontend/openchat-shared/src/domain/chat/chat.ts b/frontend/openchat-shared/src/domain/chat/chat.ts index d18d9640ce..b7963ec5ef 100644 --- a/frontend/openchat-shared/src/domain/chat/chat.ts +++ b/frontend/openchat-shared/src/domain/chat/chat.ts @@ -1073,10 +1073,12 @@ export type DirectChatSummaryUpdates = { readByThemUpTo?: number; readByMeUpTo?: number; lastUpdated: bigint; - latestEventIndex?: number; latestMessage?: EventWrapper; + latestEventIndex?: number; + latestMessageIndex?: number; notificationsMuted?: boolean; updatedEvents: UpdatedEvent[]; + eventsTTL: OptionUpdate; metrics?: Metrics; myMetrics?: Metrics; archived?: boolean; @@ -1167,10 +1169,12 @@ export type ChatType = ChatSummary["kind"]; type ChatSummaryCommon = HasMembershipRole & { lastUpdated: bigint; + latestMessage: EventWrapper | undefined; latestEventIndex: number; - latestMessage?: EventWrapper; + latestMessageIndex: number | undefined; metrics: Metrics; membership: ChatMembership; + eventsTTL: bigint | undefined; }; export type ChannelSummary = DataContent & @@ -1188,7 +1192,6 @@ export type ChannelSummary = DataContent & memberCount: number; dateLastPinned: bigint | undefined; dateReadPinned: bigint | undefined; - eventsTTL?: bigint; }; export type DirectChatSummary = ChatSummaryCommon & { @@ -1215,7 +1218,6 @@ export type GroupChatSummary = DataContent & previewed: boolean; dateLastPinned: bigint | undefined; dateReadPinned: bigint | undefined; - eventsTTL?: bigint; }; export function nullMembership(): ChatMembership { @@ -1266,6 +1268,7 @@ export type GroupCanisterGroupChatSummary = AccessControlled & minVisibleMessageIndex: number; latestMessage: EventWrapper | undefined; latestEventIndex: number; + latestMessageIndex: number | undefined; joined: bigint; myRole: MemberRole; memberCount: number; @@ -1295,6 +1298,7 @@ export type GroupCanisterGroupChatSummaryUpdates = { public: boolean | undefined; latestMessage: EventWrapper | undefined; latestEventIndex: number | undefined; + latestMessageIndex: number | undefined; memberCount: number | undefined; myRole: MemberRole | undefined; mentions: Mention[]; diff --git a/frontend/openchat-shared/src/domain/community/index.ts b/frontend/openchat-shared/src/domain/community/index.ts index 03f630c279..81827f5de3 100644 --- a/frontend/openchat-shared/src/domain/community/index.ts +++ b/frontend/openchat-shared/src/domain/community/index.ts @@ -203,6 +203,7 @@ export type CommunityCanisterChannelSummaryUpdates = { avatarId: OptionUpdate; membership: ChannelMembershipUpdates | undefined; latestEventIndex: number | undefined; + latestMessageIndex: number | undefined; memberCount: number | undefined; latestMessage: EventWrapper | undefined; updatedEvents: UpdatedEvent[];