wireweave 0.3.37 → 0.3.39

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wireweave",
3
- "version": "0.3.37",
3
+ "version": "0.3.39",
4
4
  "description": "nostr + webrtc voice + data SDK. networking layer for 247420 projects.",
5
5
  "type": "module",
6
6
  "main": "./src/index.js",
package/src/chat.js CHANGED
@@ -24,7 +24,7 @@ export class Chat extends EventTarget {
24
24
  return this._sendTimes[0] + this.rateLimitWindowMs - now;
25
25
  }
26
26
 
27
- async send(content, { announcement = false } = {}) {
27
+ async send(content, { announcement = false, replyTo = null } = {}) {
28
28
  const { channelId, serverId } = this.getChannelContext();
29
29
  if (!this.auth.isLoggedIn() || !channelId) return;
30
30
  if (announcement && !this.isAdmin(serverId)) return;
@@ -37,6 +37,7 @@ export class Chat extends EventTarget {
37
37
  this._sendTimes.push(Date.now());
38
38
  const chanHex = await hexChannelId(channelId, serverId);
39
39
  const tags = [['e', chanHex, '', 'root']];
40
+ if (replyTo?.id) tags.push(['e', replyTo.id, '', 'reply']);
40
41
  if (announcement) tags.push(['t', 'announcement']);
41
42
  const signed = await this.auth.sign({ kind: 42, created_at: Math.floor(Date.now() / 1000), tags, content: trimmed });
42
43
  this.pool.publish(signed);
@@ -82,7 +83,13 @@ export class Chat extends EventTarget {
82
83
  _eventToMsg(event) {
83
84
  const tTags = (event.tags || []).filter(t => t[0] === 't').map(t => t[1]);
84
85
  this._fetchProfile(event.pubkey);
85
- return { id: event.id, type: 'text', userId: event.pubkey, content: event.content, timestamp: event.created_at * 1000, tags: tTags };
86
+ const replyTag = (event.tags || []).find(t => t[0] === 'e' && t[3] === 'reply');
87
+ let replyTo = null;
88
+ if (replyTag) {
89
+ const cached = this.messages.find(m => m.id === replyTag[1]);
90
+ replyTo = cached ? { id: cached.id, userId: cached.userId, content: cached.content } : { id: replyTag[1] };
91
+ }
92
+ return { id: event.id, type: 'text', userId: event.pubkey, content: event.content, timestamp: event.created_at * 1000, tags: tTags, replyTo };
86
93
  }
87
94
 
88
95
  _addMessage(msg) {
package/src/servers.js CHANGED
@@ -62,13 +62,13 @@ export class Servers extends EventTarget {
62
62
  await this.switchTo(serverId);
63
63
  }
64
64
 
65
- async join(serverId) {
65
+ async join(serverId, { name = null, iconColor = '#5865F2', select = true } = {}) {
66
66
  try {
67
67
  const joined = JSON.parse(this.storage.getItem('zn_joined_servers') || '[]');
68
68
  if (!joined.includes(serverId)) { joined.push(serverId); safeSetItem(this.storage, this, 'zn_joined_servers', JSON.stringify(joined)); }
69
69
  } catch {}
70
- if (!this.servers.find(s => s.id === serverId)) { this.servers = [...this.servers, { id: serverId, name: serverId.slice(0, 8), iconColor: '#5865F2' }]; this._persist(); }
71
- await this.switchTo(serverId);
70
+ if (!this.servers.find(s => s.id === serverId)) { this.servers = [...this.servers, { id: serverId, name: name || serverId.slice(0, 8), iconColor }]; this._persist(); this._emit('updated', { servers: this.servers }); }
71
+ if (select) await this.switchTo(serverId);
72
72
  }
73
73
 
74
74
  async delete(serverId) {