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.
@@ -429,7 +429,7 @@ ODA({is: 'app-tabs',
429
429
  .tab-action-btn {
430
430
  margin: 4px;
431
431
  flex-shrink: 0;
432
- overflow: hidden;
432
+ overflow: visible;
433
433
  text-overflow: ellipsis;
434
434
  }
435
435
  </style>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "odant-work",
3
- "version": "1.0.112",
3
+ "version": "1.0.114",
4
4
  "description": "ODANT-WORK — платформа цифровой организации (встроенная система учёта, документооборот, управление процессами и приватный мультимодальный ИИ)",
5
5
  "type": "module",
6
6
  "main": "sources/work.js",
package/sources/client.js CHANGED
@@ -489,6 +489,7 @@ WORK.login = async function(force = false){
489
489
  let KEY = secure.getItem('KEY');
490
490
  let uid = WORK.credentials?.uid;
491
491
  if(uid && KEY){
492
+ const wsidBeforeLogin = WORK.wsid || '';
492
493
  if (WORK.uid && WORK.uid !== uid)
493
494
  await WORK.removeCurrentPushSubscription?.();
494
495
  let challengeId = crypto.randomUUID();
@@ -527,6 +528,8 @@ WORK.login = async function(force = false){
527
528
  window.explorer?._refreshLeftButtons?.();
528
529
  await WORK.loadUserSettings?.();
529
530
  WORK.refreshChatUnread?.();
531
+ if (WORK.wsid && WORK.wsid !== wsidBeforeLogin && typeof WORK.fetch === 'function')
532
+ (WORK.USER?.fetch ? WORK.USER.fetch('info', { reset: 1 }) : WORK.fetch('/', 'chat_unread_summary')).catch(() => {});
530
533
  if (authChanged) {
531
534
  WORK._authNotifiedOnce = true;
532
535
  WORK.notifyAuth?.({ uid, reason: 'login' });
@@ -948,6 +951,9 @@ class WebSocketEvents {
948
951
  WORK.chatEvents.dispatchEvent(new CustomEvent('node.deleted', { detail: data }));
949
952
  } break;
950
953
  case 'chat:message':
954
+ case 'chat:edit':
955
+ case 'chat:delete':
956
+ case 'chat:action':
951
957
  case 'chat:read': {
952
958
  WORK.chatEvents ??= new EventTarget();
953
959
  if (data.type === 'chat:message' && data.message?.sender !== WORK.uid) {
@@ -964,7 +970,7 @@ class WebSocketEvents {
964
970
  }
965
971
  WORK.chatUnread.total = (WORK.chatUnread.total || 0) + 1;
966
972
  }
967
- else if (data.type === 'chat:read' && data.threadId) {
973
+ else if (data.type === 'chat:read' && data.threadId && (!data.uid || data.uid === WORK.uid)) {
968
974
  WORK.applyChatReadLocal?.(data);
969
975
  break;
970
976
  }
@@ -60,7 +60,7 @@ export async function aiLayers(place) {
60
60
  if (!dir || !key || seen.has(key))
61
61
  continue;
62
62
  seen.add(key);
63
- dir.reset?.();
63
+ dir.reset?.(undefined, { localOnly: true });
64
64
  out.push({ dir, scope: scopeOfAiDir(dir), owner: dir.$owner || null });
65
65
  }
66
66
  return out;
@@ -161,7 +161,7 @@ export async function loadDocs(place, sub) {
161
161
  const folder = await safe(() => dir.get_item(sub));
162
162
  if (!folder || Array.isArray(folder) || folder.inherit_source)
163
163
  continue;
164
- folder.reset?.();
164
+ folder.reset?.(undefined, { localOnly: true });
165
165
  const kids = folder._collect_own()
166
166
  .filter(f => f instanceof FS.$file)
167
167
  .sort((a, b) => String(a.id || '').localeCompare(String(b.id || '')));
@@ -44,7 +44,7 @@ export const MEMBERS = Object.freeze({
44
44
  logs: L.READ, logs_dates: L.READ, log_files: L.READ, read_log_bodies: L.READ,
45
45
  read_log_entry: L.READ, log_index: L.READ, chatSource: L.READ,
46
46
  chat_thread_open: L.CALL, chat_threads_list: L.READ, chat_messages_list: L.READ,
47
- chat_send: L.CALL, chat_mark_read: L.CALL, chat_action: L.WRITE, chat_unread_summary: L.AUTH, visible_contacts: L.AUTH, my_scope: L.AUTH,
47
+ chat_send: L.CALL, chat_mark_read: L.CALL, chat_action: L.WRITE, chat_edit: L.CALL, chat_delete: L.CALL, chat_unread_summary: L.AUTH, visible_contacts: L.AUTH, my_scope: L.AUTH,
48
48
  mail_accounts: L.READ, mail_list: L.READ, mail_read: L.READ,
49
49
  mail_draft_save: L.WRITE, mail_send: L.WRITE, mail_state: L.WRITE, mail_refresh: L.WRITE,
50
50
  calendar_list: L.READ, calendar_save: L.WRITE,
@@ -386,7 +386,21 @@ export async function sendMessage(storage, params = {}) {
386
386
  const replyTo = params.replyTo != null && Number.isFinite(Number(params.replyTo)) ? Number(params.replyTo) : null;
387
387
  const mentions = normalizeMentions(params.mentions);
388
388
  const attachments = normalizeAttachments(params.attachments);
389
- const meta = (params.meta && typeof params.meta === 'object') ? params.meta : (typeof params.meta === 'string' ? parseJsonSafe(params.meta, {}) : {});
389
+ const meta = (params.meta && typeof params.meta === 'object') ? { ...params.meta } : (typeof params.meta === 'string' ? parseJsonSafe(params.meta, {}) : {});
390
+
391
+ if (replyTo && !meta.replyPreview) {
392
+ const orig = db.prepare('SELECT id, sender, kind, content, attachments FROM chat_messages WHERE id = ? AND thread_id = ?').get(replyTo, threadId);
393
+ if (orig) {
394
+ const origAtts = parseJsonSafe(orig.attachments, []);
395
+ meta.replyPreview = {
396
+ id: Number(orig.id),
397
+ sender: orig.sender,
398
+ kind: orig.kind || 'text',
399
+ content: String(orig.content || '').slice(0, 180),
400
+ attachmentsCount: Array.isArray(origAtts) ? origAtts.length : 0,
401
+ };
402
+ }
403
+ }
390
404
 
391
405
  // Проверяем видимость вложений отправителем и выдаём участникам беседы доступ к конкретным файлам (Q8)
392
406
  const attPaths = attachments.map(a => a.path);
@@ -474,7 +488,8 @@ export async function markRead(storage, params = {}) {
474
488
  const targetId = params.lastMessageId != null ? Math.min(Number(params.lastMessageId) || 0, Number(maxRow?.max_id) || 0) : (Number(maxRow?.max_id) || 0);
475
489
  const nextRead = Math.max(Number(part.last_read_id) || 0, targetId);
476
490
  db.prepare('UPDATE chat_participants SET last_read_id = ? WHERE thread_id = ? AND uid = ?').run(nextRead, threadId, uid);
477
- notifyChatEvent([uid], {
491
+ const allParticipants = db.prepare('SELECT uid FROM chat_participants WHERE thread_id = ?').all(threadId).map(r => r.uid).filter(Boolean);
492
+ notifyChatEvent(allParticipants.length ? allParticipants : [uid], {
478
493
  type: 'chat:read',
479
494
  threadId,
480
495
  kind,
@@ -745,11 +760,90 @@ export async function resolveApproval(storage, params = {}) {
745
760
  notifyChatEvent(thread.participants.map(p => p.uid), {
746
761
  type: 'chat:action',
747
762
  threadId,
763
+ kind: thread.kind,
764
+ nodePath: thread.nodePath,
765
+ message: updated,
766
+ });
767
+ return { ok: true, message: updated };
768
+ }
769
+
770
+ /** Редактировать своё текстовое сообщение в беседе + рассылка по WebSocket. */
771
+ export async function editMessage(storage, params = {}) {
772
+ const uid = resolveActorUid(storage, params);
773
+ if (!uid)
774
+ throw new Error(ACCESS_DENIED);
775
+ const threadId = String(params.threadId || '').trim();
776
+ const messageId = Number(params.messageId);
777
+ const nextContent = String(params.message ?? params.content ?? '').trim();
778
+ if (!threadId || !Number.isFinite(messageId) || !nextContent)
779
+ throw new Error('Требуются threadId, messageId и непустой текст');
780
+
781
+ const kindHint = threadId.startsWith('dm:') ? 'dm' : 'twin';
782
+ const db = await dbForThreadStorage(storage, kindHint);
783
+ const thread = getThreadWithMeta(db, threadId, uid);
784
+ if (!thread)
785
+ throw new Error('Беседа не найдена');
786
+ if (!thread.participants.some(p => p.uid === uid))
787
+ throw new Error(ACCESS_DENIED);
788
+
789
+ const row = db.prepare('SELECT * FROM chat_messages WHERE id = ? AND thread_id = ?').get(messageId, threadId);
790
+ if (!row)
791
+ throw new Error('Сообщение не найдено');
792
+ if (row.sender !== uid)
793
+ throw new Error('Можно редактировать только свои сообщения');
794
+ if (row.kind && !['text', 'dm', 'twin'].includes(row.kind))
795
+ throw new Error('Редактирование доступно только для текстовых сообщений');
796
+
797
+ const meta = parseJsonSafe(row.meta, {});
798
+ const nextMeta = { ...meta, editedAt: Date.now() };
799
+ db.prepare('UPDATE chat_messages SET content = ?, meta = ? WHERE id = ? AND thread_id = ?')
800
+ .run(nextContent, JSON.stringify(nextMeta), messageId, threadId);
801
+ const updated = formatMessageRow(db.prepare('SELECT * FROM chat_messages WHERE id = ?').get(messageId));
802
+ notifyChatEvent(thread.participants.map(p => p.uid), {
803
+ type: 'chat:edit',
804
+ threadId,
805
+ kind: thread.kind,
806
+ nodePath: thread.nodePath,
748
807
  message: updated,
749
808
  });
750
809
  return { ok: true, message: updated };
751
810
  }
752
811
 
812
+ /** Удалить своё сообщение из беседы + рассылка по WebSocket. */
813
+ export async function deleteMessage(storage, params = {}) {
814
+ const uid = resolveActorUid(storage, params);
815
+ if (!uid)
816
+ throw new Error(ACCESS_DENIED);
817
+ const threadId = String(params.threadId || '').trim();
818
+ const messageId = Number(params.messageId);
819
+ if (!threadId || !Number.isFinite(messageId))
820
+ throw new Error('Требуются threadId и messageId');
821
+
822
+ const kindHint = threadId.startsWith('dm:') ? 'dm' : 'twin';
823
+ const db = await dbForThreadStorage(storage, kindHint);
824
+ const thread = getThreadWithMeta(db, threadId, uid);
825
+ if (!thread)
826
+ throw new Error('Беседа не найдена');
827
+ if (!thread.participants.some(p => p.uid === uid))
828
+ throw new Error(ACCESS_DENIED);
829
+
830
+ const row = db.prepare('SELECT * FROM chat_messages WHERE id = ? AND thread_id = ?').get(messageId, threadId);
831
+ if (!row)
832
+ throw new Error('Сообщение не найдено');
833
+ if (row.sender !== uid)
834
+ throw new Error('Можно удалять только свои сообщения');
835
+
836
+ db.prepare('DELETE FROM chat_messages WHERE id = ? AND thread_id = ?').run(messageId, threadId);
837
+ notifyChatEvent(thread.participants.map(p => p.uid), {
838
+ type: 'chat:delete',
839
+ threadId,
840
+ kind: thread.kind,
841
+ nodePath: thread.nodePath,
842
+ messageId,
843
+ });
844
+ return { ok: true, threadId, messageId };
845
+ }
846
+
753
847
  /** Удалить сообщения беседы, привязанные к перенесённой задаче (`task_path`). */
754
848
  export async function deleteTaskMessages(storage, taskPath) {
755
849
  const raw = String(taskPath || '').trim();
@@ -207,6 +207,16 @@ export const classFeedMethods = {
207
207
  return CHAT.resolveApproval(this, mergeChatPost(params, post));
208
208
  },
209
209
 
210
+ /** Редактировать своё сообщение в беседе. */
211
+ async chat_edit(params = {}, post) {
212
+ return CHAT.editMessage(this, mergeChatPost(params, post));
213
+ },
214
+
215
+ /** Удалить своё сообщение из беседы. */
216
+ async chat_delete(params = {}, post) {
217
+ return CHAT.deleteMessage(this, mergeChatPost(params, post));
218
+ },
219
+
210
220
  /** Вычисляемый список видимых контактов («Люди»). */
211
221
  async visible_contacts(params = {}) {
212
222
  return CHAT.visibleContacts(this, params);
@@ -2350,6 +2350,8 @@ export class $folder extends $item{
2350
2350
  }
2351
2351
  reset(initiator, opts){
2352
2352
  this[R].cache = {};
2353
+ if (opts?.localOnly)
2354
+ return true;
2353
2355
  let key = this.short;
2354
2356
  for(let session of Object.values($server.sessions)){
2355
2357
  for(let id in session.sockets){