@shaxpir/duiduidui-models 1.24.0 → 1.24.2

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.
@@ -5,6 +5,7 @@ import { ArrayView } from './ArrayView';
5
5
  import { ContentBody, ContentId, ContentMeta } from './Content';
6
6
  import { SharedContent } from './SharedContent';
7
7
  import { SocialUser } from './Social';
8
+ export declare const NEW_CHAT_SCRATCHPAD_KEY = "(new-chat)";
8
9
  export interface TextBlock {
9
10
  type: 'text';
10
11
  text: string;
@@ -1,12 +1,16 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Chat = void 0;
3
+ exports.Chat = exports.NEW_CHAT_SCRATCHPAD_KEY = void 0;
4
4
  const shaxpir_common_1 = require("@shaxpir/shaxpir-common");
5
5
  const repo_1 = require("../repo");
6
6
  const ArrayView_1 = require("./ArrayView");
7
7
  const ContentKind_1 = require("./ContentKind");
8
8
  const Operation_1 = require("./Operation");
9
9
  const SharedContent_1 = require("./SharedContent");
10
+ // Scratchpad key for composing the first message of a new chat.
11
+ // Uses characters outside the base62 ContentId alphabet so it can never
12
+ // collide with an actual chat ID.
13
+ exports.NEW_CHAT_SCRATCHPAD_KEY = '(new-chat)';
10
14
  // ---- Chat model ----
11
15
  class Chat extends SharedContent_1.SharedContent {
12
16
  constructor(doc, shouldAcquire, shareSync) {
@@ -62,6 +62,7 @@ export declare class Workspace extends Content {
62
62
  getChatScratchpad(chatId: string): ChatScratchpad;
63
63
  updateChatScratchpadText(chatId: string, text: string): void;
64
64
  updateChatScratchpadField(chatId: string, key: string, value: any): void;
65
+ private ensureScratchpadExists;
65
66
  clearChatScratchpad(chatId: string): void;
66
67
  get devices(): ArrayView<ContentId>;
67
68
  get uploadedAvatars(): ArrayView<ContentId>;
@@ -124,16 +124,25 @@ class Workspace extends Content_1.Content {
124
124
  }
125
125
  updateChatScratchpadText(chatId, text) {
126
126
  this.checkDisposed("Workspace.updateChatScratchpadText");
127
+ this.ensureScratchpadExists(chatId);
127
128
  const batch = new Operation_1.BatchOperation(this);
128
129
  batch.editPathText(['payload', 'chat_scratchpads', chatId, 'text'], text);
129
130
  batch.commit();
130
131
  }
131
132
  updateChatScratchpadField(chatId, key, value) {
132
133
  this.checkDisposed("Workspace.updateChatScratchpadField");
134
+ this.ensureScratchpadExists(chatId);
133
135
  const batch = new Operation_1.BatchOperation(this);
134
136
  batch.setPathValue(['payload', 'chat_scratchpads', chatId, key], value);
135
137
  batch.commit();
136
138
  }
139
+ ensureScratchpadExists(chatId) {
140
+ if (!this.payload.chat_scratchpads.hasOwnProperty(chatId)) {
141
+ const batch = new Operation_1.BatchOperation(this);
142
+ batch.setPathValue(['payload', 'chat_scratchpads', chatId], {});
143
+ batch.commit();
144
+ }
145
+ }
137
146
  clearChatScratchpad(chatId) {
138
147
  this.checkDisposed("Workspace.clearChatScratchpad");
139
148
  const path = ['payload', 'chat_scratchpads', chatId];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shaxpir/duiduidui-models",
3
- "version": "1.24.0",
3
+ "version": "1.24.2",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/shaxpir/duiduidui-models"