@adminide-stack/yantra-mobile 12.0.105 → 12.0.106-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/features/messaging/BlockedContactsScreen.js +127 -0
- package/lib/features/messaging/BlockedContactsScreen.js.map +1 -0
- package/lib/features/messaging/ChatAttachments.js +4 -2
- package/lib/features/messaging/ChatAttachments.js.map +1 -1
- package/lib/features/messaging/ChatComponents.js +194 -10
- package/lib/features/messaging/ChatComponents.js.map +1 -1
- package/lib/features/messaging/ChatInfoScreen.js +173 -17
- package/lib/features/messaging/ChatInfoScreen.js.map +1 -1
- package/lib/features/messaging/ConversationListScreen.js +17 -1
- package/lib/features/messaging/ConversationListScreen.js.map +1 -1
- package/lib/features/messaging/MediaGalleryScreen.js +264 -0
- package/lib/features/messaging/MediaGalleryScreen.js.map +1 -0
- package/lib/features/messaging/NativeChatExperience.js +137 -18
- package/lib/features/messaging/NativeChatExperience.js.map +1 -1
- package/lib/features/messaging/NewGroupScreen.js +191 -0
- package/lib/features/messaging/NewGroupScreen.js.map +1 -0
- package/lib/features/messaging/PollComposer.js +137 -0
- package/lib/features/messaging/PollComposer.js.map +1 -0
- package/lib/features/messaging/PollVotesScreen.js +122 -0
- package/lib/features/messaging/PollVotesScreen.js.map +1 -0
- package/lib/features/messaging/ThreadScreen.js +180 -13
- package/lib/features/messaging/ThreadScreen.js.map +1 -1
- package/lib/features/messaging/chatLinks.js +39 -2
- package/lib/features/messaging/chatLinks.js.map +1 -1
- package/lib/features/messaging/chatModel.js +186 -19
- package/lib/features/messaging/chatModel.js.map +1 -1
- package/lib/features/messaging/chatOperations.js +111 -2
- package/lib/features/messaging/chatOperations.js.map +1 -1
- package/lib/features/messaging/nativeChatChannelQuery.js +7 -2
- package/lib/features/messaging/nativeChatChannelQuery.js.map +1 -1
- package/lib/features/messaging/useChatData.js +248 -10
- package/lib/features/messaging/useChatData.js.map +1 -1
- package/package.json +4 -4
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chatLinks.js","sources":["../../../src/features/messaging/chatLinks.ts"],"sourcesContent":["/**\n * Links in a message's text, so they can be tapped and shown as a card.\n *\n * Only what a person reads as a link: `http(s)://…` and `www.…`. A bare\n * `example.com` stays text - in chat that is far more often a name than a\n * link, and turning it blue would be a guess the sender did not make.\n */\n\nexport type ChatTextPart
|
|
1
|
+
{"version":3,"file":"chatLinks.js","sources":["../../../src/features/messaging/chatLinks.ts"],"sourcesContent":["/**\n * Links in a message's text, so they can be tapped and shown as a card.\n *\n * Only what a person reads as a link: `http(s)://…` and `www.…`. A bare\n * `example.com` stays text - in chat that is far more often a name than a\n * link, and turning it blue would be a guess the sender did not make.\n */\n\nexport type ChatTextPart =\n | { kind: 'text'; text: string }\n | { kind: 'link'; text: string; url: string }\n | { kind: 'mention'; text: string };\n\n/**\n * An `@name` mention token at the start of the text or after whitespace (so `me@x.com` is not\n * a mention), matching the composer's own rule. The match includes the leading boundary char.\n */\nconst MENTION_RE = /(?:^|\\s)@[\\p{L}\\p{N}][\\p{L}\\p{N}._'’-]*/gu;\n\nconst LINK_RE = /\\b(?:https?:\\/\\/|www\\.)[^\\s<>\"']+/gi;\nconst TRAILING_PUNCTUATION = /[.,;:!?'\"…]+$/;\nconst PAIRS: Record<string, string> = { ')': '(', ']': '[', '}': '{' };\n\n/**\n * A link's end, as a reader sees it: a sentence's full stop or a closing\n * bracket around the link is not part of it, but a bracket the URL itself\n * opened is (`…/wiki/Foo_(bar)`).\n */\nfunction trimEnd(raw: string): string {\n let text = raw;\n for (;;) {\n const before = text;\n text = text.replace(TRAILING_PUNCTUATION, '');\n const last = text[text.length - 1];\n const open = PAIRS[last];\n if (open && text.split(open).length - 1 < text.split(last).length - 1) text = text.slice(0, -1);\n if (text === before) return text;\n }\n}\n\n/** The text with its links cut out, in order. Text with no link is one text part. */\nexport function splitLinks(body: string): ChatTextPart[] {\n const parts: ChatTextPart[] = [];\n let at = 0;\n for (const match of body.matchAll(LINK_RE)) {\n const start = match.index ?? 0;\n const text = trimEnd(match[0]);\n // A bare scheme or `www.` alone is not a link.\n if (text && !/^(https?:\\/\\/|www\\.)$/i.test(text)) {\n if (start > at) parts.push({ kind: 'text', text: body.slice(at, start) });\n parts.push({ kind: 'link', text, url: /^www\\./i.test(text) ? `https://${text}` : text });\n at = start + text.length;\n }\n }\n if (at < body.length) parts.push({ kind: 'text', text: body.slice(at) });\n return parts.length ? parts : [{ kind: 'text', text: body }];\n}\n\n/**\n * Message parts for rendering: links plus, when the message carries @mentions, `@name` tokens as\n * a separate highlighted span. Links take precedence (a mention is never inside a URL). When the\n * message has no mentions this is exactly `splitLinks`, so non-group chats are unaffected.\n */\nexport function splitChatParts(body: string, highlightMentions: boolean): ChatTextPart[] {\n if (!highlightMentions) return splitLinks(body);\n const parts: ChatTextPart[] = [];\n for (const part of splitLinks(body)) {\n if (part.kind !== 'text') {\n parts.push(part);\n continue;\n }\n let at = 0;\n for (const match of part.text.matchAll(MENTION_RE)) {\n const start = match.index ?? 0;\n const whole = match[0];\n // The match may carry a leading whitespace/boundary char before the `@`.\n const atPos = whole.indexOf('@');\n const token = whole.slice(atPos);\n const lead = part.text.slice(at, start) + whole.slice(0, atPos);\n if (lead) parts.push({ kind: 'text', text: lead });\n parts.push({ kind: 'mention', text: token });\n at = start + whole.length;\n }\n if (at < part.text.length) parts.push({ kind: 'text', text: part.text.slice(at) });\n }\n return parts.length ? parts : [{ kind: 'text', text: body }];\n}\n\n/** The first link in the text - the one a message's card shows - or null. */\nexport function firstLink(body: string): string | null {\n for (const part of splitLinks(body)) if (part.kind === 'link') return part.url;\n return null;\n}\n\n/** True when the message is a link and nothing else: the card can stand in for the text. */\nexport function isOnlyALink(body: string): boolean {\n const parts = splitLinks(body.trim());\n return parts.length === 1 && parts[0].kind === 'link';\n}\n\n/**\n * Markdown with every bare link written as an autolink (`<https://…>`), which\n * CommonMark renders as a link without the linkify extension - so text a\n * person typed gets tappable links through the plain markdown renderer. A link\n * already inside `<…>` is left as it is.\n */\nexport function autolinkBareUrls(markdown: string): string {\n return splitLinks(markdown)\n .map((part, i, parts) => {\n // splitLinks only ever returns text/link parts (never mention).\n if (part.kind !== 'link') return part.text;\n const before = parts[i - 1];\n const after = parts[i + 1];\n const wrapped =\n before?.kind === 'text' &&\n before.text.endsWith('<') &&\n after?.kind === 'text' &&\n after.text.startsWith('>');\n return wrapped ? part.text : `<${part.url}>`;\n })\n .join('');\n}\n"],"names":[],"mappings":"AAwBA,MAAM,UAAa,GAAA,2CAAA;AACnB,MAAM,OAAU,GAAA,qCAAA;AAChB,MAAM,oBAAuB,GAAA,eAAA;AAC7B,MAAM,KAAgC,GAAA;AAAA,EACpC,GAAK,EAAA,GAAA;AAAA,EACL,GAAK,EAAA,GAAA;AAAA,EACL,GAAK,EAAA;AACP,CAAA;AAOA,SAAS,QAAQ,GAAqB,EAAA;AACpC,EAAA,IAAI,IAAO,GAAA,GAAA;AACX,EAAS,WAAA;AACP,IAAA,MAAM,MAAS,GAAA,IAAA;AACf,IAAO,IAAA,GAAA,IAAA,CAAK,OAAQ,CAAA,oBAAA,EAAsB,EAAE,CAAA;AAC5C,IAAA,MAAM,IAAO,GAAA,IAAA,CAAK,IAAK,CAAA,MAAA,GAAS,CAAC,CAAA;AACjC,IAAM,MAAA,IAAA,GAAO,MAAM,IAAI,CAAA;AACvB,IAAA,IAAI,QAAQ,IAAK,CAAA,KAAA,CAAM,IAAI,CAAA,CAAE,SAAS,CAAI,GAAA,IAAA,CAAK,KAAM,CAAA,IAAI,EAAE,MAAS,GAAA,CAAA,SAAU,IAAK,CAAA,KAAA,CAAM,GAAG,EAAE,CAAA;AAC9F,IAAI,IAAA,IAAA,KAAS,QAAe,OAAA,IAAA;AAAA;AAEhC;AAGO,SAAS,WAAW,IAA8B,EAAA;AAnDzD,EAAA,IAAA,EAAA;AAoDE,EAAA,MAAM,QAAwB,EAAC;AAC/B,EAAA,IAAI,EAAK,GAAA,CAAA;AACT,EAAA,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CAAK,EAAE,CAAA;AACZ"}
|
|
@@ -17,6 +17,25 @@ var __spreadValues = (a, b) => {
|
|
|
17
17
|
return a;
|
|
18
18
|
};
|
|
19
19
|
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
|
+
const DISAPPEARING_OPTIONS = [{
|
|
21
|
+
label: "Off",
|
|
22
|
+
seconds: 0
|
|
23
|
+
}, {
|
|
24
|
+
label: "24 hours",
|
|
25
|
+
seconds: 86400
|
|
26
|
+
}, {
|
|
27
|
+
label: "7 days",
|
|
28
|
+
seconds: 604800
|
|
29
|
+
}, {
|
|
30
|
+
label: "90 days",
|
|
31
|
+
seconds: 7776e3
|
|
32
|
+
}];
|
|
33
|
+
function disappearingLabel(seconds) {
|
|
34
|
+
const s = Number(seconds) || 0;
|
|
35
|
+
const match = DISAPPEARING_OPTIONS.find((o) => o.seconds === s);
|
|
36
|
+
if (match) return match.label;
|
|
37
|
+
return s > 0 ? "On" : "Off";
|
|
38
|
+
}
|
|
20
39
|
const EDIT_WINDOW_MS = 15 * 6e4;
|
|
21
40
|
const DELETE_FOR_EVERYONE_WINDOW_MS = 48 * 36e5;
|
|
22
41
|
function compareIds(a, b) {
|
|
@@ -115,6 +134,13 @@ function attachmentPreview(post) {
|
|
|
115
134
|
const kind = propsOf(post).attachmentKind;
|
|
116
135
|
return typeof kind === "string" && kind in ATTACHMENT_LABELS ? ATTACHMENT_LABELS[kind] : "";
|
|
117
136
|
}
|
|
137
|
+
function pollPreview(post) {
|
|
138
|
+
if (!post) return "";
|
|
139
|
+
const raw = propsOf(post).poll;
|
|
140
|
+
if (!raw || typeof raw !== "object" || !Array.isArray(raw.options)) return "";
|
|
141
|
+
const q = typeof raw.question === "string" ? raw.question.trim() : "";
|
|
142
|
+
return q ? `\u{1F4CA} Poll \xB7 ${q}` : "\u{1F4CA} Poll";
|
|
143
|
+
}
|
|
118
144
|
const LABEL_TEXTS = new Set(Object.values(ATTACHMENT_LABELS));
|
|
119
145
|
function bodyOf(post, hasAttachments) {
|
|
120
146
|
var _a;
|
|
@@ -158,10 +184,92 @@ function replyOf(post) {
|
|
|
158
184
|
body: typeof raw.body === "string" ? raw.body.slice(0, REPLY_QUOTE_MAX) : ""
|
|
159
185
|
};
|
|
160
186
|
}
|
|
187
|
+
function systemEventOf(post) {
|
|
188
|
+
if (!post.fromServer) return null;
|
|
189
|
+
const raw = propsOf(post).system;
|
|
190
|
+
if (!raw || typeof raw !== "object" || typeof raw.event !== "string" || !raw.event) return null;
|
|
191
|
+
return {
|
|
192
|
+
event: raw.event,
|
|
193
|
+
actorId: typeof raw.actorId === "string" ? raw.actorId : null,
|
|
194
|
+
targetIds: Array.isArray(raw.targetIds) ? raw.targetIds.filter((t) => typeof t === "string") : [],
|
|
195
|
+
value: typeof raw.value === "string" ? raw.value : null
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
function mentionsOf(post) {
|
|
199
|
+
const raw = propsOf(post).mentions;
|
|
200
|
+
return Array.isArray(raw) ? raw.filter((m) => typeof m === "string" && m.length > 0) : [];
|
|
201
|
+
}
|
|
202
|
+
function pollOf(post, viewerId) {
|
|
203
|
+
const raw = propsOf(post).poll;
|
|
204
|
+
if (!raw || typeof raw !== "object" || !Array.isArray(raw.options)) return null;
|
|
205
|
+
const votes = raw.votes && typeof raw.votes === "object" ? raw.votes : {};
|
|
206
|
+
const voters = /* @__PURE__ */ new Set();
|
|
207
|
+
const options = raw.options.map((o) => o).filter((o) => o && typeof o.id === "string").map((o) => {
|
|
208
|
+
const id = String(o.id);
|
|
209
|
+
const arr = Array.isArray(votes[id]) ? votes[id] : [];
|
|
210
|
+
const voterIds = arr.filter((v) => typeof v === "string" && v.length > 0);
|
|
211
|
+
voterIds.forEach((v) => voters.add(v));
|
|
212
|
+
return {
|
|
213
|
+
id,
|
|
214
|
+
text: typeof o.text === "string" ? o.text : "",
|
|
215
|
+
count: voterIds.length,
|
|
216
|
+
voterIds,
|
|
217
|
+
mine: voterIds.includes(viewerId)
|
|
218
|
+
};
|
|
219
|
+
});
|
|
220
|
+
if (!options.length) return null;
|
|
221
|
+
return {
|
|
222
|
+
question: typeof raw.question === "string" ? raw.question : "",
|
|
223
|
+
multiple: raw.multiple === true,
|
|
224
|
+
options,
|
|
225
|
+
totalVoters: voters.size
|
|
226
|
+
};
|
|
227
|
+
}
|
|
228
|
+
function systemText(system, viewerId, nameOf) {
|
|
229
|
+
var _a;
|
|
230
|
+
const youOrName = (id) => id && String(id) === viewerId ? "You" : nameOf(id);
|
|
231
|
+
const actor = youOrName(system.actorId);
|
|
232
|
+
const targets = system.targetIds;
|
|
233
|
+
const targetNames = targets.map((t) => youOrName(t));
|
|
234
|
+
const targetsAreYouOnly = targets.length === 1 && String(targets[0]) === viewerId;
|
|
235
|
+
switch (system.event) {
|
|
236
|
+
case "group.created":
|
|
237
|
+
return system.value ? `${actor} created the group "${system.value}"` : `${actor} created the group`;
|
|
238
|
+
case "member.added":
|
|
239
|
+
return targetsAreYouOnly ? `${actor} added you` : `${actor} added ${targetNames.join(", ")}`;
|
|
240
|
+
case "member.removed":
|
|
241
|
+
return targetsAreYouOnly ? `${actor} removed you` : `${actor} removed ${targetNames.join(", ")}`;
|
|
242
|
+
case "member.left":
|
|
243
|
+
return `${actor} left`;
|
|
244
|
+
case "admin.granted":
|
|
245
|
+
return targetsAreYouOnly ? `${actor} made you an admin` : `${actor} made ${targetNames.join(", ")} an admin`;
|
|
246
|
+
case "admin.dismissed":
|
|
247
|
+
return targetsAreYouOnly ? `${actor} dismissed you as admin` : `${actor} dismissed ${targetNames.join(", ")} as admin`;
|
|
248
|
+
case "group.renamed":
|
|
249
|
+
return system.value ? `${actor} changed the group name to "${system.value}"` : `${actor} changed the group name`;
|
|
250
|
+
case "group.description":
|
|
251
|
+
return `${actor} changed the group description`;
|
|
252
|
+
case "group.sendPolicy":
|
|
253
|
+
return system.value === "adminsOnly" ? `${actor} changed who can send messages to only admins` : `${actor} allowed everyone to send messages`;
|
|
254
|
+
case "chat.disappearing": {
|
|
255
|
+
if (!system.value || system.value === "off") return `${actor} turned off disappearing messages`;
|
|
256
|
+
const durations = {
|
|
257
|
+
"24h": "24 hours",
|
|
258
|
+
"7d": "7 days",
|
|
259
|
+
"90d": "90 days"
|
|
260
|
+
};
|
|
261
|
+
const label = (_a = durations[system.value]) != null ? _a : system.value;
|
|
262
|
+
return `${actor} turned on disappearing messages (${label})`;
|
|
263
|
+
}
|
|
264
|
+
default:
|
|
265
|
+
return "Group updated";
|
|
266
|
+
}
|
|
267
|
+
}
|
|
161
268
|
function toChatMessage(post, viewerId) {
|
|
162
269
|
var _a, _b, _c;
|
|
163
270
|
const author = pickAuthor(post);
|
|
164
271
|
const attachments = toChatAttachments(post);
|
|
272
|
+
const system = systemEventOf(post);
|
|
165
273
|
return {
|
|
166
274
|
id: String(post.id),
|
|
167
275
|
body: bodyOf(post, attachments.length > 0),
|
|
@@ -169,14 +277,19 @@ function toChatMessage(post, viewerId) {
|
|
|
169
277
|
authorId: (author == null ? void 0 : author.id) ? String(author.id) : null,
|
|
170
278
|
authorName: displayNameOf(author),
|
|
171
279
|
authorAvatar: (_c = (_b = author == null ? void 0 : author.picture) != null ? _b : (_a = author == null ? void 0 : author.profile) == null ? void 0 : _a.picture) != null ? _c : null,
|
|
172
|
-
isMine: !!(author == null ? void 0 : author.id) && String(author.id) === viewerId,
|
|
280
|
+
isMine: !system && !!(author == null ? void 0 : author.id) && String(author.id) === viewerId,
|
|
173
281
|
isDeleted: !!post.deletedAt,
|
|
174
282
|
isEdited: !!post.editedAt,
|
|
175
283
|
attachments,
|
|
176
284
|
reactions: toChatReactions(post.reactionSummary, viewerId),
|
|
177
285
|
replyTo: replyOf(post),
|
|
178
286
|
starred: Boolean(post.viewerStarred),
|
|
179
|
-
forwarded: propsOf(post).forwarded === true
|
|
287
|
+
forwarded: propsOf(post).forwarded === true,
|
|
288
|
+
system,
|
|
289
|
+
mentions: mentionsOf(post),
|
|
290
|
+
poll: pollOf(post, viewerId),
|
|
291
|
+
kept: Boolean(propsOf(post).kept),
|
|
292
|
+
disappeared: propsOf(post).disappeared === true
|
|
180
293
|
};
|
|
181
294
|
}
|
|
182
295
|
function deletedPreview(mine) {
|
|
@@ -213,7 +326,7 @@ function canDeleteForEveryone(message, now) {
|
|
|
213
326
|
}
|
|
214
327
|
function firstUnreadId(messages, unreadCount) {
|
|
215
328
|
if (unreadCount <= 0) return null;
|
|
216
|
-
const fromOthers = messages.filter((m) => !m.isMine);
|
|
329
|
+
const fromOthers = messages.filter((m) => !m.isMine && !m.system);
|
|
217
330
|
return fromOthers.length >= unreadCount ? fromOthers[fromOthers.length - unreadCount].id : null;
|
|
218
331
|
}
|
|
219
332
|
function messageReceipts(message, channel, viewerId) {
|
|
@@ -307,6 +420,31 @@ function withViewerReaction(reactions, emoji, viewerId) {
|
|
|
307
420
|
userIds: [viewerId]
|
|
308
421
|
}];
|
|
309
422
|
}
|
|
423
|
+
function withViewerPollVote(poll, optionId, viewerId) {
|
|
424
|
+
var _a, _b;
|
|
425
|
+
const tappedWasMine = (_b = (_a = poll.options.find((o) => o.id === optionId)) == null ? void 0 : _a.mine) != null ? _b : false;
|
|
426
|
+
const clear = (o) => __spreadProps(__spreadValues({}, o), {
|
|
427
|
+
mine: false,
|
|
428
|
+
count: Math.max(0, o.count - 1),
|
|
429
|
+
voterIds: o.voterIds.filter((v) => v !== viewerId)
|
|
430
|
+
});
|
|
431
|
+
const set = (o) => o.mine ? o : __spreadProps(__spreadValues({}, o), {
|
|
432
|
+
mine: true,
|
|
433
|
+
count: o.count + 1,
|
|
434
|
+
voterIds: [...o.voterIds, viewerId]
|
|
435
|
+
});
|
|
436
|
+
const options = poll.options.map((o) => {
|
|
437
|
+
if (o.id === optionId) return tappedWasMine ? clear(o) : set(o);
|
|
438
|
+
if (!poll.multiple && !tappedWasMine && o.mine) return clear(o);
|
|
439
|
+
return o;
|
|
440
|
+
});
|
|
441
|
+
const voters = /* @__PURE__ */ new Set();
|
|
442
|
+
options.forEach((o) => o.voterIds.forEach((v) => voters.add(v)));
|
|
443
|
+
return __spreadProps(__spreadValues({}, poll), {
|
|
444
|
+
options,
|
|
445
|
+
totalVoters: voters.size
|
|
446
|
+
});
|
|
447
|
+
}
|
|
310
448
|
function mergeMessages(existing, incoming) {
|
|
311
449
|
const byId = /* @__PURE__ */ new Map();
|
|
312
450
|
for (const m of existing) byId.set(m.id, m);
|
|
@@ -358,6 +496,22 @@ function unreadOf(channel, viewerId) {
|
|
|
358
496
|
return Math.max(0, total - seen);
|
|
359
497
|
}
|
|
360
498
|
const DIRECT_TYPES = /* @__PURE__ */ new Set(["DIRECT", "Direct", "direct"]);
|
|
499
|
+
const GROUP_TYPES = /* @__PURE__ */ new Set(["GROUP", "Group", "group"]);
|
|
500
|
+
function groupMembersOf(channel, viewerId) {
|
|
501
|
+
var _a, _b;
|
|
502
|
+
const creatorId = ((_a = channel.creator) == null ? void 0 : _a.id) ? String(channel.creator.id) : null;
|
|
503
|
+
return ((_b = channel.members) != null ? _b : []).map((member) => member).filter((m) => m != null && m.user != null && Boolean(m.user.id)).map((m) => {
|
|
504
|
+
var _a2, _b2, _c, _d;
|
|
505
|
+
const id = String(m.user.id);
|
|
506
|
+
return {
|
|
507
|
+
id,
|
|
508
|
+
name: displayNameOf(m.user, ""),
|
|
509
|
+
avatarUrl: (_c = (_b2 = m.user.picture) != null ? _b2 : (_a2 = m.user.profile) == null ? void 0 : _a2.picture) != null ? _c : null,
|
|
510
|
+
isAdmin: String((_d = m.roles) != null ? _d : "") === "admin" || creatorId != null && id === creatorId,
|
|
511
|
+
isYou: id === viewerId
|
|
512
|
+
};
|
|
513
|
+
});
|
|
514
|
+
}
|
|
361
515
|
function looksLikeMachineTitle(value) {
|
|
362
516
|
var _a;
|
|
363
517
|
const label = (_a = value == null ? void 0 : value.trim()) != null ? _a : "";
|
|
@@ -378,57 +532,68 @@ function allMemberNames(channel, viewerId) {
|
|
|
378
532
|
return ((_a = channel.members) != null ? _a : []).map((member) => member == null ? void 0 : member.user).filter((user) => user != null && Boolean(user.id) && String(user.id) !== viewerId).map((user) => displayNameOf(user, "")).filter(Boolean);
|
|
379
533
|
}
|
|
380
534
|
function toConversation(channel, viewerId) {
|
|
381
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t;
|
|
535
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z;
|
|
382
536
|
const peerCandidate = peerOf(channel, viewerId);
|
|
383
537
|
const explicitDirect = DIRECT_TYPES.has(String((_a = channel.type) != null ? _a : ""));
|
|
384
|
-
const
|
|
538
|
+
const explicitGroup = GROUP_TYPES.has(String((_b = channel.type) != null ? _b : ""));
|
|
539
|
+
const populatedMembers = ((_c = channel.members) != null ? _c : []).filter(Boolean);
|
|
385
540
|
const twoParty = populatedMembers.length === 2 && Boolean(peerCandidate);
|
|
386
541
|
const hasMachineLabel = looksLikeMachineTitle(channel.displayName) && looksLikeMachineTitle(channel.title);
|
|
387
542
|
const storedLabel = storedLabelOf(channel);
|
|
388
543
|
const namedGroup = Boolean(channel.type) && Boolean(storedLabel) && storedLabel.toLowerCase() !== displayNameOf(peerCandidate, "").toLowerCase();
|
|
389
|
-
const isDirect = explicitDirect || twoParty && !namedGroup || !channel.type && hasMachineLabel && Boolean(peerCandidate);
|
|
544
|
+
const isDirect = !explicitGroup && (explicitDirect || twoParty && !namedGroup || !channel.type && hasMachineLabel && Boolean(peerCandidate));
|
|
390
545
|
const peer = isDirect ? peerCandidate : null;
|
|
546
|
+
const groupMembers = isDirect ? [] : groupMembersOf(channel, viewerId);
|
|
547
|
+
const viewerIsAdmin = !isDirect && groupMembers.some((m) => m.isYou && m.isAdmin);
|
|
391
548
|
const names = memberNames(channel, viewerId);
|
|
392
549
|
const lastAuthor = channel.lastMessage ? pickAuthor(channel.lastMessage) : null;
|
|
393
550
|
const lastAuthorName = lastAuthor && String(lastAuthor.id) !== viewerId ? displayNameOf(lastAuthor, "") : "";
|
|
394
551
|
const creatorName = displayNameOf(channel.creator, "");
|
|
395
552
|
const groupFallback = names.length ? names.join(", ") : lastAuthorName || (creatorName && creatorName !== "Unknown" ? creatorName : "Chat");
|
|
396
553
|
const title = isDirect ? displayNameOf(peer, storedLabel || lastAuthorName || "Direct message") : storedLabel || groupFallback;
|
|
397
|
-
const topic = looksLikeMachineTitle(channel.topic) ? "" : ((
|
|
554
|
+
const topic = looksLikeMachineTitle(channel.topic) ? "" : ((_d = channel.topic) != null ? _d : "").trim();
|
|
398
555
|
const lastMessageMine = Boolean(lastAuthor == null ? void 0 : lastAuthor.id) && String(lastAuthor.id) === viewerId;
|
|
399
|
-
const lastMessageDeleted = Boolean((
|
|
400
|
-
const preview = lastMessageDeleted ? deletedPreview(lastMessageMine) : ((
|
|
556
|
+
const lastMessageDeleted = Boolean((_e = channel.lastMessage) == null ? void 0 : _e.deletedAt);
|
|
557
|
+
const preview = lastMessageDeleted ? deletedPreview(lastMessageMine) : pollPreview(channel.lastMessage) || ((_g = (_f = channel.lastMessage) == null ? void 0 : _f.message) == null ? void 0 : _g.trim()) || attachmentPreview(channel.lastMessage) || topic;
|
|
401
558
|
return {
|
|
402
559
|
id: String(channel.id),
|
|
403
560
|
title,
|
|
404
561
|
subtitle: preview === title ? "" : preview,
|
|
405
|
-
avatarUrl: (
|
|
562
|
+
avatarUrl: (_q = (_p = (_n = (_m = (_i = peer == null ? void 0 : peer.picture) != null ? _i : (_h = peer == null ? void 0 : peer.profile) == null ? void 0 : _h.picture) != null ? _m : (_l = (_k = (_j = channel.members) == null ? void 0 : _j.find((member) => {
|
|
406
563
|
var _a2;
|
|
407
564
|
return (_a2 = member == null ? void 0 : member.user) == null ? void 0 : _a2.picture;
|
|
408
|
-
})) == null ? void 0 :
|
|
565
|
+
})) == null ? void 0 : _k.user) == null ? void 0 : _l.picture) != null ? _n : lastAuthor == null ? void 0 : lastAuthor.picture) != null ? _p : (_o = lastAuthor == null ? void 0 : lastAuthor.profile) == null ? void 0 : _o.picture) != null ? _q : null,
|
|
409
566
|
lastActivity: toEpoch(channel.lastPostAt) || toEpoch(channel.createdAt),
|
|
410
567
|
unreadCount: unreadOf(channel, viewerId),
|
|
411
568
|
isDirect,
|
|
412
569
|
peer,
|
|
413
570
|
memberNames: allMemberNames(channel, viewerId),
|
|
571
|
+
members: groupMembers,
|
|
572
|
+
viewerIsAdmin,
|
|
573
|
+
onlyAdminsSend: Boolean((_r = channel.settings) == null ? void 0 : _r.onlyAdminsSend),
|
|
574
|
+
disappearingSeconds: Number((_s = channel.settings) == null ? void 0 : _s.disappearingSeconds) || 0,
|
|
575
|
+
creatorId: ((_t = channel.creator) == null ? void 0 : _t.id) ? String(channel.creator.id) : null,
|
|
576
|
+
description: ((_u = channel.description) != null ? _u : "").trim(),
|
|
577
|
+
unreadMentions: Math.max(0, (_v = channel.viewerUnreadMentions) != null ? _v : 0),
|
|
414
578
|
lastMessageMine,
|
|
415
579
|
lastAuthorName: channel.lastMessage && !lastMessageMine ? lastAuthorName : "",
|
|
416
|
-
lastMessageAt: toEpoch((
|
|
580
|
+
lastMessageAt: toEpoch((_w = channel.lastMessage) == null ? void 0 : _w.createdAt),
|
|
417
581
|
readWatermark: readWatermarkOf(channel, viewerId),
|
|
418
582
|
mutedUntil: mutedUntilOf(channel),
|
|
419
583
|
deliveredWatermark: deliveredWatermarkOf(channel, viewerId),
|
|
420
|
-
pinnedAt: toEpoch((
|
|
421
|
-
archivedAt: toEpoch((
|
|
584
|
+
pinnedAt: toEpoch((_x = channel.viewerPinnedAt) != null ? _x : null),
|
|
585
|
+
archivedAt: toEpoch((_y = channel.viewerArchivedAt) != null ? _y : null),
|
|
422
586
|
lastMessageDeleted,
|
|
423
|
-
draft: ((
|
|
587
|
+
draft: ((_z = channel.viewerDraft) != null ? _z : "").trim()
|
|
424
588
|
};
|
|
425
589
|
}
|
|
426
590
|
function sortConversations(list) {
|
|
427
591
|
return list.slice().sort((a, b) => Number(b.pinnedAt > 0) - Number(a.pinnedAt > 0) || b.pinnedAt - a.pinnedAt || b.lastActivity - a.lastActivity || a.title.localeCompare(b.title) || compareIds(a.id, b.id));
|
|
428
592
|
}
|
|
429
593
|
function conversationListKey(c) {
|
|
430
|
-
var _a;
|
|
594
|
+
var _a, _b, _c;
|
|
431
595
|
if ((_a = c.peer) == null ? void 0 : _a.id) return `peer:${String(c.peer.id)}`;
|
|
596
|
+
if (!c.isDirect && ((_c = (_b = c.members) == null ? void 0 : _b.length) != null ? _c : 0) > 0) return `id:${c.id}`;
|
|
432
597
|
const title = c.title.trim().toLowerCase();
|
|
433
598
|
if (!title || title === "chat" || title === "unknown") return `id:${c.id}`;
|
|
434
599
|
if (title.includes(",")) return `id:${c.id}`;
|
|
@@ -436,6 +601,8 @@ function conversationListKey(c) {
|
|
|
436
601
|
return `title:${title}`;
|
|
437
602
|
}
|
|
438
603
|
function personTitle(c) {
|
|
604
|
+
var _a, _b;
|
|
605
|
+
if (!c.isDirect && ((_b = (_a = c.members) == null ? void 0 : _a.length) != null ? _b : 0) > 0) return "";
|
|
439
606
|
const title = c.title.trim().toLowerCase();
|
|
440
607
|
if (!title || title === "chat" || title === "unknown" || title.includes(",")) return "";
|
|
441
608
|
return title;
|
|
@@ -472,7 +639,7 @@ function subtitleAfterPost(conv, preview) {
|
|
|
472
639
|
}
|
|
473
640
|
function patchConversationAfterPost(conv, post, viewerId) {
|
|
474
641
|
var _a;
|
|
475
|
-
const preview = ((_a = post.message) == null ? void 0 : _a.trim()) || attachmentPreview(post);
|
|
642
|
+
const preview = pollPreview(post) || ((_a = post.message) == null ? void 0 : _a.trim()) || attachmentPreview(post);
|
|
476
643
|
const nextSubtitle = subtitleAfterPost(conv, preview);
|
|
477
644
|
const activity = toEpoch(post.createdAt) || Date.now();
|
|
478
645
|
const author = pickAuthor(post);
|
|
@@ -497,7 +664,7 @@ function patchConversationAfterUpdate(conv, post, viewerId) {
|
|
|
497
664
|
subtitle: deletedPreview(mine),
|
|
498
665
|
lastMessageDeleted: true
|
|
499
666
|
});
|
|
500
|
-
const preview = ((_a = post.message) == null ? void 0 : _a.trim()) || attachmentPreview(post);
|
|
667
|
+
const preview = pollPreview(post) || ((_a = post.message) == null ? void 0 : _a.trim()) || attachmentPreview(post);
|
|
501
668
|
return __spreadProps(__spreadValues({}, conv), {
|
|
502
669
|
subtitle: subtitleAfterPost(conv, preview)
|
|
503
670
|
});
|
|
@@ -594,4 +761,4 @@ function muteLabel(mutedUntil, now) {
|
|
|
594
761
|
month: "short",
|
|
595
762
|
day: "numeric"
|
|
596
763
|
})}`;
|
|
597
|
-
}export{ATTACHMENT_LABELS,DELETE_FOR_EVERYONE_WINDOW_MS,EDIT_WINDOW_MS,MUTE_FOREVER_ISO,MUTE_OPTIONS,applyReactionSummary,attachmentPreview,attachmentUrl,canDeleteForEveryone,canEditMessage,conversationListKey,dayLabel,dedupeConversationList,deletedPreview,deliveredWatermarkOf,displayNameOf,emptyListCopy,fileKeyFromUrl,filterConversations,firstUnreadId,initialsOf,isMuted,mergeConversations,mergeMessages,messageReceipts,messageStatus,muteLabel,muteUntilFor,mutedUntilOf,patchConversationAfterPost,patchConversationAfterUpdate,peerOf,pickAuthor,readWatermarkOf,reconcileOptimistic,relativeLabel,replyRefOf,sortConversations,timeLabel,toChatAttachments,toChatMessage,toChatReactions,toConversation,toEpoch,unreadOf,withViewerReaction};//# sourceMappingURL=chatModel.js.map
|
|
764
|
+
}export{ATTACHMENT_LABELS,DELETE_FOR_EVERYONE_WINDOW_MS,DISAPPEARING_OPTIONS,EDIT_WINDOW_MS,MUTE_FOREVER_ISO,MUTE_OPTIONS,applyReactionSummary,attachmentPreview,attachmentUrl,canDeleteForEveryone,canEditMessage,conversationListKey,dayLabel,dedupeConversationList,deletedPreview,deliveredWatermarkOf,disappearingLabel,displayNameOf,emptyListCopy,fileKeyFromUrl,filterConversations,firstUnreadId,groupMembersOf,initialsOf,isMuted,mergeConversations,mergeMessages,messageReceipts,messageStatus,muteLabel,muteUntilFor,mutedUntilOf,patchConversationAfterPost,patchConversationAfterUpdate,peerOf,pickAuthor,pollOf,pollPreview,readWatermarkOf,reconcileOptimistic,relativeLabel,replyRefOf,sortConversations,systemText,timeLabel,toChatAttachments,toChatMessage,toChatReactions,toConversation,toEpoch,unreadOf,withViewerPollVote,withViewerReaction};//# sourceMappingURL=chatModel.js.map
|