@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.cjs CHANGED
@@ -12715,7 +12715,7 @@ var GroupChatModule = class {
12715
12715
  );
12716
12716
  this.trackSubscription(
12717
12717
  createNip29Filter({
12718
- kinds: [NIP29_KINDS.GROUP_METADATA, NIP29_KINDS.GROUP_MEMBERS, NIP29_KINDS.GROUP_ADMINS],
12718
+ kinds: [NIP29_KINDS.GROUP_METADATA, NIP29_KINDS.GROUP_ADMINS],
12719
12719
  "#d": groupIds
12720
12720
  }),
12721
12721
  { onEvent: (event) => this.handleMetadataEvent(event) }
@@ -12810,8 +12810,6 @@ var GroupChatModule = class {
12810
12810
  group.updatedAt = event.created_at * 1e3;
12811
12811
  this.groups.set(groupId, group);
12812
12812
  this.schedulePersist();
12813
- } else if (event.kind === NIP29_KINDS.GROUP_MEMBERS) {
12814
- this.updateMembersFromEvent(groupId, event);
12815
12813
  } else if (event.kind === NIP29_KINDS.GROUP_ADMINS) {
12816
12814
  this.updateAdminsFromEvent(groupId, event);
12817
12815
  }
@@ -12874,25 +12872,6 @@ var GroupChatModule = class {
12874
12872
  this.schedulePersist();
12875
12873
  }
12876
12874
  }
12877
- updateMembersFromEvent(groupId, event) {
12878
- const pTags = event.tags.filter((t) => t[0] === "p");
12879
- const existingMembers = this.members.get(groupId) || [];
12880
- for (const tag of pTags) {
12881
- const pubkey = tag[1];
12882
- const roleFromTag = tag[3];
12883
- const existing = existingMembers.find((m) => m.pubkey === pubkey);
12884
- const role = roleFromTag || existing?.role || GroupRole.MEMBER;
12885
- const member = {
12886
- pubkey,
12887
- groupId,
12888
- role,
12889
- nametag: existing?.nametag,
12890
- joinedAt: existing?.joinedAt || event.created_at * 1e3
12891
- };
12892
- this.saveMemberToMemory(member);
12893
- }
12894
- this.schedulePersist();
12895
- }
12896
12875
  updateAdminsFromEvent(groupId, event) {
12897
12876
  const pTags = event.tags.filter((t) => t[0] === "p");
12898
12877
  const existingMembers = this.members.get(groupId) || [];
@@ -12970,47 +12949,24 @@ var GroupChatModule = class {
12970
12949
  await this.ensureConnected();
12971
12950
  if (!this.client) return [];
12972
12951
  const groupsMap = /* @__PURE__ */ new Map();
12973
- const memberCountsMap = /* @__PURE__ */ new Map();
12974
- await Promise.all([
12975
- this.oneshotSubscription(
12976
- new import_nostr_js_sdk4.Filter({ kinds: [NIP29_KINDS.GROUP_METADATA] }),
12977
- {
12978
- onEvent: (event) => {
12979
- const group = this.parseGroupMetadata(event);
12980
- if (group && group.visibility === GroupVisibility.PUBLIC) {
12981
- const existing = groupsMap.get(group.id);
12982
- if (!existing || group.createdAt > existing.createdAt) {
12983
- groupsMap.set(group.id, group);
12984
- }
12985
- }
12986
- },
12987
- onComplete: () => {
12988
- },
12989
- timeoutMs: 1e4,
12990
- timeoutLabel: "fetchAvailableGroups(metadata)"
12991
- }
12992
- ),
12993
- this.oneshotSubscription(
12994
- new import_nostr_js_sdk4.Filter({ kinds: [NIP29_KINDS.GROUP_MEMBERS] }),
12995
- {
12996
- onEvent: (event) => {
12997
- const groupId = this.getGroupIdFromMetadataEvent(event);
12998
- if (groupId) {
12999
- const pTags = event.tags.filter((t) => t[0] === "p");
13000
- memberCountsMap.set(groupId, pTags.length);
12952
+ await this.oneshotSubscription(
12953
+ new import_nostr_js_sdk4.Filter({ kinds: [NIP29_KINDS.GROUP_METADATA] }),
12954
+ {
12955
+ onEvent: (event) => {
12956
+ const group = this.parseGroupMetadata(event);
12957
+ if (group && group.visibility === GroupVisibility.PUBLIC) {
12958
+ const existing = groupsMap.get(group.id);
12959
+ if (!existing || group.createdAt > existing.createdAt) {
12960
+ groupsMap.set(group.id, group);
13001
12961
  }
13002
- },
13003
- onComplete: () => {
13004
- },
13005
- timeoutMs: 1e4,
13006
- timeoutLabel: "fetchAvailableGroups(members)"
13007
- }
13008
- )
13009
- ]);
13010
- for (const [groupId, count] of memberCountsMap) {
13011
- const group = groupsMap.get(groupId);
13012
- if (group) group.memberCount = count;
13013
- }
12962
+ }
12963
+ },
12964
+ onComplete: () => {
12965
+ },
12966
+ timeoutMs: 1e4,
12967
+ timeoutLabel: "fetchAvailableGroups(metadata)"
12968
+ }
12969
+ );
13014
12970
  return Array.from(groupsMap.values());
13015
12971
  }
13016
12972
  async joinGroup(groupId, inviteCode) {
@@ -13815,6 +13771,7 @@ var GroupChatModule = class {
13815
13771
  let name = "Unnamed Group";
13816
13772
  let description;
13817
13773
  let picture;
13774
+ let memberCount;
13818
13775
  let isPrivate = false;
13819
13776
  let writeRestricted = false;
13820
13777
  if (event.content && event.content.trim()) {
@@ -13835,6 +13792,7 @@ var GroupChatModule = class {
13835
13792
  if (tag[0] === "private") isPrivate = true;
13836
13793
  if (tag[0] === "public" && tag[1] === "false") isPrivate = true;
13837
13794
  if (tag[0] === "write-restricted") writeRestricted = true;
13795
+ if (tag[0] === "member_count" && tag[1]) memberCount = parseInt(tag[1], 10) || void 0;
13838
13796
  }
13839
13797
  return {
13840
13798
  id: groupId,
@@ -13842,6 +13800,7 @@ var GroupChatModule = class {
13842
13800
  name,
13843
13801
  description,
13844
13802
  picture,
13803
+ memberCount,
13845
13804
  visibility: isPrivate ? GroupVisibility.PRIVATE : GroupVisibility.PUBLIC,
13846
13805
  writeRestricted: writeRestricted || void 0,
13847
13806
  createdAt: event.created_at * 1e3