@unicitylabs/sphere-sdk 0.6.0-dev.1 → 0.6.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.
package/dist/index.d.cts CHANGED
@@ -30,6 +30,8 @@ interface GroupData {
30
30
  unreadCount?: number;
31
31
  lastMessageTime?: number;
32
32
  lastMessageText?: string;
33
+ /** Only admins and moderators can post; other members are read-only (NIP-29 "write-restricted" tag) */
34
+ writeRestricted?: boolean;
33
35
  /** When the current user joined this group locally (used to filter old events) */
34
36
  localJoinedAt?: number;
35
37
  }
@@ -67,6 +69,8 @@ interface CreateGroupOptions {
67
69
  description?: string;
68
70
  picture?: string;
69
71
  visibility?: GroupVisibility;
72
+ /** Only admins and moderators can post; other members are read-only */
73
+ writeRestricted?: boolean;
70
74
  }
71
75
 
72
76
  /**
@@ -3667,6 +3671,12 @@ declare class GroupChatModule {
3667
3671
  */
3668
3672
  canModerateGroup(groupId: string): Promise<boolean>;
3669
3673
  isCurrentUserRelayAdmin(): Promise<boolean>;
3674
+ /**
3675
+ * Check if current user can write messages to a group.
3676
+ * For write-restricted groups, only admins/moderators can post.
3677
+ * For normal groups, any member can post.
3678
+ */
3679
+ canWriteToGroup(groupId: string): boolean;
3670
3680
  getCurrentUserRole(groupId: string): GroupRole | null;
3671
3681
  onMessage(handler: (message: GroupMessageData) => void): () => void;
3672
3682
  getRelayUrls(): string[];
package/dist/index.d.ts CHANGED
@@ -30,6 +30,8 @@ interface GroupData {
30
30
  unreadCount?: number;
31
31
  lastMessageTime?: number;
32
32
  lastMessageText?: string;
33
+ /** Only admins and moderators can post; other members are read-only (NIP-29 "write-restricted" tag) */
34
+ writeRestricted?: boolean;
33
35
  /** When the current user joined this group locally (used to filter old events) */
34
36
  localJoinedAt?: number;
35
37
  }
@@ -67,6 +69,8 @@ interface CreateGroupOptions {
67
69
  description?: string;
68
70
  picture?: string;
69
71
  visibility?: GroupVisibility;
72
+ /** Only admins and moderators can post; other members are read-only */
73
+ writeRestricted?: boolean;
70
74
  }
71
75
 
72
76
  /**
@@ -3667,6 +3671,12 @@ declare class GroupChatModule {
3667
3671
  */
3668
3672
  canModerateGroup(groupId: string): Promise<boolean>;
3669
3673
  isCurrentUserRelayAdmin(): Promise<boolean>;
3674
+ /**
3675
+ * Check if current user can write messages to a group.
3676
+ * For write-restricted groups, only admins/moderators can post.
3677
+ * For normal groups, any member can post.
3678
+ */
3679
+ canWriteToGroup(groupId: string): boolean;
3670
3680
  getCurrentUserRole(groupId: string): GroupRole | null;
3671
3681
  onMessage(handler: (message: GroupMessageData) => void): () => void;
3672
3682
  getRelayUrls(): string[];
package/dist/index.js CHANGED
@@ -9358,17 +9358,23 @@ var GroupChatModule = class {
9358
9358
  const group = this.groups.get(groupId);
9359
9359
  if (!group) return;
9360
9360
  if (event.kind === NIP29_KINDS.GROUP_METADATA) {
9361
- if (!event.content || event.content.trim() === "") return;
9362
- try {
9363
- const metadata = JSON.parse(event.content);
9364
- group.name = metadata.name || group.name;
9365
- group.description = metadata.about || group.description;
9366
- group.picture = metadata.picture || group.picture;
9367
- group.updatedAt = event.created_at * 1e3;
9368
- this.groups.set(groupId, group);
9369
- this.persistGroups();
9370
- } catch {
9361
+ if (event.content && event.content.trim()) {
9362
+ try {
9363
+ const metadata = JSON.parse(event.content);
9364
+ group.name = metadata.name || group.name;
9365
+ group.description = metadata.about || group.description;
9366
+ group.picture = metadata.picture || group.picture;
9367
+ if (metadata["write-restricted"] === true) group.writeRestricted = true;
9368
+ else group.writeRestricted = void 0;
9369
+ } catch {
9370
+ }
9371
9371
  }
9372
+ for (const tag of event.tags) {
9373
+ if (tag[0] === "write-restricted") group.writeRestricted = true;
9374
+ }
9375
+ group.updatedAt = event.created_at * 1e3;
9376
+ this.groups.set(groupId, group);
9377
+ this.persistGroups();
9372
9378
  } else if (event.kind === NIP29_KINDS.GROUP_MEMBERS) {
9373
9379
  this.updateMembersFromEvent(groupId, event);
9374
9380
  } else if (event.kind === NIP29_KINDS.GROUP_ADMINS) {
@@ -9672,7 +9678,8 @@ var GroupChatModule = class {
9672
9678
  picture: options.picture,
9673
9679
  closed: true,
9674
9680
  private: isPrivate,
9675
- hidden: isPrivate
9681
+ hidden: isPrivate,
9682
+ ...options.writeRestricted ? { "write-restricted": true } : {}
9676
9683
  })
9677
9684
  });
9678
9685
  if (!eventId) return null;
@@ -9973,6 +9980,17 @@ var GroupChatModule = class {
9973
9980
  const admins = await this.fetchRelayAdmins();
9974
9981
  return admins.has(myPubkey);
9975
9982
  }
9983
+ /**
9984
+ * Check if current user can write messages to a group.
9985
+ * For write-restricted groups, only admins/moderators can post.
9986
+ * For normal groups, any member can post.
9987
+ */
9988
+ canWriteToGroup(groupId) {
9989
+ const group = this.groups.get(groupId);
9990
+ if (!group) return false;
9991
+ if (!group.writeRestricted) return true;
9992
+ return this.isCurrentUserModerator(groupId);
9993
+ }
9976
9994
  getCurrentUserRole(groupId) {
9977
9995
  const myPubkey = this.getMyPublicKey();
9978
9996
  if (!myPubkey) return null;
@@ -10347,6 +10365,7 @@ var GroupChatModule = class {
10347
10365
  let description;
10348
10366
  let picture;
10349
10367
  let isPrivate = false;
10368
+ let writeRestricted = false;
10350
10369
  if (event.content && event.content.trim()) {
10351
10370
  try {
10352
10371
  const metadata = JSON.parse(event.content);
@@ -10354,6 +10373,7 @@ var GroupChatModule = class {
10354
10373
  description = metadata.about || metadata.description;
10355
10374
  picture = metadata.picture;
10356
10375
  isPrivate = metadata.private === true;
10376
+ if (metadata["write-restricted"] === true) writeRestricted = true;
10357
10377
  } catch {
10358
10378
  }
10359
10379
  }
@@ -10363,6 +10383,7 @@ var GroupChatModule = class {
10363
10383
  if (tag[0] === "picture" && tag[1]) picture = tag[1];
10364
10384
  if (tag[0] === "private") isPrivate = true;
10365
10385
  if (tag[0] === "public" && tag[1] === "false") isPrivate = true;
10386
+ if (tag[0] === "write-restricted") writeRestricted = true;
10366
10387
  }
10367
10388
  return {
10368
10389
  id: groupId,
@@ -10371,6 +10392,7 @@ var GroupChatModule = class {
10371
10392
  description,
10372
10393
  picture,
10373
10394
  visibility: isPrivate ? GroupVisibility.PRIVATE : GroupVisibility.PUBLIC,
10395
+ writeRestricted: writeRestricted || void 0,
10374
10396
  createdAt: event.created_at * 1e3
10375
10397
  };
10376
10398
  } catch {