This commit is contained in:
or-else
2023-04-14 19:38:21 -07:00
parent 364cd2c488
commit e7296d5d14
4 changed files with 75 additions and 11 deletions
+72 -8
View File
@@ -410,6 +410,7 @@ __webpack_require__.r(__webpack_exports__);
/* harmony export */ "EXPIRE_PROMISES_TIMEOUT": () => (/* binding */ EXPIRE_PROMISES_TIMEOUT), /* harmony export */ "EXPIRE_PROMISES_TIMEOUT": () => (/* binding */ EXPIRE_PROMISES_TIMEOUT),
/* harmony export */ "LIBRARY": () => (/* binding */ LIBRARY), /* harmony export */ "LIBRARY": () => (/* binding */ LIBRARY),
/* harmony export */ "LOCAL_SEQID": () => (/* binding */ LOCAL_SEQID), /* harmony export */ "LOCAL_SEQID": () => (/* binding */ LOCAL_SEQID),
/* harmony export */ "MAX_PINNED_COUNT": () => (/* binding */ MAX_PINNED_COUNT),
/* harmony export */ "MESSAGE_STATUS_FAILED": () => (/* binding */ MESSAGE_STATUS_FAILED), /* harmony export */ "MESSAGE_STATUS_FAILED": () => (/* binding */ MESSAGE_STATUS_FAILED),
/* harmony export */ "MESSAGE_STATUS_FATAL": () => (/* binding */ MESSAGE_STATUS_FATAL), /* harmony export */ "MESSAGE_STATUS_FATAL": () => (/* binding */ MESSAGE_STATUS_FATAL),
/* harmony export */ "MESSAGE_STATUS_NONE": () => (/* binding */ MESSAGE_STATUS_NONE), /* harmony export */ "MESSAGE_STATUS_NONE": () => (/* binding */ MESSAGE_STATUS_NONE),
@@ -463,6 +464,7 @@ const EXPIRE_PROMISES_PERIOD = 1000;
const RECV_TIMEOUT = 100; const RECV_TIMEOUT = 100;
const DEFAULT_MESSAGES_PAGE = 24; const DEFAULT_MESSAGES_PAGE = 24;
const DEL_CHAR = '\u2421'; const DEL_CHAR = '\u2421';
const MAX_PINNED_COUNT = 5;
/***/ }), /***/ }),
@@ -1306,7 +1308,7 @@ function _serializeMessage(dst, msg) {
} }
var _topic_fields = { var _topic_fields = {
writable: true, writable: true,
value: ['created', 'updated', 'deleted', 'read', 'recv', 'seq', 'clear', 'defacs', 'creds', 'public', 'trusted', 'private', 'touched', '_deleted'] value: ['created', 'updated', 'deleted', 'touched', 'read', 'recv', 'seq', 'clear', 'defacs', 'creds', 'public', 'trusted', 'private', '_aux', '_deleted']
}; };
/***/ }), /***/ }),
@@ -3327,6 +3329,10 @@ class MetaGetBuilder {
} }
return this; return this;
} }
withAux() {
this.what['aux'] = true;
return this;
}
withDel(since, limit) { withDel(since, limit) {
if (since || limit) { if (since || limit) {
this.what['del'] = { this.what['del'] = {
@@ -3345,7 +3351,7 @@ class MetaGetBuilder {
build() { build() {
const what = []; const what = [];
let params = {}; let params = {};
['data', 'sub', 'desc', 'tags', 'cred', 'del'].forEach(key => { ['data', 'sub', 'desc', 'tags', 'cred', 'aux', 'del'].forEach(key => {
if (this.what.hasOwnProperty(key)) { if (this.what.hasOwnProperty(key)) {
what.push(key); what.push(key);
if (Object.getOwnPropertyNames(this.what[key]).length > 0) { if (Object.getOwnPropertyNames(this.what[key]).length > 0) {
@@ -3425,6 +3431,7 @@ class Topic {
this._recvNotificationTimer = null; this._recvNotificationTimer = null;
this._tags = []; this._tags = [];
this._credentials = []; this._credentials = [];
this._aux = {};
this._messageVersions = {}; this._messageVersions = {};
this._messages = new _cbuffer_js__WEBPACK_IMPORTED_MODULE_1__["default"]((a, b) => { this._messages = new _cbuffer_js__WEBPACK_IMPORTED_MODULE_1__["default"]((a, b) => {
return a.seq - b.seq; return a.seq - b.seq;
@@ -3444,6 +3451,7 @@ class Topic {
this.onSubsUpdated = callbacks.onSubsUpdated; this.onSubsUpdated = callbacks.onSubsUpdated;
this.onTagsUpdated = callbacks.onTagsUpdated; this.onTagsUpdated = callbacks.onTagsUpdated;
this.onCredsUpdated = callbacks.onCredsUpdated; this.onCredsUpdated = callbacks.onCredsUpdated;
this.onAuxUpdated = callbacks.onAuxUpdated;
this.onDeleteTopic = callbacks.onDeleteTopic; this.onDeleteTopic = callbacks.onDeleteTopic;
this.onAllMessagesReceived = callbacks.onAllMessagesReceived; this.onAllMessagesReceived = callbacks.onAllMessagesReceived;
} }
@@ -3688,6 +3696,9 @@ class Topic {
if (params.cred) { if (params.cred) {
this._processMetaCreds([params.cred], true); this._processMetaCreds([params.cred], true);
} }
if (params.aux) {
this._processMetaAux(params.aux);
}
return ctrl; return ctrl;
}); });
} }
@@ -3721,6 +3732,38 @@ class Topic {
} }
}); });
} }
pinMessage(seq, pin) {
let pinned = this.aux('pins');
if (!Array.isArray(pinned)) {
pinned = [];
}
let changed = false;
if (pin) {
if (!pinned.includes(seq)) {
changed = true;
if (pinned.length == _config_js__WEBPACK_IMPORTED_MODULE_3__.MAX_PINNED_COUNT) {
pinned.shift();
}
pinned.push(seq);
}
} else {
if (pinned.includes(seq)) {
changed = true;
pinned = pinned.filter(id => id != seq);
if (pinned.length == 0) {
pinned = _config_js__WEBPACK_IMPORTED_MODULE_3__.DEL_CHAR;
}
}
}
if (changed) {
return this.setMeta({
aux: {
pins: pinned
}
});
}
return Promise.resolve();
}
delMessages(ranges, hard) { delMessages(ranges, hard) {
if (!this._attached) { if (!this._attached) {
return Promise.reject(new Error("Cannot delete messages in inactive topic")); return Promise.reject(new Error("Cannot delete messages in inactive topic"));
@@ -3950,6 +3993,9 @@ class Topic {
tags() { tags() {
return this._tags.slice(0); return this._tags.slice(0);
} }
aux(key) {
return this._aux[key];
}
subscriber(uid) { subscriber(uid) {
return this._users[uid]; return this._users[uid];
} }
@@ -4250,6 +4296,9 @@ class Topic {
if (meta.cred) { if (meta.cred) {
this._processMetaCreds(meta.cred); this._processMetaCreds(meta.cred);
} }
if (meta.aux) {
this._processMetaAux(meta.aux);
}
if (this.onMeta) { if (this.onMeta) {
this.onMeta(meta); this.onMeta(meta);
} }
@@ -4277,6 +4326,9 @@ class Topic {
this.getMeta(this.startMetaQuery().withLaterOneSub(pres.src).build()); this.getMeta(this.startMetaQuery().withLaterOneSub(pres.src).build());
} }
break; break;
case 'aux':
this.getMeta(this.startMetaQuery().withAux().build());
break;
case 'acs': case 'acs':
uid = pres.src || this._tinode.getCurrentUserID(); uid = pres.src || this._tinode.getCurrentUserID();
user = this._users[uid]; user = this._users[uid];
@@ -4391,22 +4443,31 @@ class Topic {
} }
} }
_processMetaTags(tags) { _processMetaTags(tags) {
if (tags.length == 1 && tags[0] == _config_js__WEBPACK_IMPORTED_MODULE_3__.DEL_CHAR) { if (tags == _config_js__WEBPACK_IMPORTED_MODULE_3__.DEL_CHAR || tags.length == 1 && tags[0] == _config_js__WEBPACK_IMPORTED_MODULE_3__.DEL_CHAR) {
tags = []; tags = [];
} }
this._tags = tags; this._tags = tags;
this._tinode._db.updTopic(this);
if (this.onTagsUpdated) { if (this.onTagsUpdated) {
this.onTagsUpdated(tags); this.onTagsUpdated(tags);
} }
} }
_processMetaCreds(creds) {} _processMetaCreds(creds) {}
_processMetaAux(aux) {
aux = !aux || aux == _config_js__WEBPACK_IMPORTED_MODULE_3__.DEL_CHAR ? {} : aux;
this._aux = (0,_utils_js__WEBPACK_IMPORTED_MODULE_6__.mergeObj)(this._aux, aux);
this._tinode._db.updTopic(this);
if (this.onAuxUpdated) {
this.onAuxUpdated(this._aux);
}
}
_processDelMessages(clear, delseq) { _processDelMessages(clear, delseq) {
this._maxDel = Math.max(clear, this._maxDel); this._maxDel = Math.max(clear, this._maxDel);
this.clear = Math.max(clear, this.clear); this.clear = Math.max(clear, this.clear);
const topic = this; const topic = this;
let count = 0; let count = 0;
if (Array.isArray(delseq)) { if (Array.isArray(delseq)) {
delseq.forEach(function (range) { delseq.forEach(range => {
if (!range.hi) { if (!range.hi) {
count++; count++;
topic.flushMessage(range.low); topic.flushMessage(range.low);
@@ -4928,7 +4989,7 @@ function normalizeArray(arr) {
} }
} }
} }
out.sort().filter(function (item, pos, ary) { out.sort().filter((item, pos, ary) => {
return !pos || item != ary[pos - 1]; return !pos || item != ary[pos - 1];
}); });
} }
@@ -4950,7 +5011,7 @@ __webpack_require__.r(__webpack_exports__);
/* harmony export */ __webpack_require__.d(__webpack_exports__, { /* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */ "PACKAGE_VERSION": () => (/* binding */ PACKAGE_VERSION) /* harmony export */ "PACKAGE_VERSION": () => (/* binding */ PACKAGE_VERSION)
/* harmony export */ }); /* harmony export */ });
const PACKAGE_VERSION = "0.22.3"; const PACKAGE_VERSION = "0.23.0-rc1";
/***/ }) /***/ })
@@ -5670,6 +5731,9 @@ class Tinode {
if (setParams.tags) { if (setParams.tags) {
pkt.sub.set.tags = setParams.tags; pkt.sub.set.tags = setParams.tags;
} }
if (setParams.aux) {
pkt.sub.set.aux = setParams.aux;
}
} }
return _classPrivateMethodGet(this, _send, _send2).call(this, pkt, pkt.sub.id); return _classPrivateMethodGet(this, _send, _send2).call(this, pkt, pkt.sub.id);
} }
@@ -5784,7 +5848,7 @@ class Tinode {
const pkt = _classPrivateMethodGet(this, _initPacket, _initPacket2).call(this, 'set', topic); const pkt = _classPrivateMethodGet(this, _initPacket, _initPacket2).call(this, 'set', topic);
const what = []; const what = [];
if (params) { if (params) {
['desc', 'sub', 'tags', 'cred', 'ephemeral'].forEach(function (key) { ['desc', 'sub', 'tags', 'cred', 'aux'].forEach(key => {
if (params.hasOwnProperty(key)) { if (params.hasOwnProperty(key)) {
what.push(key); what.push(key);
pkt.set[key] = params[key]; pkt.set[key] = params[key];
@@ -6210,7 +6274,7 @@ function _initPacket2(type, topic) {
'desc': {}, 'desc': {},
'sub': {}, 'sub': {},
'tags': [], 'tags': [],
'ephemeral': {} 'aux': {}
} }
}; };
case 'del': case 'del':
File diff suppressed because one or more lines are too long
+1 -1
View File
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long