Skip to content

Commit

Permalink
Display placeholder message if latest message has expired (#4710)
Browse files Browse the repository at this point in the history
  • Loading branch information
hpeebles authored Nov 7, 2023
1 parent a6b5a16 commit 4a5eeec
Show file tree
Hide file tree
Showing 25 changed files with 127 additions and 54 deletions.
12 changes: 11 additions & 1 deletion frontend/app/src/components/home/ChatSummary.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand Down
10 changes: 6 additions & 4 deletions frontend/app/src/i18n/cn.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": "消息消失已禁用"
}
}
}
10 changes: 6 additions & 4 deletions frontend/app/src/i18n/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
}
8 changes: 5 additions & 3 deletions frontend/app/src/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
10 changes: 6 additions & 4 deletions frontend/app/src/i18n/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
}
10 changes: 6 additions & 4 deletions frontend/app/src/i18n/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
}
10 changes: 6 additions & 4 deletions frontend/app/src/i18n/it.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
}
10 changes: 6 additions & 4 deletions frontend/app/src/i18n/iw.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": "הודעות נעלמות מושבתות"
}
}
}
10 changes: 6 additions & 4 deletions frontend/app/src/i18n/jp.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": "消えるメッセージの無効化"
}
}
}
10 changes: 6 additions & 4 deletions frontend/app/src/i18n/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": "Исчезающие сообщения отключены"
}
}
}
10 changes: 6 additions & 4 deletions frontend/app/src/i18n/vi.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
}
3 changes: 3 additions & 0 deletions frontend/openchat-agent/src/services/common/chatMappers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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),
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down
1 change: 1 addition & 0 deletions frontend/openchat-agent/src/services/community/mappers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
2 changes: 2 additions & 0 deletions frontend/openchat-agent/src/services/group/mappers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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
Expand Down
15 changes: 15 additions & 0 deletions frontend/openchat-agent/src/services/openchatAgent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -1537,6 +1541,17 @@ export class OpenChatAgent extends EventTarget {
};
}

private removeExpiredLatestMessages(
chats: { latestMessage?: EventWrapper<Message> }[],
now: number,
) {
for (const chat of chats) {
if (chat.latestMessage?.expiresAt !== undefined && chat.latestMessage.expiresAt < now) {
chat.latestMessage = undefined;
}
}
}

async getCommunitySummary(communityId: string): Promise<CommunitySummaryResponse> {
const resp = await this.communityClient(communityId).summary();
if (isSuccessfulCommunitySummaryResponse(resp)) {
Expand Down
6 changes: 6 additions & 0 deletions frontend/openchat-agent/src/services/user/mappers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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,
Expand All @@ -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),
Expand Down Expand Up @@ -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(),
Expand Down
2 changes: 1 addition & 1 deletion frontend/openchat-agent/src/utils/caching.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<IDBPDatabase<ChatSchema>>;
Expand Down
4 changes: 4 additions & 0 deletions frontend/openchat-agent/src/utils/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down
Loading

0 comments on commit 4a5eeec

Please sign in to comment.