@shaxpir/duiduidui-models 1.6.8 → 1.6.14

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,37 @@ 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 declare enum SharingLevel {
12
+ FRIEND = "friend",// Default sharing level - basic progress visibility
13
+ TEACHER = "teacher"
14
+ }
15
+ export interface SocialUser {
16
+ user_id: ContentId;
17
+ username: string;
18
+ full_name: string;
19
+ avatar_image_ref: ContentId | null;
20
+ avatar_cropping: ImageCropping | null;
21
+ }
10
22
  export interface FriendRequest {
11
23
  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;
24
+ from: SocialUser;
25
+ to: SocialUser;
18
26
  status: FriendRequestStatus;
19
27
  created_at: CompactDateTime;
20
28
  updated_at: CompactDateTime;
21
29
  }
22
- export interface Friend {
23
- user_id: ContentId;
24
- username: string;
25
- full_name: string;
30
+ export interface Friend extends SocialUser {
26
31
  since: CompactDateTime;
32
+ my_sharing_level: SharingLevel;
33
+ their_sharing_level: SharingLevel;
27
34
  }
28
- export interface BlockedUser {
29
- user_id: ContentId;
30
- username: string;
31
- full_name: string;
35
+ export interface BlockedUser extends SocialUser {
32
36
  blocked_at: CompactDateTime;
33
37
  }
34
38
  export interface SocialPayload {
@@ -57,8 +61,15 @@ export declare class Social extends Content {
57
61
  addFriend(friend: Friend): void;
58
62
  removeFriend(userId: ContentId): void;
59
63
  isFriend(userId: ContentId): boolean;
64
+ updateMySharingLevel(userId: ContentId, sharingLevel: SharingLevel): void;
65
+ updateTheirSharingLevel(userId: ContentId, sharingLevel: SharingLevel): void;
60
66
  getBlockedUsers(): BlockedUser[];
61
67
  addBlockedUser(blockedUser: BlockedUser): void;
62
68
  removeBlockedUser(userId: ContentId): void;
63
69
  isBlocked(userId: ContentId): boolean;
70
+ /**
71
+ * Updates cached profile fields for all SocialUser references matching the given userId.
72
+ * This should be called when a user updates their Profile to keep cached data in sync.
73
+ */
74
+ updateProfileFields(userId: ContentId, username: string, fullName: string, avatarImageRef: ContentId | null, avatarCropping: ImageCropping | null): void;
64
75
  }
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Social = exports.FriendRequestStatus = void 0;
3
+ exports.Social = exports.SharingLevel = exports.FriendRequestStatus = void 0;
4
4
  const shaxpir_common_1 = require("@shaxpir/shaxpir-common");
5
5
  const repo_1 = require("../repo");
6
6
  const Content_1 = require("./Content");
@@ -12,6 +12,11 @@ var FriendRequestStatus;
12
12
  FriendRequestStatus["ACCEPTED"] = "accepted";
13
13
  FriendRequestStatus["REJECTED"] = "rejected";
14
14
  })(FriendRequestStatus || (exports.FriendRequestStatus = FriendRequestStatus = {}));
15
+ var SharingLevel;
16
+ (function (SharingLevel) {
17
+ SharingLevel["FRIEND"] = "friend";
18
+ SharingLevel["TEACHER"] = "teacher"; // Enhanced sharing - detailed progress and learning insights
19
+ })(SharingLevel || (exports.SharingLevel = SharingLevel = {}));
15
20
  class Social extends Content_1.Content {
16
21
  static makeSocialId(userId) {
17
22
  return shaxpir_common_1.CachingHasher.makeMd5Base62Hash(userId + "-" + ContentKind_1.ContentKind.SOCIAL);
@@ -118,6 +123,24 @@ class Social extends Content_1.Content {
118
123
  this.checkDisposed("Social.isFriend");
119
124
  return this.payload.friends.some(f => f.user_id === userId);
120
125
  }
126
+ updateMySharingLevel(userId, sharingLevel) {
127
+ this.checkDisposed("Social.updateMySharingLevel");
128
+ const index = this.payload.friends.findIndex(f => f.user_id === userId);
129
+ if (index !== -1) {
130
+ const batch = new Operation_1.BatchOperation(this);
131
+ batch.setPathValue(['payload', 'friends', index, 'my_sharing_level'], sharingLevel);
132
+ batch.commit();
133
+ }
134
+ }
135
+ updateTheirSharingLevel(userId, sharingLevel) {
136
+ this.checkDisposed("Social.updateTheirSharingLevel");
137
+ const index = this.payload.friends.findIndex(f => f.user_id === userId);
138
+ if (index !== -1) {
139
+ const batch = new Operation_1.BatchOperation(this);
140
+ batch.setPathValue(['payload', 'friends', index, 'their_sharing_level'], sharingLevel);
141
+ batch.commit();
142
+ }
143
+ }
121
144
  // ========== Blocked Users ==========
122
145
  getBlockedUsers() {
123
146
  this.checkDisposed("Social.getBlockedUsers");
@@ -144,5 +167,56 @@ class Social extends Content_1.Content {
144
167
  this.checkDisposed("Social.isBlocked");
145
168
  return this.payload.blocked_users.some(b => b.user_id === userId);
146
169
  }
170
+ // ========== Sync Profile Changes ==========
171
+ /**
172
+ * Updates cached profile fields for all SocialUser references matching the given userId.
173
+ * This should be called when a user updates their Profile to keep cached data in sync.
174
+ */
175
+ updateProfileFields(userId, username, fullName, avatarImageRef, avatarCropping) {
176
+ this.checkDisposed("Social.updateProfileFields");
177
+ const batch = new Operation_1.BatchOperation(this);
178
+ let updated = false;
179
+ // Helper to update a SocialUser at the given path
180
+ const updateSocialUser = (basePath) => {
181
+ batch.setPathValue([...basePath, 'username'], username);
182
+ batch.setPathValue([...basePath, 'full_name'], fullName);
183
+ batch.setPathValue([...basePath, 'avatar_image_ref'], avatarImageRef);
184
+ batch.setPathValue([...basePath, 'avatar_cropping'], avatarCropping);
185
+ updated = true;
186
+ };
187
+ // Update friends
188
+ this.payload.friends.forEach((friend, index) => {
189
+ if (friend.user_id === userId) {
190
+ updateSocialUser(['payload', 'friends', index]);
191
+ }
192
+ });
193
+ // Update blocked users
194
+ this.payload.blocked_users.forEach((blocked, index) => {
195
+ if (blocked.user_id === userId) {
196
+ updateSocialUser(['payload', 'blocked_users', index]);
197
+ }
198
+ });
199
+ // Update outgoing requests (both from and to)
200
+ this.payload.outgoing_requests.forEach((request, index) => {
201
+ if (request.from.user_id === userId) {
202
+ updateSocialUser(['payload', 'outgoing_requests', index, 'from']);
203
+ }
204
+ if (request.to.user_id === userId) {
205
+ updateSocialUser(['payload', 'outgoing_requests', index, 'to']);
206
+ }
207
+ });
208
+ // Update incoming requests (both from and to)
209
+ this.payload.incoming_requests.forEach((request, index) => {
210
+ if (request.from.user_id === userId) {
211
+ updateSocialUser(['payload', 'incoming_requests', index, 'from']);
212
+ }
213
+ if (request.to.user_id === userId) {
214
+ updateSocialUser(['payload', 'incoming_requests', index, 'to']);
215
+ }
216
+ });
217
+ if (updated) {
218
+ batch.commit();
219
+ }
220
+ }
147
221
  }
148
222
  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.14",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/shaxpir/duiduidui-models"