@unicitylabs/sphere-sdk 0.6.0-dev.1 → 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.
- package/README.md +8 -0
- package/dist/core/index.cjs +33 -11
- package/dist/core/index.cjs.map +1 -1
- package/dist/core/index.d.cts +10 -0
- package/dist/core/index.d.ts +10 -0
- package/dist/core/index.js +33 -11
- package/dist/core/index.js.map +1 -1
- package/dist/index.cjs +33 -11
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +10 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +33 -11
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -9527,17 +9527,23 @@ var GroupChatModule = class {
|
|
|
9527
9527
|
const group = this.groups.get(groupId);
|
|
9528
9528
|
if (!group) return;
|
|
9529
9529
|
if (event.kind === NIP29_KINDS.GROUP_METADATA) {
|
|
9530
|
-
if (
|
|
9531
|
-
|
|
9532
|
-
|
|
9533
|
-
|
|
9534
|
-
|
|
9535
|
-
|
|
9536
|
-
|
|
9537
|
-
|
|
9538
|
-
|
|
9539
|
-
|
|
9530
|
+
if (event.content && event.content.trim()) {
|
|
9531
|
+
try {
|
|
9532
|
+
const metadata = JSON.parse(event.content);
|
|
9533
|
+
group.name = metadata.name || group.name;
|
|
9534
|
+
group.description = metadata.about || group.description;
|
|
9535
|
+
group.picture = metadata.picture || group.picture;
|
|
9536
|
+
if (metadata["write-restricted"] === true) group.writeRestricted = true;
|
|
9537
|
+
else group.writeRestricted = void 0;
|
|
9538
|
+
} catch {
|
|
9539
|
+
}
|
|
9540
9540
|
}
|
|
9541
|
+
for (const tag of event.tags) {
|
|
9542
|
+
if (tag[0] === "write-restricted") group.writeRestricted = true;
|
|
9543
|
+
}
|
|
9544
|
+
group.updatedAt = event.created_at * 1e3;
|
|
9545
|
+
this.groups.set(groupId, group);
|
|
9546
|
+
this.persistGroups();
|
|
9541
9547
|
} else if (event.kind === NIP29_KINDS.GROUP_MEMBERS) {
|
|
9542
9548
|
this.updateMembersFromEvent(groupId, event);
|
|
9543
9549
|
} else if (event.kind === NIP29_KINDS.GROUP_ADMINS) {
|
|
@@ -9841,7 +9847,8 @@ var GroupChatModule = class {
|
|
|
9841
9847
|
picture: options.picture,
|
|
9842
9848
|
closed: true,
|
|
9843
9849
|
private: isPrivate,
|
|
9844
|
-
hidden: isPrivate
|
|
9850
|
+
hidden: isPrivate,
|
|
9851
|
+
...options.writeRestricted ? { "write-restricted": true } : {}
|
|
9845
9852
|
})
|
|
9846
9853
|
});
|
|
9847
9854
|
if (!eventId) return null;
|
|
@@ -10142,6 +10149,17 @@ var GroupChatModule = class {
|
|
|
10142
10149
|
const admins = await this.fetchRelayAdmins();
|
|
10143
10150
|
return admins.has(myPubkey);
|
|
10144
10151
|
}
|
|
10152
|
+
/**
|
|
10153
|
+
* Check if current user can write messages to a group.
|
|
10154
|
+
* For write-restricted groups, only admins/moderators can post.
|
|
10155
|
+
* For normal groups, any member can post.
|
|
10156
|
+
*/
|
|
10157
|
+
canWriteToGroup(groupId) {
|
|
10158
|
+
const group = this.groups.get(groupId);
|
|
10159
|
+
if (!group) return false;
|
|
10160
|
+
if (!group.writeRestricted) return true;
|
|
10161
|
+
return this.isCurrentUserModerator(groupId);
|
|
10162
|
+
}
|
|
10145
10163
|
getCurrentUserRole(groupId) {
|
|
10146
10164
|
const myPubkey = this.getMyPublicKey();
|
|
10147
10165
|
if (!myPubkey) return null;
|
|
@@ -10516,6 +10534,7 @@ var GroupChatModule = class {
|
|
|
10516
10534
|
let description;
|
|
10517
10535
|
let picture;
|
|
10518
10536
|
let isPrivate = false;
|
|
10537
|
+
let writeRestricted = false;
|
|
10519
10538
|
if (event.content && event.content.trim()) {
|
|
10520
10539
|
try {
|
|
10521
10540
|
const metadata = JSON.parse(event.content);
|
|
@@ -10523,6 +10542,7 @@ var GroupChatModule = class {
|
|
|
10523
10542
|
description = metadata.about || metadata.description;
|
|
10524
10543
|
picture = metadata.picture;
|
|
10525
10544
|
isPrivate = metadata.private === true;
|
|
10545
|
+
if (metadata["write-restricted"] === true) writeRestricted = true;
|
|
10526
10546
|
} catch {
|
|
10527
10547
|
}
|
|
10528
10548
|
}
|
|
@@ -10532,6 +10552,7 @@ var GroupChatModule = class {
|
|
|
10532
10552
|
if (tag[0] === "picture" && tag[1]) picture = tag[1];
|
|
10533
10553
|
if (tag[0] === "private") isPrivate = true;
|
|
10534
10554
|
if (tag[0] === "public" && tag[1] === "false") isPrivate = true;
|
|
10555
|
+
if (tag[0] === "write-restricted") writeRestricted = true;
|
|
10535
10556
|
}
|
|
10536
10557
|
return {
|
|
10537
10558
|
id: groupId,
|
|
@@ -10540,6 +10561,7 @@ var GroupChatModule = class {
|
|
|
10540
10561
|
description,
|
|
10541
10562
|
picture,
|
|
10542
10563
|
visibility: isPrivate ? GroupVisibility.PRIVATE : GroupVisibility.PUBLIC,
|
|
10564
|
+
writeRestricted: writeRestricted || void 0,
|
|
10543
10565
|
createdAt: event.created_at * 1e3
|
|
10544
10566
|
};
|
|
10545
10567
|
} catch {
|