trac-peer 0.0.52 → 0.0.53
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 +1 -1
- package/src/contract.js +2 -2
- package/src/index.js +10 -2
package/package.json
CHANGED
package/src/contract.js
CHANGED
|
@@ -19,9 +19,9 @@ class Contract {
|
|
|
19
19
|
|
|
20
20
|
async put(key, value){
|
|
21
21
|
if(typeof this.storage === "undefined" || this.storage === null) throw new Error('put(key,value): storage undefined');
|
|
22
|
-
if(key.startsWith('sh/') || key.startsWith('tx/') || key === 'msgl' || key.startsWith('kcin/') ||
|
|
22
|
+
if(key.startsWith('sh/') || key.startsWith('tx/') || key === 'msgl' || key.startsWith('kcin/') || key.startsWith('delm/') ||
|
|
23
23
|
key.startsWith('msg/') || key === 'admin' || key === 'auto_add_writers' || key.startsWith('nick/') || key.startsWith('mod/') ||
|
|
24
|
-
key === 'chat_status' || key.startsWith('mtd/')) throw Error('put(key,value): ' + key + 'is reserved');
|
|
24
|
+
key === 'chat_status' || key.startsWith('mtd/') || key === 'delml') throw Error('put(key,value): ' + key + 'is reserved');
|
|
25
25
|
return await this.storage.put(key, value);
|
|
26
26
|
}
|
|
27
27
|
|
package/src/index.js
CHANGED
|
@@ -302,7 +302,7 @@ export class Peer extends ReadyResource {
|
|
|
302
302
|
if(op.value === undefined || op.value.dispatch === undefined || op.value.dispatch.id === undefined ||
|
|
303
303
|
typeof op.value.dispatch.id !== "number" || op.value.dispatch.type === undefined ||
|
|
304
304
|
op.value.dispatch.address === undefined || typeof op.value.dispatch.address !== "string" ||
|
|
305
|
-
op.nonce === undefined || op.hash === undefined) continue;
|
|
305
|
+
op.nonce === undefined || op.hash === undefined || op.value.dispatch.deleted_by === undefined) continue;
|
|
306
306
|
|
|
307
307
|
const admin = await batch.get('admin');
|
|
308
308
|
const str_value = jsonStringify(op.value);
|
|
@@ -310,7 +310,7 @@ export class Peer extends ReadyResource {
|
|
|
310
310
|
null === await batch.get('sh/'+op.hash)){
|
|
311
311
|
const mod = await batch.get('mod/'+op.value.dispatch.address);
|
|
312
312
|
const message = await batch.get('msg/'+op.value.dispatch.id);
|
|
313
|
-
if(null !== message && null !== message.value) {
|
|
313
|
+
if(null !== message && null !== message.value && message.value.deleted_by !== undefined && null === message.value.deleted_by) {
|
|
314
314
|
let mod_verified = false;
|
|
315
315
|
if(null !== mod && true === mod.value && message.value.address !== admin.value) {
|
|
316
316
|
mod_verified = _this.wallet.verify(op.hash, str_value + op.nonce, op.value.dispatch.address);
|
|
@@ -325,7 +325,15 @@ export class Peer extends ReadyResource {
|
|
|
325
325
|
message.value.msg = null;
|
|
326
326
|
message.value.attachments = [];
|
|
327
327
|
message.value.deleted_by = verified ? admin.value : op.value.dispatch.address;
|
|
328
|
+
let len = await batch.get('delml');
|
|
329
|
+
if(null === len) {
|
|
330
|
+
len = 0;
|
|
331
|
+
} else {
|
|
332
|
+
len = len.value;
|
|
333
|
+
}
|
|
328
334
|
await batch.put('msg/'+op.value.dispatch.id, message);
|
|
335
|
+
await batch.put('delm/'+len, op.value.dispatch.id);
|
|
336
|
+
await batch.put('delml', len + 1);
|
|
329
337
|
console.log(`Deleted message ${op.value.dispatch.id} by user ${message.value.address}`);
|
|
330
338
|
}
|
|
331
339
|
}
|