odant-work 1.0.112 → 1.0.114

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.
@@ -457,6 +457,37 @@ ODA({
457
457
  overflow: visible;
458
458
  padding-bottom: var(--safe-bottom, 0px);
459
459
  }
460
+ .composer-banner {
461
+ align-items: center;
462
+ gap: 8px;
463
+ padding: 6px 12px;
464
+ background: color-mix(in oklch, var(--accent-color, #4f46e5) 8%, var(--content-background, #fff));
465
+ border-bottom: 1px solid color-mix(in oklch, var(--accent-color, #4f46e5) 22%, transparent);
466
+ font-size: 12.5px;
467
+ }
468
+ .composer-banner .banner-icon {
469
+ color: var(--accent-color, #4f46e5);
470
+ flex-shrink: 0;
471
+ }
472
+ .composer-banner .banner-body {
473
+ min-width: 0;
474
+ border-left: 2.5px solid var(--accent-color, #4f46e5);
475
+ padding-left: 8px;
476
+ }
477
+ .composer-banner .banner-title {
478
+ font-weight: 700;
479
+ color: var(--accent-color, #4f46e5);
480
+ font-size: 12px;
481
+ overflow: hidden;
482
+ text-overflow: ellipsis;
483
+ white-space: nowrap;
484
+ }
485
+ .composer-banner .banner-text {
486
+ opacity: .78;
487
+ overflow: hidden;
488
+ text-overflow: ellipsis;
489
+ white-space: nowrap;
490
+ }
460
491
  @media (max-width: 768px) {
461
492
  .feed-top-bar {
462
493
  padding: 4px 8px;
@@ -499,18 +530,26 @@ ODA({
499
530
  }
500
531
  </style>
501
532
  <div class="back"></div>
502
- <chat-ribbon id="ribbon" :$item @chat-item-expanded="onCardExpanded($event)"></chat-ribbon>
533
+ <chat-ribbon id="ribbon" :$item
534
+ @chat-item-expanded="onCardExpanded($event)"
535
+ @chat-reply="onMessageReply($event)"
536
+ @chat-edit="onMessageEdit($event)"
537
+ @chat-delete="onMessageDelete($event)"
538
+ @chat-scroll-to-message="onScrollToMessage($event)"
539
+ @chat-retry-send="onRetrySend($event)"
540
+ @chat-dismiss-send="onDismissSend($event)"></chat-ribbon>
503
541
  <div class="mover" vertical hidden>
504
542
  <oda-button :hidden="$('#ribbon').scrollTop < 0" content shadow icon="icons:chevron-right:270" @tap="$('#ribbon').scrollTop = -($('#ribbon').scrollHeight)"></oda-button>
505
543
  <oda-button :hidden="$('#ribbon').scrollTop > 0" content shadow icon="icons:chevron-right:90" @tap="$('#ribbon').scrollTop = 0"></oda-button>
506
544
  </div>
507
545
  <div vertical shadow content :hidden="hasExpandedCard" class="chat-composer">
508
- <div ~if="replyTarget" horizontal accent-invert style="padding: 4px;">
509
- <div horizontal flex style="overflow: auto; align-self: center;"></div>
510
- <oda-button icon="icons:close" @tap="clear" style="padding: 0"></oda-button>
511
- </div>
512
- <div ~if="replyTarget" light vertical style="overflow-y: auto;" disabled>
513
- <chat-item reply :$file="replyTarget"></chat-item>
546
+ <div class="composer-banner" ~if="replyTarget || editingTarget" horizontal>
547
+ <oda-icon :icon="editingTarget ? 'icons:edit' : 'icons:reply'" :icon-size="16" class="banner-icon"></oda-icon>
548
+ <div class="banner-body" flex vertical>
549
+ <div class="banner-title">{{editingTarget ? 'Редактирование сообщения' : ('Ответ для ' + (replyTarget.senderLabel || 'собеседника'))}}</div>
550
+ <div class="banner-text">{{editingTarget ? editingTarget.content : replyTarget.previewText}}</div>
551
+ </div>
552
+ <oda-button icon="icons:close" :icon-size="16" @tap="cancelComposerMode" title="Отменить"></oda-button>
514
553
  </div>
515
554
  <microchat-voice ~if="voiceOn"></microchat-voice>
516
555
  <work-prompt-bar style="margin: 8px;" @tap="focusedItem = null"
@@ -545,6 +584,8 @@ ODA({
545
584
  return Boolean(this.$pdp?.isPrivate && this.$pdp?.$item?.id && WORK?.uid && this.$pdp.$item.id !== WORK.uid);
546
585
  },
547
586
  get placeholder() {
587
+ if (this.editingTarget)
588
+ return 'Редактировать сообщение ...';
548
589
  if (this.isForeignPrivate) {
549
590
  const lbl = this.$pdp.$item?.DATA?.label || this.$pdp.$item?.label || 'пользователя';
550
591
  return 'Сообщение для ' + lbl + ' ...';
@@ -627,10 +668,96 @@ ODA({
627
668
  this.value = '';
628
669
  this.files = [];
629
670
  this.$pdp.replyTarget = null;
671
+ this.editingTarget = null;
630
672
  this.$pdp.files = [];
631
673
  this.$('#ribbon').lastIdxHistory = -1;
632
674
  this.focusInput();
633
675
  },
676
+ editingTarget: null,
677
+ cancelComposerMode() {
678
+ const wasEdit = Boolean(this.editingTarget);
679
+ this.editingTarget = null;
680
+ this.$pdp.replyTarget = null;
681
+ if (wasEdit)
682
+ this.value = '';
683
+ this.focusInput();
684
+ },
685
+ onMessageReply(e) {
686
+ const d = e?.detail;
687
+ const cm = d?.message;
688
+ if (!cm?.id) return;
689
+ this.editingTarget = null;
690
+ const previewText = String(d.content || '').trim() || (d.attachments?.length ? `Вложение (${d.attachments.length})` : 'Сообщение');
691
+ this.$pdp.replyTarget = {
692
+ id: Number(cm.id),
693
+ sender: cm.sender || d.senderId || '',
694
+ senderLabel: d.senderLabel || cm.sender || 'Собеседник',
695
+ kind: cm.kind || 'text',
696
+ content: previewText,
697
+ previewText,
698
+ attachmentsCount: Array.isArray(d.attachments) ? d.attachments.length : (cm.attachments?.length || 0),
699
+ };
700
+ this.focusInput();
701
+ },
702
+ onMessageEdit(e) {
703
+ const d = e?.detail;
704
+ const cm = d?.message;
705
+ if (!cm?.id) return;
706
+ this.$pdp.replyTarget = null;
707
+ this.editingTarget = {
708
+ id: Number(cm.id),
709
+ threadId: cm.threadId || this.$('#ribbon')?._threadId || '',
710
+ content: String(d.content ?? cm.content ?? ''),
711
+ };
712
+ this.value = this.editingTarget.content;
713
+ this.focusInput();
714
+ },
715
+ async onMessageDelete(e) {
716
+ const d = e?.detail;
717
+ const cm = d?.message;
718
+ const threadId = cm?.threadId || this.$('#ribbon')?._threadId || '';
719
+ const ribbon = this.$('#ribbon');
720
+ if (!cm?.id) return;
721
+ if (cm.meta?.pending || cm.meta?.sendError) {
722
+ ribbon?.removeOptimisticByNonce?.(cm.meta?.clientNonce);
723
+ return;
724
+ }
725
+ if (!threadId || !this.$item?.fetch) return;
726
+ if (typeof WORK?.showConfirm === 'function') {
727
+ try {
728
+ await WORK.showConfirm('Удалить это сообщение?');
729
+ } catch {
730
+ return;
731
+ }
732
+ }
733
+ try {
734
+ await this.$item.fetch('chat_delete', {}, JSON.stringify({ threadId, messageId: Number(cm.id) }));
735
+ ribbon?.applyDeletedMessage?.(Number(cm.id));
736
+ } catch (err) {
737
+ ODA.showMessage?.('Не удалось удалить: ' + (err?.message || err));
738
+ }
739
+ },
740
+ onScrollToMessage(e) {
741
+ const msgId = Number(e?.detail?.messageId);
742
+ if (!msgId) return;
743
+ this.$('#ribbon')?.scrollToMessage?.(msgId);
744
+ },
745
+ async onRetrySend(e) {
746
+ const d = e?.detail;
747
+ const cm = d?.message;
748
+ const nonce = cm?.meta?.clientNonce;
749
+ const retryDraft = cm?.meta?.retryDraft;
750
+ if (!nonce || !retryDraft) return;
751
+ this.$('#ribbon')?.removeOptimisticByNonce?.(nonce);
752
+ this.value = retryDraft.value || '';
753
+ this.files = retryDraft.files || [];
754
+ this.$pdp.replyTarget = retryDraft.reply || null;
755
+ await this.send();
756
+ },
757
+ onDismissSend(e) {
758
+ const nonce = e?.detail?.message?.meta?.clientNonce;
759
+ if (nonce) this.$('#ribbon')?.removeOptimisticByNonce?.(nonce);
760
+ },
634
761
  $public: {
635
762
  showDatePanel: {
636
763
  $def: false,
@@ -683,7 +810,10 @@ ODA({
683
810
  detached() {
684
811
  if (this._onWsChatMsg && globalThis.WORK?.chatEvents) {
685
812
  globalThis.WORK.chatEvents.removeEventListener('chat:message', this._onWsChatMsg);
813
+ globalThis.WORK.chatEvents.removeEventListener('chat:edit', this._onWsChatMsg);
814
+ globalThis.WORK.chatEvents.removeEventListener('chat:delete', this._onWsChatMsg);
686
815
  globalThis.WORK.chatEvents.removeEventListener('chat:action', this._onWsChatMsg);
816
+ globalThis.WORK.chatEvents.removeEventListener('chat:read', this._onWsChatMsg);
687
817
  globalThis.WORK.chatEvents.removeEventListener('task.moved', this._onWsTaskMoved);
688
818
  this._onWsChatMsg = null;
689
819
  this._onWsTaskMoved = null;
@@ -766,20 +896,60 @@ ODA({
766
896
  await ribbon.refreshDates?.(true);
767
897
  await this._openCreated(path);
768
898
  },
899
+ _matchesChatEvent(d) {
900
+ const cur = this.$item;
901
+ if (!d || !cur) return false;
902
+ const curPath = String(cur.path || '/').replace(/\/+$/, '') || '/';
903
+ if (d.kind === 'twin')
904
+ return d.nodePath === curPath;
905
+ if (d.kind === 'dm' && cur.type === '$user') {
906
+ const ribId = this.$('#ribbon')?._threadId;
907
+ if (ribId && d.threadId)
908
+ return d.threadId === ribId;
909
+ if (d.threadId && String(d.threadId).startsWith('dm:')) {
910
+ const parts = String(d.threadId).slice(3).split('|');
911
+ if (parts.length === 2) {
912
+ if (cur.id === WORK.uid)
913
+ return parts[0] === WORK.uid && parts[1] === WORK.uid;
914
+ return parts.includes(cur.id) && parts.includes(WORK.uid);
915
+ }
916
+ }
917
+ return d.message?.sender === cur.id || d.message?.sender === WORK.uid;
918
+ }
919
+ return Boolean(d.threadId && this.$('#ribbon')?._threadId === d.threadId);
920
+ },
769
921
  _bindChatSocket() {
770
922
  if (this._onWsChatMsg) return;
771
923
  globalThis.WORK.chatEvents ??= new EventTarget();
772
924
  this._onWsChatMsg = ev => {
773
925
  const d = ev?.detail;
774
926
  const cur = this.$item;
775
- if (!d || !cur) return;
927
+ if (!d || !cur || !this._matchesChatEvent(d)) return;
928
+ const ribbon = this.$('#ribbon');
776
929
  const curPath = String(cur.path || '/').replace(/\/+$/, '') || '/';
777
- const hitTwin = d.kind === 'twin' && d.nodePath === curPath;
778
- const hitDm = d.kind === 'dm' && cur.type === '$user' && (d.message?.sender === cur.id || d.message?.sender === WORK.uid);
779
- const hitThread = d.threadId && this.$('#ribbon')?._threadId === d.threadId;
780
- if (hitTwin || hitDm || hitThread) {
781
- this.$('#ribbon')?.refreshFeed?.();
782
- if (d.threadId && ev.type === 'chat:message') {
930
+ if (ev.type === 'chat:read') {
931
+ if (d.uid && d.uid !== WORK.uid && d.lastReadId != null)
932
+ ribbon?.applyPeerRead?.(d.lastReadId);
933
+ return;
934
+ }
935
+ if (ev.type === 'chat:delete') {
936
+ if (d.messageId != null)
937
+ ribbon?.applyDeletedMessage?.(d.messageId);
938
+ return;
939
+ }
940
+ if (ev.type === 'chat:edit' || ev.type === 'chat:action') {
941
+ if (d.message)
942
+ ribbon?.applyUpdatedMessage?.(d.message);
943
+ else
944
+ ribbon?.refreshFeed?.();
945
+ return;
946
+ }
947
+ if (ev.type === 'chat:message') {
948
+ if (d.message)
949
+ ribbon?.applyIncomingMessage?.(d.message, d.threadId);
950
+ else
951
+ ribbon?.refreshFeed?.();
952
+ if (d.threadId && d.message?.sender !== WORK.uid) {
783
953
  cur.fetch?.('chat_mark_read', {
784
954
  threadId: d.threadId
785
955
  })?.then?.(res => WORK.applyChatReadLocal?.(res || {
@@ -792,7 +962,10 @@ ODA({
792
962
  }
793
963
  };
794
964
  globalThis.WORK.chatEvents.addEventListener('chat:message', this._onWsChatMsg);
965
+ globalThis.WORK.chatEvents.addEventListener('chat:edit', this._onWsChatMsg);
966
+ globalThis.WORK.chatEvents.addEventListener('chat:delete', this._onWsChatMsg);
795
967
  globalThis.WORK.chatEvents.addEventListener('chat:action', this._onWsChatMsg);
968
+ globalThis.WORK.chatEvents.addEventListener('chat:read', this._onWsChatMsg);
796
969
  },
797
970
  focusInput() {
798
971
  this.$('work-prompt-bar')?.focusInput();
@@ -1046,10 +1219,33 @@ ODA({
1046
1219
  async send() {
1047
1220
  // Один send за раз: повторные Enter/клики игнорируются, иначе каждый клик создаст свою задачу-дубликат.
1048
1221
  if (this._sending) return;
1222
+ const ribbon = this.$('#ribbon');
1223
+ if (this.editingTarget) {
1224
+ const nextText = String(this.value ?? '').trim();
1225
+ if (!nextText) return;
1226
+ const editInfo = { ...this.editingTarget };
1227
+ this._sending = true;
1228
+ try {
1229
+ const res = await this.$item?.fetch?.('chat_edit', {}, JSON.stringify({
1230
+ threadId: editInfo.threadId || ribbon?._threadId || '',
1231
+ messageId: editInfo.id,
1232
+ message: nextText,
1233
+ }));
1234
+ if (res?.message)
1235
+ ribbon?.applyUpdatedMessage?.(res.message);
1236
+ this.editingTarget = null;
1237
+ this.clear();
1238
+ } catch (err) {
1239
+ ODA.showMessage?.('Не удалось изменить сообщение: ' + (err?.message || err));
1240
+ } finally {
1241
+ this._sending = false;
1242
+ }
1243
+ return;
1244
+ }
1049
1245
  const files = this.$('work-prompt-bar')?.files ?? this.files;
1050
1246
  if (!(this.value || files.length)) return;
1051
1247
  chatDebug('send: клик');
1052
- this.$('#ribbon').scrollDown = true;
1248
+ if (ribbon) ribbon.scrollDown = true;
1053
1249
  const text = String(this.value ?? '').trim();
1054
1250
  const list = [...files];
1055
1251
  // Черновик на случай сбоя: поле очищается до сохранения — при ошибке вернуть текст и вложения.
@@ -1068,107 +1264,153 @@ ODA({
1068
1264
  files: list,
1069
1265
  draft
1070
1266
  });
1071
- } else if (this.isForeignPrivate) {
1072
- const uploadedPaths = [];
1073
- if (list.length) {
1074
- const uploadTarget = (await this._ownCabinet()) || this.$pdp.$item;
1075
- const formData = new FormData();
1076
- for (const file of list) formData.append('file', file, file.name);
1077
- const fileParams = {
1078
- encoding: 'utf-8',
1079
- ...(WORK.uid ? { sender: WORK.uid } : {}),
1080
- ignore_save_logs: true
1081
- };
1082
- const savedLogs = await uploadTarget.save_files(formData, fileParams);
1083
- const arr = Array.isArray(savedLogs) ? savedLogs : savedLogs ? [savedLogs] : [];
1084
- for (const l of arr) {
1085
- const p = await pathOfLog(l);
1086
- if (p) uploadedPaths.push(p.startsWith('/') ? p : '/' + p);
1087
- }
1088
- }
1089
- const chatTarget = this.$pdp.$item;
1090
- if (chatTarget?.fetch && (text || uploadedPaths.length)) {
1091
- const chatPayload = {
1092
- kind: 'dm',
1093
- peerId: chatTarget.id,
1094
- message: text,
1095
- attachments: uploadedPaths.map(p => ({
1096
- path: p,
1097
- name: p.split('/').pop() || 'file'
1098
- }))
1099
- };
1100
- await chatTarget.fetch('chat_send', {}, JSON.stringify(chatPayload));
1101
- }
1102
- this.clear();
1103
- this.$('#ribbon')?.refreshFeed?.();
1104
1267
  } else {
1105
- const params = {
1106
- encoding: 'utf-8'
1107
- };
1108
- if (WORK.uid) params.sender = WORK.uid;
1109
- if (this.$pdp.isPrivate && this.$pdp.$item.id !== WORK.uid) params.receivers = [this.$pdp.$item.id];else if (this.$pdp.receivers.length) params.receivers = this.$pdp.receivers.map(u => u.id);
1110
- const uploadedPaths = [];
1111
- const isForeignDm = Boolean(this.$pdp.isPrivate && this.$pdp.$item?.id && this.$pdp.$item.id !== WORK.uid);
1112
- const runWrite = typeof this._runWithCabinetFallback === 'function' ? fn => this._runWithCabinetFallback(fn) : async fn => ({
1113
- target: this.$pdp.$item,
1114
- result: await fn(this.$pdp.$item)
1268
+ const reply = draft.reply;
1269
+ const replyTo = reply?.id ? Number(reply.id) : null;
1270
+ const replyPreview = reply?.id ? {
1271
+ id: Number(reply.id),
1272
+ sender: reply.sender || '',
1273
+ senderLabel: reply.senderLabel || reply.sender || '',
1274
+ kind: reply.kind || 'text',
1275
+ content: String(reply.previewText || reply.content || '').slice(0, 180),
1276
+ attachmentsCount: Number(reply.attachmentsCount) || 0,
1277
+ } : null;
1278
+ const clientNonce = `tmp_${Date.now()}_${Math.random().toString(36).slice(2, 7)}`;
1279
+ const isPrivate = Boolean(this.$pdp.isPrivate);
1280
+ const isForeignDm = Boolean(isPrivate && this.$pdp.$item?.id && this.$pdp.$item.id !== WORK.uid);
1281
+
1282
+ this.clear();
1283
+ ribbon?.addOptimisticMessage?.({
1284
+ clientNonce,
1285
+ sender: WORK.uid,
1286
+ content: text,
1287
+ attachments: list.map(f => ({ path: '', name: f.name })),
1288
+ replyTo,
1289
+ replyPreview,
1290
+ created: Date.now(),
1115
1291
  });
1116
- await runWrite(async target => {
1117
- uploadedPaths.length = 0;
1118
- const uploadTarget = isForeignDm ? (await this._ownCabinet()) || target : target;
1119
- if (list.length) {
1120
- const formData = new FormData();
1121
- for (const file of list) formData.append('file', file, file.name);
1122
- const fileParams = text || isForeignDm ? {
1123
- ...params,
1124
- ignore_save_logs: true
1125
- } : params;
1126
- const savedLogs = await uploadTarget.save_files(formData, fileParams);
1127
- const arr = Array.isArray(savedLogs) ? savedLogs : savedLogs ? [savedLogs] : [];
1128
- for (const l of arr) {
1129
- const p = await pathOfLog(l);
1130
- if (p) uploadedPaths.push(p.startsWith('/') ? p : '/' + p);
1292
+
1293
+ try {
1294
+ if (this.isForeignPrivate) {
1295
+ const uploadedPaths = [];
1296
+ if (list.length) {
1297
+ const uploadTarget = (await this._ownCabinet()) || this.$pdp.$item;
1298
+ const formData = new FormData();
1299
+ for (const file of list) formData.append('file', file, file.name);
1300
+ const fileParams = {
1301
+ encoding: 'utf-8',
1302
+ ...(WORK.uid ? { sender: WORK.uid } : {}),
1303
+ ignore_save_logs: true
1304
+ };
1305
+ const savedLogs = await uploadTarget.save_files(formData, fileParams);
1306
+ const arr = Array.isArray(savedLogs) ? savedLogs : savedLogs ? [savedLogs] : [];
1307
+ for (const l of arr) {
1308
+ const p = await pathOfLog(l);
1309
+ if (p) uploadedPaths.push(p.startsWith('/') ? p : '/' + p);
1310
+ }
1131
1311
  }
1132
- }
1133
- if (text && !isForeignDm) {
1134
- const msgParams = {
1135
- ...params,
1136
- message: text
1137
- };
1138
- if (uploadedPaths.length) msgParams.includes = JSON.stringify(uploadedPaths);
1139
- await target.fetch('save_message', msgParams);
1140
- }
1141
- const chatTarget = this.$pdp.$item || target;
1142
- if (chatTarget?.fetch && (text || uploadedPaths.length)) {
1143
- const chatPayload = {
1144
- kind: this.$pdp.isPrivate ? 'dm' : 'twin',
1145
- ...(this.$pdp.isPrivate ? {
1146
- peerId: this.$pdp.$item?.id || WORK.uid
1147
- } : {}),
1148
- message: text,
1149
- attachments: uploadedPaths.map(p => ({
1150
- path: p,
1151
- name: p.split('/').pop() || 'file'
1152
- }))
1312
+ const chatTarget = this.$pdp.$item;
1313
+ let savedMsg = null;
1314
+ if (chatTarget?.fetch && (text || uploadedPaths.length)) {
1315
+ const chatPayload = {
1316
+ kind: 'dm',
1317
+ peerId: chatTarget.id,
1318
+ message: text,
1319
+ ...(replyTo ? { replyTo } : {}),
1320
+ meta: { clientNonce, ...(replyPreview ? { replyPreview } : {}) },
1321
+ attachments: uploadedPaths.map(p => ({
1322
+ path: p,
1323
+ name: p.split('/').pop() || 'file'
1324
+ }))
1325
+ };
1326
+ savedMsg = await chatTarget.fetch('chat_send', {}, JSON.stringify(chatPayload));
1327
+ }
1328
+ if (savedMsg?.id)
1329
+ ribbon?.resolveOptimisticMessage?.(clientNonce, savedMsg);
1330
+ else
1331
+ ribbon?.removeOptimisticByNonce?.(clientNonce);
1332
+ } else {
1333
+ const params = {
1334
+ encoding: 'utf-8'
1153
1335
  };
1154
- await chatTarget.fetch('chat_send', {}, JSON.stringify(chatPayload))?.catch?.(() => {});
1336
+ if (WORK.uid) params.sender = WORK.uid;
1337
+ if (isPrivate && this.$pdp.$item.id !== WORK.uid) params.receivers = [this.$pdp.$item.id];
1338
+ else if (this.$pdp.receivers.length) params.receivers = this.$pdp.receivers.map(u => u.id);
1339
+ const uploadedPaths = [];
1340
+ const runWrite = typeof this._runWithCabinetFallback === 'function' ? fn => this._runWithCabinetFallback(fn) : async fn => ({
1341
+ target: this.$pdp.$item,
1342
+ result: await fn(this.$pdp.$item)
1343
+ });
1344
+ let savedMsg = null;
1345
+ await runWrite(async target => {
1346
+ uploadedPaths.length = 0;
1347
+ const uploadTarget = isForeignDm ? (await this._ownCabinet()) || target : target;
1348
+ if (list.length) {
1349
+ const formData = new FormData();
1350
+ for (const file of list) formData.append('file', file, file.name);
1351
+ const fileParams = (text || isPrivate) ? {
1352
+ ...params,
1353
+ ignore_save_logs: true
1354
+ } : params;
1355
+ const savedLogs = await uploadTarget.save_files(formData, fileParams);
1356
+ const arr = Array.isArray(savedLogs) ? savedLogs : savedLogs ? [savedLogs] : [];
1357
+ for (const l of arr) {
1358
+ const p = await pathOfLog(l);
1359
+ if (p) uploadedPaths.push(p.startsWith('/') ? p : '/' + p);
1360
+ }
1361
+ }
1362
+ if (text && !isPrivate) {
1363
+ const msgParams = {
1364
+ ...params,
1365
+ message: text
1366
+ };
1367
+ if (uploadedPaths.length) msgParams.includes = JSON.stringify(uploadedPaths);
1368
+ await target.fetch('save_message', msgParams);
1369
+ }
1370
+ const chatTarget = this.$pdp.$item || target;
1371
+ if (chatTarget?.fetch && (text || uploadedPaths.length)) {
1372
+ const chatPayload = {
1373
+ kind: isPrivate ? 'dm' : 'twin',
1374
+ ...(isPrivate ? {
1375
+ peerId: this.$pdp.$item?.id || WORK.uid
1376
+ } : {}),
1377
+ message: text,
1378
+ ...(replyTo ? { replyTo } : {}),
1379
+ meta: { clientNonce, ...(replyPreview ? { replyPreview } : {}) },
1380
+ attachments: uploadedPaths.map(p => ({
1381
+ path: p,
1382
+ name: p.split('/').pop() || 'file'
1383
+ }))
1384
+ };
1385
+ savedMsg = await chatTarget.fetch('chat_send', {}, JSON.stringify(chatPayload));
1386
+ }
1387
+ });
1388
+ if (savedMsg?.id)
1389
+ ribbon?.resolveOptimisticMessage?.(clientNonce, savedMsg);
1390
+ else
1391
+ ribbon?.removeOptimisticByNonce?.(clientNonce);
1155
1392
  }
1156
- });
1157
- this.clear();
1158
- this.$('#ribbon')?.refreshFeed?.();
1393
+ } catch (sendErr) {
1394
+ ribbon?.markOptimisticError?.(clientNonce, sendErr?.message || String(sendErr), draft);
1395
+ throw sendErr;
1396
+ }
1159
1397
  }
1160
1398
  } catch (err) {
1161
1399
  console.warn('[chat] send', err);
1162
- // Сбой — черновик не теряем: текст и вложения обратно в поле.
1163
- this.value = draft.value;
1164
- this.files = draft.files;
1165
- this.$pdp.replyTarget = draft.reply;
1166
- ODA.showMessage?.('Не удалось отправить: ' + (err?.message || err));
1167
- this.focusInput();
1400
+ if (!this.isAIMode && ribbon?._hasOptimisticNonce?.()) {
1401
+ ODA.showMessage?.('Не удалось отправить: ' + (err?.message || err));
1402
+ } else {
1403
+ // Сбой до вставки — черновик возвращаем в поле.
1404
+ this.value = draft.value;
1405
+ this.files = draft.files;
1406
+ this.$pdp.replyTarget = draft.reply;
1407
+ ODA.showMessage?.('Не удалось отправить: ' + (err?.message || err));
1408
+ this.focusInput();
1409
+ }
1168
1410
  } finally {
1169
1411
  this._sending = false;
1170
1412
  }
1171
- this.$('#ribbon').scrollDown = true;
1413
+ if (ribbon) ribbon.scrollDown = true;
1172
1414
  },
1173
1415
  _collectKnownLogKeys() {
1174
1416
  const ribbon = this.$('#ribbon');
@@ -1656,6 +1898,9 @@ ODA({
1656
1898
  get isLocalFeed() {
1657
1899
  return this.$pdp?.feedMode === 'local';
1658
1900
  },
1901
+ get isPrivateFeed() {
1902
+ return Boolean(this.$pdp?.isPrivate || this.$item?.DATA?.isUser);
1903
+ },
1659
1904
  get isForeignUser() {
1660
1905
  return Boolean(this.$pdp?.isPrivate && this.$item?.id && WORK?.uid && this.$item.id !== WORK.uid);
1661
1906
  },
@@ -1663,6 +1908,7 @@ ODA({
1663
1908
  return !this.isLocalFeed && this.$pdp?.feedMode !== 'audit';
1664
1909
  },
1665
1910
  _threadId: '',
1911
+ _peerLastReadId: 0,
1666
1912
  _threadMessages: [],
1667
1913
  _threadMessagesByDay: null,
1668
1914
  _localDayOf(ms) {
@@ -1677,6 +1923,187 @@ ODA({
1677
1923
  if (!day || !(this._threadMessagesByDay instanceof Map)) return [];
1678
1924
  return this._threadMessagesByDay.get(day) || [];
1679
1925
  },
1926
+ _syncThreadByDay() {
1927
+ const byDay = new Map();
1928
+ for (const msg of this._threadMessages || []) {
1929
+ const d = this._localDayOf(msg.created);
1930
+ if (!d) continue;
1931
+ let arr = byDay.get(d);
1932
+ if (!arr) {
1933
+ arr = [];
1934
+ byDay.set(d, arr);
1935
+ }
1936
+ arr.push(msg);
1937
+ }
1938
+ this._threadMessagesByDay = byDay;
1939
+ return byDay;
1940
+ },
1941
+ _hasOptimisticNonce() {
1942
+ return (this._threadMessages || []).some(m => m?.meta?.clientNonce && m?.meta?.sendError);
1943
+ },
1944
+ addOptimisticMessage({ clientNonce, sender, content, attachments = [], replyTo = null, replyPreview = null, created = Date.now() }) {
1945
+ const tmpId = -Math.floor(Date.now() + Math.random() * 1000);
1946
+ const msg = {
1947
+ id: tmpId,
1948
+ threadId: this._threadId || '',
1949
+ sender: sender || WORK.uid || '',
1950
+ kind: 'text',
1951
+ content: String(content || ''),
1952
+ replyTo,
1953
+ attachments,
1954
+ meta: {
1955
+ pending: true,
1956
+ clientNonce,
1957
+ ...(replyPreview ? { replyPreview } : {}),
1958
+ },
1959
+ created,
1960
+ };
1961
+ this.applyIncomingMessage(msg, this._threadId);
1962
+ return msg;
1963
+ },
1964
+ resolveOptimisticMessage(clientNonce, saved) {
1965
+ if (!saved) return;
1966
+ const list = Array.isArray(this._threadMessages) ? [...this._threadMessages] : [];
1967
+ const optIdx = clientNonce ? list.findIndex(m => m?.meta?.clientNonce === clientNonce) : -1;
1968
+ const dupIdx = list.findIndex(m => Number(m?.id) === Number(saved.id));
1969
+ if (optIdx >= 0 && dupIdx >= 0 && optIdx !== dupIdx) {
1970
+ list.splice(optIdx, 1);
1971
+ } else if (optIdx >= 0) {
1972
+ list[optIdx] = saved;
1973
+ } else if (dupIdx >= 0) {
1974
+ list[dupIdx] = saved;
1975
+ } else {
1976
+ list.push(saved);
1977
+ }
1978
+ this._threadMessages = list;
1979
+ if (saved.threadId) this._threadId = saved.threadId;
1980
+ this._syncThreadByDay();
1981
+ const day = this._localDayOf(saved.created);
1982
+ if (day && !this.dateList.includes(day)) {
1983
+ this.dateList = [...this.dateList, day].sort();
1984
+ this.render();
1985
+ }
1986
+ const dayEl = [...(this.$$('chat-day') || [])].find(d => d.day === day);
1987
+ if (dayEl)
1988
+ dayEl.replaceOptimisticMessage?.(clientNonce, saved);
1989
+ },
1990
+ removeOptimisticByNonce(clientNonce) {
1991
+ if (!clientNonce) return;
1992
+ const prev = Array.isArray(this._threadMessages) ? this._threadMessages : [];
1993
+ const next = prev.filter(m => m?.meta?.clientNonce !== clientNonce);
1994
+ if (next.length === prev.length) return;
1995
+ this._threadMessages = next;
1996
+ this._syncThreadByDay();
1997
+ for (const dayEl of this.$$('chat-day') || []) {
1998
+ dayEl.removeOptimisticByNonce?.(clientNonce);
1999
+ }
2000
+ },
2001
+ markOptimisticError(clientNonce, errText, retryDraft) {
2002
+ if (!clientNonce) return;
2003
+ const list = Array.isArray(this._threadMessages) ? this._threadMessages : [];
2004
+ const target = list.find(m => m?.meta?.clientNonce === clientNonce);
2005
+ if (!target) return;
2006
+ const updated = {
2007
+ ...target,
2008
+ meta: {
2009
+ ...(target.meta || {}),
2010
+ pending: false,
2011
+ sendError: String(errText || 'Ошибка отправки'),
2012
+ retryDraft,
2013
+ },
2014
+ };
2015
+ const idx = list.indexOf(target);
2016
+ list[idx] = updated;
2017
+ this._threadMessages = [...list];
2018
+ this._syncThreadByDay();
2019
+ const day = this._localDayOf(updated.created);
2020
+ const dayEl = [...(this.$$('chat-day') || [])].find(d => d.day === day);
2021
+ dayEl?.upsertThreadMessage?.(updated);
2022
+ },
2023
+ applyIncomingMessage(msg, threadId = '') {
2024
+ if (!msg) return;
2025
+ if (threadId && !this._threadId) this._threadId = threadId;
2026
+ const nonce = msg.meta?.clientNonce;
2027
+ const list = Array.isArray(this._threadMessages) ? [...this._threadMessages] : [];
2028
+ const byIdIdx = msg.id != null ? list.findIndex(m => Number(m?.id) === Number(msg.id)) : -1;
2029
+ const byNonceIdx = nonce ? list.findIndex(m => m?.meta?.clientNonce === nonce) : -1;
2030
+ if (byIdIdx >= 0) {
2031
+ list[byIdIdx] = msg;
2032
+ if (byNonceIdx >= 0 && byNonceIdx !== byIdIdx) list.splice(byNonceIdx, 1);
2033
+ } else if (byNonceIdx >= 0) {
2034
+ list[byNonceIdx] = msg;
2035
+ } else {
2036
+ list.push(msg);
2037
+ }
2038
+ this._threadMessages = list;
2039
+ this._syncThreadByDay();
2040
+ const day = this._localDayOf(msg.created || Date.now());
2041
+ if (day && !this.dateList.includes(day)) {
2042
+ this.dateList = [...this.dateList, day].sort();
2043
+ this.render();
2044
+ }
2045
+ const dayEl = [...(this.$$('chat-day') || [])].find(d => d.day === day);
2046
+ if (dayEl) {
2047
+ if (nonce && byNonceIdx >= 0)
2048
+ dayEl.replaceOptimisticMessage?.(nonce, msg);
2049
+ else
2050
+ dayEl.upsertThreadMessage?.(msg);
2051
+ }
2052
+ this.scrollDown = true;
2053
+ this.async(() => {
2054
+ if (this.scrollDown) {
2055
+ this._savedScrollTop = 0;
2056
+ this.scrollTop = 0;
2057
+ }
2058
+ }, 10);
2059
+ },
2060
+ applyUpdatedMessage(msg) {
2061
+ if (!msg?.id) return;
2062
+ const list = Array.isArray(this._threadMessages) ? [...this._threadMessages] : [];
2063
+ const idx = list.findIndex(m => Number(m?.id) === Number(msg.id));
2064
+ if (idx >= 0) {
2065
+ list[idx] = msg;
2066
+ this._threadMessages = list;
2067
+ this._syncThreadByDay();
2068
+ }
2069
+ const day = this._localDayOf(msg.created || Date.now());
2070
+ const dayEl = [...(this.$$('chat-day') || [])].find(d => d.day === day) || [...(this.$$('chat-day') || [])].find(d => d._wrappedById?.has(`chatmsg.${msg.id}.msg`));
2071
+ dayEl?.upsertThreadMessage?.(msg);
2072
+ },
2073
+ applyDeletedMessage(messageId) {
2074
+ const idNum = Number(messageId);
2075
+ if (!idNum) return;
2076
+ this._threadMessages = (this._threadMessages || []).filter(m => Number(m?.id) !== idNum);
2077
+ this._syncThreadByDay();
2078
+ for (const dayEl of this.$$('chat-day') || []) {
2079
+ dayEl.removeThreadMessage?.(idNum);
2080
+ }
2081
+ },
2082
+ applyPeerRead(lastReadId) {
2083
+ const next = Math.max(Number(this._peerLastReadId) || 0, Number(lastReadId) || 0);
2084
+ if (next <= (this._peerLastReadId || 0)) return;
2085
+ this._peerLastReadId = next;
2086
+ for (const dayEl of this.$$('chat-day') || []) {
2087
+ dayEl.peerLastReadId = next;
2088
+ for (const ci of dayEl.$$?.('chat-item') || []) {
2089
+ ci.peerLastReadId = next;
2090
+ ci.invalidate?.('isReadByPeer');
2091
+ ci.render?.();
2092
+ }
2093
+ }
2094
+ },
2095
+ scrollToMessage(messageId) {
2096
+ const targetId = `chatmsg.${Number(messageId)}.msg`;
2097
+ for (const dayEl of this.$$('chat-day') || []) {
2098
+ const card = [...(dayEl.$$?.('chat-item') || [])].find(ci => ci.$item?.id === targetId || ci.cmId === Number(messageId));
2099
+ if (card) {
2100
+ if (!dayEl.expanded) dayEl.expanded = true;
2101
+ card.scrollIntoView?.({ behavior: 'smooth', block: 'center' });
2102
+ card.flashHighlight?.();
2103
+ return;
2104
+ }
2105
+ }
2106
+ },
1680
2107
  async _resolveLogsSource() {
1681
2108
  return this.$item || null;
1682
2109
  },
@@ -1687,11 +2114,12 @@ ODA({
1687
2114
  if (source && source !== this.$item) source.listen?.('changed', this.onChanged);
1688
2115
  },
1689
2116
  async refreshFeed() {
1690
- this.dateList = [];
1691
2117
  await this.refreshDates(true);
1692
2118
  for (const dayEl of this.$$('chat-day') || []) {
1693
- dayEl._logsInit = false;
1694
- dayEl._ensureLogsInit?.();
2119
+ if (dayEl._logsInit)
2120
+ dayEl._onLogsChangedRun?.();
2121
+ else
2122
+ dayEl._ensureLogsInit?.();
1695
2123
  }
1696
2124
  },
1697
2125
  async refreshDates(force = false) {
@@ -1728,9 +2156,18 @@ ODA({
1728
2156
  const dateSet = new Set((Array.isArray(rawDates) ? rawDates : []).slice().reverse());
1729
2157
  const byDay = new Map();
1730
2158
  const msgs = Array.isArray(threadRes?.messages) ? threadRes.messages : [];
2159
+ const pendingOpt = (this._threadMessages || []).filter(m => m?.meta?.clientNonce && (m?.meta?.pending || m?.meta?.sendError));
1731
2160
  this._threadId = threadRes?.thread?.id || '';
1732
- this._threadMessages = msgs;
1733
- for (const msg of msgs) {
2161
+ const parts = Array.isArray(threadRes?.thread?.participants) ? threadRes.thread.participants : [];
2162
+ const peerReads = parts.filter(p => p?.uid && (this.$item.id === WORK.uid ? p.uid === WORK.uid : p.uid !== WORK.uid)).map(p => Number(p.lastReadId) || 0);
2163
+ this._peerLastReadId = peerReads.length ? Math.max(...peerReads) : 0;
2164
+ const mergedMsgs = [...msgs];
2165
+ for (const opt of pendingOpt) {
2166
+ if (!mergedMsgs.some(m => m?.meta?.clientNonce === opt.meta.clientNonce))
2167
+ mergedMsgs.push(opt);
2168
+ }
2169
+ this._threadMessages = mergedMsgs;
2170
+ for (const msg of mergedMsgs) {
1734
2171
  const d = this._localDayOf(msg.created);
1735
2172
  if (!d) continue;
1736
2173
  dateSet.add(d);
@@ -1770,6 +2207,11 @@ ODA({
1770
2207
  this.render();
1771
2208
  return true;
1772
2209
  }
2210
+ for (const dayEl of this.$$('chat-day') || []) {
2211
+ dayEl.peerLastReadId = this._peerLastReadId;
2212
+ if (dayEl._logsInit && this._threadMessagesByDay?.get(dayEl.day)?.length)
2213
+ dayEl._onLogsChangedRun?.();
2214
+ }
1773
2215
  return false;
1774
2216
  },
1775
2217
  get onChanged() {
@@ -1836,8 +2278,8 @@ ODA({
1836
2278
  width: -webkit-fill-available;
1837
2279
  }
1838
2280
  .day-ribbon{
1839
- gap: 8px;
1840
- padding: 8px;
2281
+ gap: 2px;
2282
+ padding: 8px 12px;
1841
2283
  opacity: 0;
1842
2284
  }
1843
2285
  </style>
@@ -1849,9 +2291,51 @@ ODA({
1849
2291
  </div>
1850
2292
 
1851
2293
  <div class="day-ribbon" flex vertical ~if="expanded">
1852
- <chat-item @tap="setFocus" ~for="logs" :$item="$for.item"></chat-item>
2294
+ <chat-item @tap="setFocus"
2295
+ ~for="logs"
2296
+ :$item="$for.item"
2297
+ :is-dm="isDmFeed"
2298
+ :peer-last-read-id="peerLastReadId"
2299
+ :group-first="_isGroupFirst($for.index)"
2300
+ :group-last="_isGroupLast($for.index)"
2301
+ ~style="{ marginTop: _isGroupFirst($for.index) && $for.index > 0 ? '6px' : '0px' }"></chat-item>
1853
2302
  </div>
1854
2303
  `,
2304
+ get isDmFeed() {
2305
+ return Boolean(this.$pdp?.isPrivateFeed);
2306
+ },
2307
+ get peerLastReadId() {
2308
+ return Number(this.$pdp?._peerLastReadId) || 0;
2309
+ },
2310
+ _itemGroupInfo(it) {
2311
+ if (!it) return null;
2312
+ const row = it.logRow || it.DATA?.logRow;
2313
+ const ext = String(row?.ext || it.ext || '').toLowerCase();
2314
+ const p = String(row?.path || it.path || it.id || '');
2315
+ if (ext === 'task' || ext === 'call' || ext === 'operation' || ext === 'object' || p.endsWith('.task') || p.endsWith('.call'))
2316
+ return null;
2317
+ const sender = String(row?.sender || row?.chatMessage?.sender || '').trim();
2318
+ if (!sender) return null;
2319
+ return { sender, time: this._logItemTime(it) };
2320
+ },
2321
+ _isGroupFirst(idx) {
2322
+ const items = Array.isArray(this.logItems) ? this.logItems : [];
2323
+ const cur = this._itemGroupInfo(items[idx]);
2324
+ if (!cur) return true;
2325
+ const prev = idx > 0 ? this._itemGroupInfo(items[idx - 1]) : null;
2326
+ if (!prev || prev.sender !== cur.sender) return true;
2327
+ if (cur.time && prev.time && Math.abs(cur.time - prev.time) > 5 * 60 * 1000) return true;
2328
+ return false;
2329
+ },
2330
+ _isGroupLast(idx) {
2331
+ const items = Array.isArray(this.logItems) ? this.logItems : [];
2332
+ const cur = this._itemGroupInfo(items[idx]);
2333
+ if (!cur) return true;
2334
+ const next = idx + 1 < items.length ? this._itemGroupInfo(items[idx + 1]) : null;
2335
+ if (!next || next.sender !== cur.sender) return true;
2336
+ if (next.time && cur.time && Math.abs(next.time - cur.time) > 5 * 60 * 1000) return true;
2337
+ return false;
2338
+ },
1855
2339
  get expanderIcon() {
1856
2340
  return this.expanded ? 'icons:chevron-right:90' : 'icons:chevron-right';
1857
2341
  },
@@ -2047,6 +2531,89 @@ ODA({
2047
2531
  this._wrappedById.set(id, wrapped);
2048
2532
  return wrapped;
2049
2533
  },
2534
+ _syncCardWithWrapped(wrapped) {
2535
+ if (!wrapped?.id) return;
2536
+ for (const card of this.$$?.('chat-item') || []) {
2537
+ if (card.$item === wrapped || card.$item?.id === wrapped.id) {
2538
+ card.log = { ...wrapped.logRow };
2539
+ card.invalidate?.('log', 'logContent', 'isEdited', 'isPending', 'sendError', 'isReadByPeer', 'cmId', 'attachmentItems', 'replyInfo', 'shortTime');
2540
+ card.render?.();
2541
+ }
2542
+ }
2543
+ },
2544
+ upsertThreadMessage(msg) {
2545
+ if (!msg || !msg.id) return;
2546
+ if (!this._logsInit) {
2547
+ this._ensureLogsInit();
2548
+ return;
2549
+ }
2550
+ const w = this._wrapThreadMessage(msg);
2551
+ if (!w) return;
2552
+ const prev = Array.isArray(this.logItems) ? [...this.logItems] : [];
2553
+ const idx = prev.findIndex(it => it?.id === w.id || (msg.meta?.clientNonce && it?.logRow?.chatMessage?.meta?.clientNonce === msg.meta.clientNonce));
2554
+ if (idx >= 0) {
2555
+ prev[idx] = w;
2556
+ this.logItems = this._sortLogFiles(prev);
2557
+ this.render();
2558
+ this._syncCardWithWrapped(w);
2559
+ return;
2560
+ }
2561
+ this.logItems = this._sortLogFiles([...prev, w]);
2562
+ this.expanded = true;
2563
+ this.render();
2564
+ this._scrollRibbonDown();
2565
+ },
2566
+ replaceOptimisticMessage(clientNonce, saved) {
2567
+ if (!saved) return;
2568
+ if (!this._logsInit) {
2569
+ this._ensureLogsInit();
2570
+ return;
2571
+ }
2572
+ const w = this._wrapThreadMessage(saved);
2573
+ if (!w) return;
2574
+ const prev = Array.isArray(this.logItems) ? [...this.logItems] : [];
2575
+ const optIdx = clientNonce ? prev.findIndex(it => it?.logRow?.chatMessage?.meta?.clientNonce === clientNonce) : -1;
2576
+ const dupIdx = prev.findIndex(it => it?.id === w.id);
2577
+ if (optIdx >= 0 && dupIdx >= 0 && optIdx !== dupIdx) {
2578
+ const oldOpt = prev[optIdx];
2579
+ prev.splice(optIdx, 1);
2580
+ if (oldOpt?.id && this._wrappedById instanceof Map) this._wrappedById.delete(oldOpt.id);
2581
+ } else if (optIdx >= 0) {
2582
+ const oldOpt = prev[optIdx];
2583
+ if (oldOpt?.id && oldOpt.id !== w.id && this._wrappedById instanceof Map) this._wrappedById.delete(oldOpt.id);
2584
+ prev[optIdx] = w;
2585
+ } else if (dupIdx >= 0) {
2586
+ prev[dupIdx] = w;
2587
+ } else {
2588
+ prev.push(w);
2589
+ }
2590
+ this.logItems = this._sortLogFiles(prev);
2591
+ this.expanded = true;
2592
+ this.render();
2593
+ this._syncCardWithWrapped(w);
2594
+ },
2595
+ removeOptimisticByNonce(clientNonce) {
2596
+ if (!clientNonce || !Array.isArray(this.logItems)) return;
2597
+ const next = this.logItems.filter(it => {
2598
+ const match = it?.logRow?.chatMessage?.meta?.clientNonce === clientNonce;
2599
+ if (match && it?.id && this._wrappedById instanceof Map) this._wrappedById.delete(it.id);
2600
+ return !match;
2601
+ });
2602
+ if (next.length !== this.logItems.length) {
2603
+ this.logItems = next;
2604
+ this.render();
2605
+ }
2606
+ },
2607
+ removeThreadMessage(messageId) {
2608
+ const idStr = `chatmsg.${Number(messageId)}.msg`;
2609
+ if (this._wrappedById instanceof Map) this._wrappedById.delete(idStr);
2610
+ if (!Array.isArray(this.logItems)) return;
2611
+ const next = this.logItems.filter(it => it?.id !== idStr);
2612
+ if (next.length !== this.logItems.length) {
2613
+ this.logItems = next;
2614
+ this.render();
2615
+ }
2616
+ },
2050
2617
  async _bindLogsFolder() {
2051
2618
  const source = await Promise.resolve(this.logsSource);
2052
2619
  return !!source;
@@ -2112,6 +2679,7 @@ ODA({
2112
2679
  }
2113
2680
  const msgs = this.$pdp.threadMessagesForDay(this.day);
2114
2681
  for (const m of msgs) {
2682
+ if (m.meta?.deleted) continue;
2115
2683
  if (m.taskPath && taskKeys.has(taskKeyOf(m.taskPath))) continue;
2116
2684
  if (!String(m.content || '').trim() && !m.attachments?.length && m.kind !== 'approval') continue;
2117
2685
  if (m.sender !== '$twin' && m.kind === 'text' && rows.some(r => r?.sender === m.sender && String(r?.content || '').trim() === String(m.content || '').trim() && Math.abs((Number(r?.time) || 0) - (Number(m.created) || 0)) < 5000)) continue;
@@ -2188,10 +2756,14 @@ ODA({
2188
2756
  const items = await this._fetchLogFiles();
2189
2757
  const prev = Array.isArray(this.logItems) ? this.logItems : [];
2190
2758
  const prevLen = prev.length;
2191
- const sameList = prev.length === items.length && items.every((it, idx) => it === prev[idx] || it?.id && it.id === prev[idx]?.id);
2759
+ const sigOf = it => `${it?.id || ''}|${it?.logRow?.content || ''}|${it?.logRow?.chatMessage?.meta?.editedAt || ''}|${it?.logRow?.chatMessage?.meta?.status || ''}|${it?.logRow?.chatMessage?.meta?.pending ? 1 : 0}|${it?.logRow?.chatMessage?.meta?.sendError || ''}`;
2760
+ const sameList = prev.length === items.length && items.every((it, idx) => (it === prev[idx] || (it?.id && it.id === prev[idx]?.id)) && sigOf(it) === sigOf(prev[idx]));
2192
2761
  if (!sameList) {
2193
2762
  this.logItems = items;
2194
2763
  this.render();
2764
+ for (const it of items) {
2765
+ if (it?.id?.startsWith?.('chatmsg.')) this._syncCardWithWrapped(it);
2766
+ }
2195
2767
  this._syncExpandedTaskCard();
2196
2768
  if (items.length > prevLen) this._scrollRibbonDown();
2197
2769
  }