@decentnetwork/beagle 0.1.138 → 0.1.143

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.
@@ -38,6 +38,12 @@ export class MessageStore {
38
38
  for (const m of msgs)
39
39
  if (m.status === "sending")
40
40
  m.status = "queued";
41
+ // Same for an outgoing file: its transfer died with the process, and
42
+ // its bytes are still in outbox/<id>. Left "sending" it was stuck
43
+ // forever — nothing ever offers a "sending" row again.
44
+ for (const m of msgs)
45
+ if (m.dir === "out" && m.file?.status === "sending")
46
+ m.file.status = "queued";
41
47
  this.byPeer.set(peer, msgs);
42
48
  total += msgs.length;
43
49
  }
@@ -96,6 +102,19 @@ export class MessageStore {
96
102
  this.scheduleSave();
97
103
  return true;
98
104
  }
105
+ /** The same for a FILE row: "offline" = parked on Express, "online" = a
106
+ * live transfer, undefined = not on the wire yet (waiting in the outbox). */
107
+ setFileVia(peer, id, via) {
108
+ const msg = this.byPeer.get(peer)?.find((m) => m.id === id);
109
+ if (!msg || !msg.file)
110
+ return false;
111
+ if (via)
112
+ msg.via = via;
113
+ else
114
+ delete msg.via;
115
+ this.scheduleSave();
116
+ return true;
117
+ }
99
118
  /** Has this peer ever sent us anything? Used as proof-of-friendship for
100
119
  * records that predate the SDK's acceptedAt bookkeeping — a message can
101
120
  * only arrive over an established session. */
@@ -145,9 +164,12 @@ export class MessageStore {
145
164
  thread(peer) {
146
165
  return this.byPeer.get(peer) ?? [];
147
166
  }
148
- /** True when this peer's thread already holds a file with these bytes. */
149
- hasFileSha(peer, sha256) {
150
- return (this.history(peer)[peer] ?? []).some((m) => m.file?.sha256 === sha256);
167
+ /** True when this peer's thread already holds a file with these bytes —
168
+ * in `dir` only, when given (a received file must not be dropped because
169
+ * we once SENT the same bytes). */
170
+ hasFileSha(peer, sha256, dir) {
171
+ const want = sha256.toLowerCase();
172
+ return (this.history(peer)[peer] ?? []).some((m) => m.file?.sha256?.toLowerCase() === want && (!dir || m.dir === dir));
151
173
  }
152
174
  /** Patch an existing file message's transfer fields (status / sent bytes).
153
175
  * No-op if the id isn't found. Returns true if it patched. */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@decentnetwork/beagle",
3
- "version": "0.1.138",
3
+ "version": "0.1.143",
4
4
  "description": "Beagle — P2P chat, file transfer and calls for regular users, on the Decent Network. No admin privilege required.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -26,10 +26,10 @@
26
26
  "start": "node dist/cli.js"
27
27
  },
28
28
  "dependencies": {
29
- "@decentnetwork/beagle-ui": "^0.2.43",
29
+ "@decentnetwork/beagle-ui": "^0.2.45",
30
30
  "@decentnetwork/chat-components": "^0.1.3",
31
31
  "@decentnetwork/lan": "^0.1.316",
32
- "@decentnetwork/peer": "^0.1.172",
32
+ "@decentnetwork/peer": "^0.1.178",
33
33
  "@decentnetwork/peer-webrtc": "^0.2.21",
34
34
  "js-yaml": "^4.1.0",
35
35
  "ws": "^8.21.1",