@shaxpir/duiduidui-models 1.6.8 → 1.6.13

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.
@@ -2,33 +2,31 @@ import { Doc } from '@shaxpir/sharedb/lib/client';
2
2
  import { CompactDateTime, MultiTime } from '@shaxpir/shaxpir-common';
3
3
  import { ShareSync } from '../repo';
4
4
  import { Content, ContentBody, ContentId, ContentMeta } from "./Content";
5
+ import { ImageCropping } from './Image';
5
6
  export declare enum FriendRequestStatus {
6
7
  PENDING = "pending",
7
8
  ACCEPTED = "accepted",
8
9
  REJECTED = "rejected"
9
10
  }
11
+ export interface SocialUser {
12
+ user_id: ContentId;
13
+ username: string;
14
+ full_name: string;
15
+ avatar_image_ref: ContentId | null;
16
+ avatar_cropping: ImageCropping | null;
17
+ }
10
18
  export interface FriendRequest {
11
19
  request_id: string;
12
- from_user_id: ContentId;
13
- to_user_id: ContentId;
14
- from_username: string;
15
- from_full_name: string;
16
- to_username: string;
17
- to_full_name: string;
20
+ from: SocialUser;
21
+ to: SocialUser;
18
22
  status: FriendRequestStatus;
19
23
  created_at: CompactDateTime;
20
24
  updated_at: CompactDateTime;
21
25
  }
22
- export interface Friend {
23
- user_id: ContentId;
24
- username: string;
25
- full_name: string;
26
+ export interface Friend extends SocialUser {
26
27
  since: CompactDateTime;
27
28
  }
28
- export interface BlockedUser {
29
- user_id: ContentId;
30
- username: string;
31
- full_name: string;
29
+ export interface BlockedUser extends SocialUser {
32
30
  blocked_at: CompactDateTime;
33
31
  }
34
32
  export interface SocialPayload {
@@ -61,4 +59,9 @@ export declare class Social extends Content {
61
59
  addBlockedUser(blockedUser: BlockedUser): void;
62
60
  removeBlockedUser(userId: ContentId): void;
63
61
  isBlocked(userId: ContentId): boolean;
62
+ /**
63
+ * Updates cached profile fields for all SocialUser references matching the given userId.
64
+ * This should be called when a user updates their Profile to keep cached data in sync.
65
+ */
66
+ updateProfileFields(userId: ContentId, username: string, fullName: string, avatarImageRef: ContentId | null, avatarCropping: ImageCropping | null): void;
64
67
  }
@@ -144,5 +144,56 @@ class Social extends Content_1.Content {
144
144
  this.checkDisposed("Social.isBlocked");
145
145
  return this.payload.blocked_users.some(b => b.user_id === userId);
146
146
  }
147
+ // ========== Sync Profile Changes ==========
148
+ /**
149
+ * Updates cached profile fields for all SocialUser references matching the given userId.
150
+ * This should be called when a user updates their Profile to keep cached data in sync.
151
+ */
152
+ updateProfileFields(userId, username, fullName, avatarImageRef, avatarCropping) {
153
+ this.checkDisposed("Social.updateProfileFields");
154
+ const batch = new Operation_1.BatchOperation(this);
155
+ let updated = false;
156
+ // Helper to update a SocialUser at the given path
157
+ const updateSocialUser = (basePath) => {
158
+ batch.setPathValue([...basePath, 'username'], username);
159
+ batch.setPathValue([...basePath, 'full_name'], fullName);
160
+ batch.setPathValue([...basePath, 'avatar_image_ref'], avatarImageRef);
161
+ batch.setPathValue([...basePath, 'avatar_cropping'], avatarCropping);
162
+ updated = true;
163
+ };
164
+ // Update friends
165
+ this.payload.friends.forEach((friend, index) => {
166
+ if (friend.user_id === userId) {
167
+ updateSocialUser(['payload', 'friends', index]);
168
+ }
169
+ });
170
+ // Update blocked users
171
+ this.payload.blocked_users.forEach((blocked, index) => {
172
+ if (blocked.user_id === userId) {
173
+ updateSocialUser(['payload', 'blocked_users', index]);
174
+ }
175
+ });
176
+ // Update outgoing requests (both from and to)
177
+ this.payload.outgoing_requests.forEach((request, index) => {
178
+ if (request.from.user_id === userId) {
179
+ updateSocialUser(['payload', 'outgoing_requests', index, 'from']);
180
+ }
181
+ if (request.to.user_id === userId) {
182
+ updateSocialUser(['payload', 'outgoing_requests', index, 'to']);
183
+ }
184
+ });
185
+ // Update incoming requests (both from and to)
186
+ this.payload.incoming_requests.forEach((request, index) => {
187
+ if (request.from.user_id === userId) {
188
+ updateSocialUser(['payload', 'incoming_requests', index, 'from']);
189
+ }
190
+ if (request.to.user_id === userId) {
191
+ updateSocialUser(['payload', 'incoming_requests', index, 'to']);
192
+ }
193
+ });
194
+ if (updated) {
195
+ batch.commit();
196
+ }
197
+ }
147
198
  }
148
199
  exports.Social = Social;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shaxpir/duiduidui-models",
3
- "version": "1.6.8",
3
+ "version": "1.6.13",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/shaxpir/duiduidui-models"