@shaxpir/duiduidui-models 1.20.0 → 1.20.1

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.
@@ -49,6 +49,11 @@ export declare class Workspace extends Content {
49
49
  /**
50
50
  * Update a chat stub in the chats array and move it to the top.
51
51
  * If the stub doesn't exist yet, it is prepended.
52
+ *
53
+ * When the stub already exists but isn't at the top, we remove it
54
+ * entirely and insert a fresh copy at index 0 (cleaner for OT than
55
+ * editing fields and then moving). When it's already at the top,
56
+ * we update its fields in place to avoid unnecessary churn.
52
57
  */
53
58
  upsertChatStub(stub: ChatStub): void;
54
59
  get devices(): ArrayView<ContentId>;
@@ -88,19 +88,25 @@ class Workspace extends Content_1.Content {
88
88
  /**
89
89
  * Update a chat stub in the chats array and move it to the top.
90
90
  * If the stub doesn't exist yet, it is prepended.
91
+ *
92
+ * When the stub already exists but isn't at the top, we remove it
93
+ * entirely and insert a fresh copy at index 0 (cleaner for OT than
94
+ * editing fields and then moving). When it's already at the top,
95
+ * we update its fields in place to avoid unnecessary churn.
91
96
  */
92
97
  upsertChatStub(stub) {
93
98
  this.checkDisposed("Workspace.upsertChatStub");
94
99
  const index = this._chatsView.firstIndexWhere(s => s.id === stub.id);
95
- if (index >= 0) {
96
- // Update the existing stub fields
97
- this._chatsView.setObjectValueAtIndex(index, 'title', stub.title);
98
- this._chatsView.setObjectValueAtIndex(index, 'last_message_preview', stub.last_message_preview);
99
- this._chatsView.setObjectValueAtIndex(index, 'updated_at', stub.updated_at);
100
- // Move to top if not already there
101
- if (index > 0) {
102
- this._chatsView.move(index, 0);
103
- }
100
+ if (index === 0) {
101
+ // Already at the top update fields in place
102
+ this._chatsView.setObjectValueAtIndex(0, 'title', stub.title);
103
+ this._chatsView.setObjectValueAtIndex(0, 'last_message_preview', stub.last_message_preview);
104
+ this._chatsView.setObjectValueAtIndex(0, 'updated_at', stub.updated_at);
105
+ }
106
+ else if (index > 0) {
107
+ // Exists but not at top — remove and reinsert at head
108
+ this._chatsView.removeAt(index);
109
+ this._chatsView.unshift(stub);
104
110
  }
105
111
  else {
106
112
  // New chat — prepend
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shaxpir/duiduidui-models",
3
- "version": "1.20.0",
3
+ "version": "1.20.1",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/shaxpir/duiduidui-models"