@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.
@@ -3285,7 +3285,6 @@ declare class GroupChatModule {
3285
3285
  private handleGroupEvent;
3286
3286
  private handleMetadataEvent;
3287
3287
  private handleModerationEvent;
3288
- private updateMembersFromEvent;
3289
3288
  private updateAdminsFromEvent;
3290
3289
  private restoreJoinedGroups;
3291
3290
  fetchAvailableGroups(): Promise<GroupData[]>;
@@ -3285,7 +3285,6 @@ declare class GroupChatModule {
3285
3285
  private handleGroupEvent;
3286
3286
  private handleMetadataEvent;
3287
3287
  private handleModerationEvent;
3288
- private updateMembersFromEvent;
3289
3288
  private updateAdminsFromEvent;
3290
3289
  private restoreJoinedGroups;
3291
3290
  fetchAvailableGroups(): Promise<GroupData[]>;
@@ -12299,7 +12299,7 @@ var GroupChatModule = class {
12299
12299
  );
12300
12300
  this.trackSubscription(
12301
12301
  createNip29Filter({
12302
- kinds: [NIP29_KINDS.GROUP_METADATA, NIP29_KINDS.GROUP_MEMBERS, NIP29_KINDS.GROUP_ADMINS],
12302
+ kinds: [NIP29_KINDS.GROUP_METADATA, NIP29_KINDS.GROUP_ADMINS],
12303
12303
  "#d": groupIds
12304
12304
  }),
12305
12305
  { onEvent: (event) => this.handleMetadataEvent(event) }
@@ -12394,8 +12394,6 @@ var GroupChatModule = class {
12394
12394
  group.updatedAt = event.created_at * 1e3;
12395
12395
  this.groups.set(groupId, group);
12396
12396
  this.schedulePersist();
12397
- } else if (event.kind === NIP29_KINDS.GROUP_MEMBERS) {
12398
- this.updateMembersFromEvent(groupId, event);
12399
12397
  } else if (event.kind === NIP29_KINDS.GROUP_ADMINS) {
12400
12398
  this.updateAdminsFromEvent(groupId, event);
12401
12399
  }
@@ -12458,25 +12456,6 @@ var GroupChatModule = class {
12458
12456
  this.schedulePersist();
12459
12457
  }
12460
12458
  }
12461
- updateMembersFromEvent(groupId, event) {
12462
- const pTags = event.tags.filter((t) => t[0] === "p");
12463
- const existingMembers = this.members.get(groupId) || [];
12464
- for (const tag of pTags) {
12465
- const pubkey = tag[1];
12466
- const roleFromTag = tag[3];
12467
- const existing = existingMembers.find((m) => m.pubkey === pubkey);
12468
- const role = roleFromTag || existing?.role || GroupRole.MEMBER;
12469
- const member = {
12470
- pubkey,
12471
- groupId,
12472
- role,
12473
- nametag: existing?.nametag,
12474
- joinedAt: existing?.joinedAt || event.created_at * 1e3
12475
- };
12476
- this.saveMemberToMemory(member);
12477
- }
12478
- this.schedulePersist();
12479
- }
12480
12459
  updateAdminsFromEvent(groupId, event) {
12481
12460
  const pTags = event.tags.filter((t) => t[0] === "p");
12482
12461
  const existingMembers = this.members.get(groupId) || [];
@@ -12554,47 +12533,24 @@ var GroupChatModule = class {
12554
12533
  await this.ensureConnected();
12555
12534
  if (!this.client) return [];
12556
12535
  const groupsMap = /* @__PURE__ */ new Map();
12557
- const memberCountsMap = /* @__PURE__ */ new Map();
12558
- await Promise.all([
12559
- this.oneshotSubscription(
12560
- new Filter3({ kinds: [NIP29_KINDS.GROUP_METADATA] }),
12561
- {
12562
- onEvent: (event) => {
12563
- const group = this.parseGroupMetadata(event);
12564
- if (group && group.visibility === GroupVisibility.PUBLIC) {
12565
- const existing = groupsMap.get(group.id);
12566
- if (!existing || group.createdAt > existing.createdAt) {
12567
- groupsMap.set(group.id, group);
12568
- }
12569
- }
12570
- },
12571
- onComplete: () => {
12572
- },
12573
- timeoutMs: 1e4,
12574
- timeoutLabel: "fetchAvailableGroups(metadata)"
12575
- }
12576
- ),
12577
- this.oneshotSubscription(
12578
- new Filter3({ kinds: [NIP29_KINDS.GROUP_MEMBERS] }),
12579
- {
12580
- onEvent: (event) => {
12581
- const groupId = this.getGroupIdFromMetadataEvent(event);
12582
- if (groupId) {
12583
- const pTags = event.tags.filter((t) => t[0] === "p");
12584
- memberCountsMap.set(groupId, pTags.length);
12536
+ await this.oneshotSubscription(
12537
+ new Filter3({ kinds: [NIP29_KINDS.GROUP_METADATA] }),
12538
+ {
12539
+ onEvent: (event) => {
12540
+ const group = this.parseGroupMetadata(event);
12541
+ if (group && group.visibility === GroupVisibility.PUBLIC) {
12542
+ const existing = groupsMap.get(group.id);
12543
+ if (!existing || group.createdAt > existing.createdAt) {
12544
+ groupsMap.set(group.id, group);
12585
12545
  }
12586
- },
12587
- onComplete: () => {
12588
- },
12589
- timeoutMs: 1e4,
12590
- timeoutLabel: "fetchAvailableGroups(members)"
12591
- }
12592
- )
12593
- ]);
12594
- for (const [groupId, count] of memberCountsMap) {
12595
- const group = groupsMap.get(groupId);
12596
- if (group) group.memberCount = count;
12597
- }
12546
+ }
12547
+ },
12548
+ onComplete: () => {
12549
+ },
12550
+ timeoutMs: 1e4,
12551
+ timeoutLabel: "fetchAvailableGroups(metadata)"
12552
+ }
12553
+ );
12598
12554
  return Array.from(groupsMap.values());
12599
12555
  }
12600
12556
  async joinGroup(groupId, inviteCode) {
@@ -13399,6 +13355,7 @@ var GroupChatModule = class {
13399
13355
  let name = "Unnamed Group";
13400
13356
  let description;
13401
13357
  let picture;
13358
+ let memberCount;
13402
13359
  let isPrivate = false;
13403
13360
  let writeRestricted = false;
13404
13361
  if (event.content && event.content.trim()) {
@@ -13419,6 +13376,7 @@ var GroupChatModule = class {
13419
13376
  if (tag[0] === "private") isPrivate = true;
13420
13377
  if (tag[0] === "public" && tag[1] === "false") isPrivate = true;
13421
13378
  if (tag[0] === "write-restricted") writeRestricted = true;
13379
+ if (tag[0] === "member_count" && tag[1]) memberCount = parseInt(tag[1], 10) || void 0;
13422
13380
  }
13423
13381
  return {
13424
13382
  id: groupId,
@@ -13426,6 +13384,7 @@ var GroupChatModule = class {
13426
13384
  name,
13427
13385
  description,
13428
13386
  picture,
13387
+ memberCount,
13429
13388
  visibility: isPrivate ? GroupVisibility.PRIVATE : GroupVisibility.PUBLIC,
13430
13389
  writeRestricted: writeRestricted || void 0,
13431
13390
  createdAt: event.created_at * 1e3