@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.
@@ -12375,7 +12375,7 @@ var GroupChatModule = class {
12375
12375
  );
12376
12376
  this.trackSubscription(
12377
12377
  createNip29Filter({
12378
- kinds: [NIP29_KINDS.GROUP_METADATA, NIP29_KINDS.GROUP_MEMBERS, NIP29_KINDS.GROUP_ADMINS],
12378
+ kinds: [NIP29_KINDS.GROUP_METADATA, NIP29_KINDS.GROUP_ADMINS],
12379
12379
  "#d": groupIds
12380
12380
  }),
12381
12381
  { onEvent: (event) => this.handleMetadataEvent(event) }
@@ -12470,8 +12470,6 @@ var GroupChatModule = class {
12470
12470
  group.updatedAt = event.created_at * 1e3;
12471
12471
  this.groups.set(groupId, group);
12472
12472
  this.schedulePersist();
12473
- } else if (event.kind === NIP29_KINDS.GROUP_MEMBERS) {
12474
- this.updateMembersFromEvent(groupId, event);
12475
12473
  } else if (event.kind === NIP29_KINDS.GROUP_ADMINS) {
12476
12474
  this.updateAdminsFromEvent(groupId, event);
12477
12475
  }
@@ -12534,25 +12532,6 @@ var GroupChatModule = class {
12534
12532
  this.schedulePersist();
12535
12533
  }
12536
12534
  }
12537
- updateMembersFromEvent(groupId, event) {
12538
- const pTags = event.tags.filter((t) => t[0] === "p");
12539
- const existingMembers = this.members.get(groupId) || [];
12540
- for (const tag of pTags) {
12541
- const pubkey = tag[1];
12542
- const roleFromTag = tag[3];
12543
- const existing = existingMembers.find((m) => m.pubkey === pubkey);
12544
- const role = roleFromTag || existing?.role || GroupRole.MEMBER;
12545
- const member = {
12546
- pubkey,
12547
- groupId,
12548
- role,
12549
- nametag: existing?.nametag,
12550
- joinedAt: existing?.joinedAt || event.created_at * 1e3
12551
- };
12552
- this.saveMemberToMemory(member);
12553
- }
12554
- this.schedulePersist();
12555
- }
12556
12535
  updateAdminsFromEvent(groupId, event) {
12557
12536
  const pTags = event.tags.filter((t) => t[0] === "p");
12558
12537
  const existingMembers = this.members.get(groupId) || [];
@@ -12630,47 +12609,24 @@ var GroupChatModule = class {
12630
12609
  await this.ensureConnected();
12631
12610
  if (!this.client) return [];
12632
12611
  const groupsMap = /* @__PURE__ */ new Map();
12633
- const memberCountsMap = /* @__PURE__ */ new Map();
12634
- await Promise.all([
12635
- this.oneshotSubscription(
12636
- new import_nostr_js_sdk4.Filter({ kinds: [NIP29_KINDS.GROUP_METADATA] }),
12637
- {
12638
- onEvent: (event) => {
12639
- const group = this.parseGroupMetadata(event);
12640
- if (group && group.visibility === GroupVisibility.PUBLIC) {
12641
- const existing = groupsMap.get(group.id);
12642
- if (!existing || group.createdAt > existing.createdAt) {
12643
- groupsMap.set(group.id, group);
12644
- }
12645
- }
12646
- },
12647
- onComplete: () => {
12648
- },
12649
- timeoutMs: 1e4,
12650
- timeoutLabel: "fetchAvailableGroups(metadata)"
12651
- }
12652
- ),
12653
- this.oneshotSubscription(
12654
- new import_nostr_js_sdk4.Filter({ kinds: [NIP29_KINDS.GROUP_MEMBERS] }),
12655
- {
12656
- onEvent: (event) => {
12657
- const groupId = this.getGroupIdFromMetadataEvent(event);
12658
- if (groupId) {
12659
- const pTags = event.tags.filter((t) => t[0] === "p");
12660
- memberCountsMap.set(groupId, pTags.length);
12612
+ await this.oneshotSubscription(
12613
+ new import_nostr_js_sdk4.Filter({ kinds: [NIP29_KINDS.GROUP_METADATA] }),
12614
+ {
12615
+ onEvent: (event) => {
12616
+ const group = this.parseGroupMetadata(event);
12617
+ if (group && group.visibility === GroupVisibility.PUBLIC) {
12618
+ const existing = groupsMap.get(group.id);
12619
+ if (!existing || group.createdAt > existing.createdAt) {
12620
+ groupsMap.set(group.id, group);
12661
12621
  }
12662
- },
12663
- onComplete: () => {
12664
- },
12665
- timeoutMs: 1e4,
12666
- timeoutLabel: "fetchAvailableGroups(members)"
12667
- }
12668
- )
12669
- ]);
12670
- for (const [groupId, count] of memberCountsMap) {
12671
- const group = groupsMap.get(groupId);
12672
- if (group) group.memberCount = count;
12673
- }
12622
+ }
12623
+ },
12624
+ onComplete: () => {
12625
+ },
12626
+ timeoutMs: 1e4,
12627
+ timeoutLabel: "fetchAvailableGroups(metadata)"
12628
+ }
12629
+ );
12674
12630
  return Array.from(groupsMap.values());
12675
12631
  }
12676
12632
  async joinGroup(groupId, inviteCode) {
@@ -13475,6 +13431,7 @@ var GroupChatModule = class {
13475
13431
  let name = "Unnamed Group";
13476
13432
  let description;
13477
13433
  let picture;
13434
+ let memberCount;
13478
13435
  let isPrivate = false;
13479
13436
  let writeRestricted = false;
13480
13437
  if (event.content && event.content.trim()) {
@@ -13495,6 +13452,7 @@ var GroupChatModule = class {
13495
13452
  if (tag[0] === "private") isPrivate = true;
13496
13453
  if (tag[0] === "public" && tag[1] === "false") isPrivate = true;
13497
13454
  if (tag[0] === "write-restricted") writeRestricted = true;
13455
+ if (tag[0] === "member_count" && tag[1]) memberCount = parseInt(tag[1], 10) || void 0;
13498
13456
  }
13499
13457
  return {
13500
13458
  id: groupId,
@@ -13502,6 +13460,7 @@ var GroupChatModule = class {
13502
13460
  name,
13503
13461
  description,
13504
13462
  picture,
13463
+ memberCount,
13505
13464
  visibility: isPrivate ? GroupVisibility.PRIVATE : GroupVisibility.PUBLIC,
13506
13465
  writeRestricted: writeRestricted || void 0,
13507
13466
  createdAt: event.created_at * 1e3