@unicitylabs/sphere-sdk 0.6.10-dev.5 → 0.6.10-dev.7

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
@@ -3695,7 +3695,6 @@ declare class GroupChatModule {
3695
3695
  private handleGroupEvent;
3696
3696
  private handleMetadataEvent;
3697
3697
  private handleModerationEvent;
3698
- private updateMembersFromEvent;
3699
3698
  private updateAdminsFromEvent;
3700
3699
  private restoreJoinedGroups;
3701
3700
  fetchAvailableGroups(): Promise<GroupData[]>;
package/dist/index.d.ts CHANGED
@@ -3695,7 +3695,6 @@ declare class GroupChatModule {
3695
3695
  private handleGroupEvent;
3696
3696
  private handleMetadataEvent;
3697
3697
  private handleModerationEvent;
3698
- private updateMembersFromEvent;
3699
3698
  private updateAdminsFromEvent;
3700
3699
  private restoreJoinedGroups;
3701
3700
  fetchAvailableGroups(): Promise<GroupData[]>;
package/dist/index.js CHANGED
@@ -12568,7 +12568,7 @@ var GroupChatModule = class {
12568
12568
  );
12569
12569
  this.trackSubscription(
12570
12570
  createNip29Filter({
12571
- kinds: [NIP29_KINDS.GROUP_METADATA, NIP29_KINDS.GROUP_MEMBERS, NIP29_KINDS.GROUP_ADMINS],
12571
+ kinds: [NIP29_KINDS.GROUP_METADATA, NIP29_KINDS.GROUP_ADMINS],
12572
12572
  "#d": groupIds
12573
12573
  }),
12574
12574
  { onEvent: (event) => this.handleMetadataEvent(event) }
@@ -12663,8 +12663,6 @@ var GroupChatModule = class {
12663
12663
  group.updatedAt = event.created_at * 1e3;
12664
12664
  this.groups.set(groupId, group);
12665
12665
  this.schedulePersist();
12666
- } else if (event.kind === NIP29_KINDS.GROUP_MEMBERS) {
12667
- this.updateMembersFromEvent(groupId, event);
12668
12666
  } else if (event.kind === NIP29_KINDS.GROUP_ADMINS) {
12669
12667
  this.updateAdminsFromEvent(groupId, event);
12670
12668
  }
@@ -12727,25 +12725,6 @@ var GroupChatModule = class {
12727
12725
  this.schedulePersist();
12728
12726
  }
12729
12727
  }
12730
- updateMembersFromEvent(groupId, event) {
12731
- const pTags = event.tags.filter((t) => t[0] === "p");
12732
- const existingMembers = this.members.get(groupId) || [];
12733
- for (const tag of pTags) {
12734
- const pubkey = tag[1];
12735
- const roleFromTag = tag[3];
12736
- const existing = existingMembers.find((m) => m.pubkey === pubkey);
12737
- const role = roleFromTag || existing?.role || GroupRole.MEMBER;
12738
- const member = {
12739
- pubkey,
12740
- groupId,
12741
- role,
12742
- nametag: existing?.nametag,
12743
- joinedAt: existing?.joinedAt || event.created_at * 1e3
12744
- };
12745
- this.saveMemberToMemory(member);
12746
- }
12747
- this.schedulePersist();
12748
- }
12749
12728
  updateAdminsFromEvent(groupId, event) {
12750
12729
  const pTags = event.tags.filter((t) => t[0] === "p");
12751
12730
  const existingMembers = this.members.get(groupId) || [];
@@ -12823,47 +12802,24 @@ var GroupChatModule = class {
12823
12802
  await this.ensureConnected();
12824
12803
  if (!this.client) return [];
12825
12804
  const groupsMap = /* @__PURE__ */ new Map();
12826
- const memberCountsMap = /* @__PURE__ */ new Map();
12827
- await Promise.all([
12828
- this.oneshotSubscription(
12829
- new Filter3({ kinds: [NIP29_KINDS.GROUP_METADATA] }),
12830
- {
12831
- onEvent: (event) => {
12832
- const group = this.parseGroupMetadata(event);
12833
- if (group && group.visibility === GroupVisibility.PUBLIC) {
12834
- const existing = groupsMap.get(group.id);
12835
- if (!existing || group.createdAt > existing.createdAt) {
12836
- groupsMap.set(group.id, group);
12837
- }
12838
- }
12839
- },
12840
- onComplete: () => {
12841
- },
12842
- timeoutMs: 1e4,
12843
- timeoutLabel: "fetchAvailableGroups(metadata)"
12844
- }
12845
- ),
12846
- this.oneshotSubscription(
12847
- new Filter3({ kinds: [NIP29_KINDS.GROUP_MEMBERS] }),
12848
- {
12849
- onEvent: (event) => {
12850
- const groupId = this.getGroupIdFromMetadataEvent(event);
12851
- if (groupId) {
12852
- const pTags = event.tags.filter((t) => t[0] === "p");
12853
- memberCountsMap.set(groupId, pTags.length);
12805
+ await this.oneshotSubscription(
12806
+ new Filter3({ kinds: [NIP29_KINDS.GROUP_METADATA] }),
12807
+ {
12808
+ onEvent: (event) => {
12809
+ const group = this.parseGroupMetadata(event);
12810
+ if (group && group.visibility === GroupVisibility.PUBLIC) {
12811
+ const existing = groupsMap.get(group.id);
12812
+ if (!existing || group.createdAt > existing.createdAt) {
12813
+ groupsMap.set(group.id, group);
12854
12814
  }
12855
- },
12856
- onComplete: () => {
12857
- },
12858
- timeoutMs: 1e4,
12859
- timeoutLabel: "fetchAvailableGroups(members)"
12860
- }
12861
- )
12862
- ]);
12863
- for (const [groupId, count] of memberCountsMap) {
12864
- const group = groupsMap.get(groupId);
12865
- if (group) group.memberCount = count;
12866
- }
12815
+ }
12816
+ },
12817
+ onComplete: () => {
12818
+ },
12819
+ timeoutMs: 1e4,
12820
+ timeoutLabel: "fetchAvailableGroups(metadata)"
12821
+ }
12822
+ );
12867
12823
  return Array.from(groupsMap.values());
12868
12824
  }
12869
12825
  async joinGroup(groupId, inviteCode) {
@@ -13668,6 +13624,7 @@ var GroupChatModule = class {
13668
13624
  let name = "Unnamed Group";
13669
13625
  let description;
13670
13626
  let picture;
13627
+ let memberCount;
13671
13628
  let isPrivate = false;
13672
13629
  let writeRestricted = false;
13673
13630
  if (event.content && event.content.trim()) {
@@ -13688,6 +13645,7 @@ var GroupChatModule = class {
13688
13645
  if (tag[0] === "private") isPrivate = true;
13689
13646
  if (tag[0] === "public" && tag[1] === "false") isPrivate = true;
13690
13647
  if (tag[0] === "write-restricted") writeRestricted = true;
13648
+ if (tag[0] === "member_count" && tag[1]) memberCount = parseInt(tag[1], 10) || void 0;
13691
13649
  }
13692
13650
  return {
13693
13651
  id: groupId,
@@ -13695,6 +13653,7 @@ var GroupChatModule = class {
13695
13653
  name,
13696
13654
  description,
13697
13655
  picture,
13656
+ memberCount,
13698
13657
  visibility: isPrivate ? GroupVisibility.PRIVATE : GroupVisibility.PUBLIC,
13699
13658
  writeRestricted: writeRestricted || void 0,
13700
13659
  createdAt: event.created_at * 1e3