Skip to content

Commit

Permalink
work in progress on disappearing deleted topic
Browse files Browse the repository at this point in the history
  • Loading branch information
or-else committed May 9, 2023
1 parent 96a9317 commit 0e5586d
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 27 deletions.
9 changes: 6 additions & 3 deletions src/db.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,10 @@ export default class DB {
* Mark or unmark topic as deleted.
* @memberOf DB
* @param {string} name - name of the topic to mark or unmark.
* @param {boolean} deleted - status
* @return {Promise} promise resolved/rejected on operation completion.
*/
markTopicAsDeleted(name) {
markTopicAsDeleted(name, deleted) {
if (!this.isReady()) {
return this.disabled ?
Promise.resolve() :
Expand All @@ -197,8 +198,10 @@ export default class DB {
const req = trx.objectStore('topic').get(name);
req.onsuccess = event => {
const topic = event.target.result;
topic._deleted = true;
trx.objectStore('topic').put(topic);
if (topic && topic._deleted != deleted) {
topic._deleted = deleted;
trx.objectStore('topic').put(topic);
}
trx.commit();
};
});
Expand Down
4 changes: 2 additions & 2 deletions src/meta-builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ export default class MetaGetBuilder {

// Get timestamp of the most recent desc update.
#get_desc_ims() {
return this.topic.updated;
return this.topic._deleted ? undefined : this.topic.updated;
}

// Get timestamp of the most recent subs update.
#get_subs_ims() {
if (this.topic.isP2PType()) {
return this.#get_desc_ims();
}
return this.topic._lastSubsUpdate;
return this.topic._deleted ? undefined : this.topic._lastSubsUpdate;
}
/**
* Add query parameters to fetch messages within explicit limits.
Expand Down
3 changes: 3 additions & 0 deletions src/tinode.js
Original file line number Diff line number Diff line change
Expand Up @@ -843,6 +843,9 @@ export class Tinode {

// Cache management
#cachePut(type, name, obj) {
if (name == 'usrGosrQjv25RM') {
console.log("adding", type, "to cache", new Error("stacktrace"));
}
this._cache[type + ':' + name] = obj;
}
#cacheGet(type, name) {
Expand Down
25 changes: 17 additions & 8 deletions src/topic.js
Original file line number Diff line number Diff line change
Expand Up @@ -239,11 +239,6 @@ export class Topic {
return Promise.resolve(this);
}

// If the topic is deleted, reject subscription requests.
if (this._deleted) {
return Promise.reject(new Error("Conversation deleted"));
}

// Send subscribe message, handle async response.
// If topic name is explicitly provided, use it. If no name, then it's a new group topic,
// use "new".
Expand Down Expand Up @@ -1633,7 +1628,7 @@ export class Topic {
// Issue {get sub} only if the current user has no p2p topics with the updated user (p2p name is not in cache).
// Otherwise 'me' will issue a {get desc} request.
if (pres.src && !this._tinode.isTopicCached(pres.src)) {
this.getMeta(this.startMetaQuery().withLaterOneSub(pres.src).build());
this.getMeta(this.startMetaQuery().withOneSub(pres.src).build());
}
break;
case 'acs':
Expand Down Expand Up @@ -2076,6 +2071,8 @@ export class TopicMe extends Topic {

// Process presence change message
_routePres(pres) {
console.log("me._routePres", pres.what);

if (pres.what == 'term') {
// The 'me' topic itself is detached. Mark as unsubscribed.
this._resetSub();
Expand Down Expand Up @@ -2103,6 +2100,7 @@ export class TopicMe extends Topic {
}
break;
case 'msg': // new message received
console.log("me._routePres>_updateReceived", pres.seq, pres.act, cont._deleted);
cont._updateReceived(pres.seq, pres.act);
break;
case 'upd': // desc updated
Expand Down Expand Up @@ -2138,10 +2136,12 @@ export class TopicMe extends Topic {
break;
case 'gone':
// topic deleted or unsubscribed from.
this._tinode.cacheRemTopic(pres.src);
console.log("gone, deleting", this._tinode.cacheGetTopic(pres.src));
if (!cont._deleted) {
cont._deleted = true;
cont._attached = false;
this._tinode._db.markTopicAsDeleted(pres.src);
this._tinode._db.markTopicAsDeleted(pres.src, true);
} else {
this._tinode._db.remTopic(pres.src);
}
Expand Down Expand Up @@ -2172,14 +2172,23 @@ export class TopicMe extends Topic {
this.getMeta(this.startMetaQuery().withOneSub(undefined, pres.src).build());
// Create a dummy entry to catch online status update.
const dummy = this._tinode.getTopic(pres.src);
dummy.topic = pres.src;
dummy.online = false;
dummy.acs = acs;
this._tinode._db.updTopic(dummy);
}
} else if (pres.what == 'tags') {
this.getMeta(this.startMetaQuery().withTags().build());
} else if (pres.what == 'msg') {
console.log("me._routePres > this.getMeta", pres.src);
// Message received for un unknown (previously deleted) topic.
this.getMeta(this.startMetaQuery().withOneSub(undefined, pres.src).build());
// Create an entry to catch updates and messages.
const dummy = this._tinode.getTopic(pres.src);
dummy._deleted = false;
this._tinode._db.updTopic(dummy);
}

this._refreshContact(pres.what, cont);
}

if (this.onPres) {
Expand Down
34 changes: 23 additions & 11 deletions umd/tinode.dev.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion umd/tinode.dev.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion umd/tinode.prod.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion umd/tinode.prod.js.map

Large diffs are not rendered by default.

0 comments on commit 0e5586d

Please sign in to comment.