@unicitylabs/sphere-sdk 0.6.0 → 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.
@@ -29,6 +29,8 @@ interface GroupData {
29
29
  unreadCount?: number;
30
30
  lastMessageTime?: number;
31
31
  lastMessageText?: string;
32
+ /** Only admins and moderators can post; other members are read-only (NIP-29 "write-restricted" tag) */
33
+ writeRestricted?: boolean;
32
34
  /** When the current user joined this group locally (used to filter old events) */
33
35
  localJoinedAt?: number;
34
36
  }
@@ -66,6 +68,8 @@ interface CreateGroupOptions {
66
68
  description?: string;
67
69
  picture?: string;
68
70
  visibility?: GroupVisibility;
71
+ /** Only admins and moderators can post; other members are read-only */
72
+ writeRestricted?: boolean;
69
73
  }
70
74
 
71
75
  /**
@@ -2962,6 +2966,12 @@ declare class GroupChatModule {
2962
2966
  */
2963
2967
  canModerateGroup(groupId: string): Promise<boolean>;
2964
2968
  isCurrentUserRelayAdmin(): Promise<boolean>;
2969
+ /**
2970
+ * Check if current user can write messages to a group.
2971
+ * For write-restricted groups, only admins/moderators can post.
2972
+ * For normal groups, any member can post.
2973
+ */
2974
+ canWriteToGroup(groupId: string): boolean;
2965
2975
  getCurrentUserRole(groupId: string): GroupRole | null;
2966
2976
  onMessage(handler: (message: GroupMessageData) => void): () => void;
2967
2977
  getRelayUrls(): string[];
@@ -29,6 +29,8 @@ interface GroupData {
29
29
  unreadCount?: number;
30
30
  lastMessageTime?: number;
31
31
  lastMessageText?: string;
32
+ /** Only admins and moderators can post; other members are read-only (NIP-29 "write-restricted" tag) */
33
+ writeRestricted?: boolean;
32
34
  /** When the current user joined this group locally (used to filter old events) */
33
35
  localJoinedAt?: number;
34
36
  }
@@ -66,6 +68,8 @@ interface CreateGroupOptions {
66
68
  description?: string;
67
69
  picture?: string;
68
70
  visibility?: GroupVisibility;
71
+ /** Only admins and moderators can post; other members are read-only */
72
+ writeRestricted?: boolean;
69
73
  }
70
74
 
71
75
  /**
@@ -2962,6 +2966,12 @@ declare class GroupChatModule {
2962
2966
  */
2963
2967
  canModerateGroup(groupId: string): Promise<boolean>;
2964
2968
  isCurrentUserRelayAdmin(): Promise<boolean>;
2969
+ /**
2970
+ * Check if current user can write messages to a group.
2971
+ * For write-restricted groups, only admins/moderators can post.
2972
+ * For normal groups, any member can post.
2973
+ */
2974
+ canWriteToGroup(groupId: string): boolean;
2965
2975
  getCurrentUserRole(groupId: string): GroupRole | null;
2966
2976
  onMessage(handler: (message: GroupMessageData) => void): () => void;
2967
2977
  getRelayUrls(): string[];
@@ -9063,17 +9063,23 @@ var GroupChatModule = class {
9063
9063
  const group = this.groups.get(groupId);
9064
9064
  if (!group) return;
9065
9065
  if (event.kind === NIP29_KINDS.GROUP_METADATA) {
9066
- if (!event.content || event.content.trim() === "") return;
9067
- try {
9068
- const metadata = JSON.parse(event.content);
9069
- group.name = metadata.name || group.name;
9070
- group.description = metadata.about || group.description;
9071
- group.picture = metadata.picture || group.picture;
9072
- group.updatedAt = event.created_at * 1e3;
9073
- this.groups.set(groupId, group);
9074
- this.persistGroups();
9075
- } catch {
9066
+ if (event.content && event.content.trim()) {
9067
+ try {
9068
+ const metadata = JSON.parse(event.content);
9069
+ group.name = metadata.name || group.name;
9070
+ group.description = metadata.about || group.description;
9071
+ group.picture = metadata.picture || group.picture;
9072
+ if (metadata["write-restricted"] === true) group.writeRestricted = true;
9073
+ else group.writeRestricted = void 0;
9074
+ } catch {
9075
+ }
9076
9076
  }
9077
+ for (const tag of event.tags) {
9078
+ if (tag[0] === "write-restricted") group.writeRestricted = true;
9079
+ }
9080
+ group.updatedAt = event.created_at * 1e3;
9081
+ this.groups.set(groupId, group);
9082
+ this.persistGroups();
9077
9083
  } else if (event.kind === NIP29_KINDS.GROUP_MEMBERS) {
9078
9084
  this.updateMembersFromEvent(groupId, event);
9079
9085
  } else if (event.kind === NIP29_KINDS.GROUP_ADMINS) {
@@ -9377,7 +9383,8 @@ var GroupChatModule = class {
9377
9383
  picture: options.picture,
9378
9384
  closed: true,
9379
9385
  private: isPrivate,
9380
- hidden: isPrivate
9386
+ hidden: isPrivate,
9387
+ ...options.writeRestricted ? { "write-restricted": true } : {}
9381
9388
  })
9382
9389
  });
9383
9390
  if (!eventId) return null;
@@ -9678,6 +9685,17 @@ var GroupChatModule = class {
9678
9685
  const admins = await this.fetchRelayAdmins();
9679
9686
  return admins.has(myPubkey);
9680
9687
  }
9688
+ /**
9689
+ * Check if current user can write messages to a group.
9690
+ * For write-restricted groups, only admins/moderators can post.
9691
+ * For normal groups, any member can post.
9692
+ */
9693
+ canWriteToGroup(groupId) {
9694
+ const group = this.groups.get(groupId);
9695
+ if (!group) return false;
9696
+ if (!group.writeRestricted) return true;
9697
+ return this.isCurrentUserModerator(groupId);
9698
+ }
9681
9699
  getCurrentUserRole(groupId) {
9682
9700
  const myPubkey = this.getMyPublicKey();
9683
9701
  if (!myPubkey) return null;
@@ -10052,6 +10070,7 @@ var GroupChatModule = class {
10052
10070
  let description;
10053
10071
  let picture;
10054
10072
  let isPrivate = false;
10073
+ let writeRestricted = false;
10055
10074
  if (event.content && event.content.trim()) {
10056
10075
  try {
10057
10076
  const metadata = JSON.parse(event.content);
@@ -10059,6 +10078,7 @@ var GroupChatModule = class {
10059
10078
  description = metadata.about || metadata.description;
10060
10079
  picture = metadata.picture;
10061
10080
  isPrivate = metadata.private === true;
10081
+ if (metadata["write-restricted"] === true) writeRestricted = true;
10062
10082
  } catch {
10063
10083
  }
10064
10084
  }
@@ -10068,6 +10088,7 @@ var GroupChatModule = class {
10068
10088
  if (tag[0] === "picture" && tag[1]) picture = tag[1];
10069
10089
  if (tag[0] === "private") isPrivate = true;
10070
10090
  if (tag[0] === "public" && tag[1] === "false") isPrivate = true;
10091
+ if (tag[0] === "write-restricted") writeRestricted = true;
10071
10092
  }
10072
10093
  return {
10073
10094
  id: groupId,
@@ -10076,6 +10097,7 @@ var GroupChatModule = class {
10076
10097
  description,
10077
10098
  picture,
10078
10099
  visibility: isPrivate ? GroupVisibility.PRIVATE : GroupVisibility.PUBLIC,
10100
+ writeRestricted: writeRestricted || void 0,
10079
10101
  createdAt: event.created_at * 1e3
10080
10102
  };
10081
10103
  } catch {