mostly functional

This commit is contained in:
or-else
2023-04-27 17:44:20 -07:00
parent 1bc3e15da3
commit c277c16a53
9 changed files with 33 additions and 43 deletions
+1 -2
View File
@@ -585,9 +585,8 @@ class MessagesView extends React.Component {
const {min, max} = this.getVisibleMessageRange(event.target.getBoundingClientRect());
const gaps = topic.msgHasMoreMessages(min, max, false);
if (gaps.length > 0) {
console.log("Fetch triggered", min, max, gaps);
this.setState({fetchingMessages: true}, _ => {
topic.getMessagesPage(MESSAGES_PAGE, gaps)
topic.getMessagesPage(MESSAGES_PAGE, gaps, min, max)
.catch(err => this.props.onError(err.message, 'err'))
.finally(_ => this.setState({fetchingMessages: false}));
});
+1 -2
View File
@@ -5593,11 +5593,10 @@ class MessagesView extends (react__WEBPACK_IMPORTED_MODULE_0___default().Compone
} = this.getVisibleMessageRange(event.target.getBoundingClientRect());
const gaps = topic.msgHasMoreMessages(min, max, false);
if (gaps.length > 0) {
console.log("Fetch triggered", min, max, gaps);
this.setState({
fetchingMessages: true
}, _ => {
topic.getMessagesPage(_config_js__WEBPACK_IMPORTED_MODULE_18__.MESSAGES_PAGE, gaps).catch(err => this.props.onError(err.message, 'err')).finally(_ => this.setState({
topic.getMessagesPage(_config_js__WEBPACK_IMPORTED_MODULE_18__.MESSAGES_PAGE, gaps, min, max).catch(err => this.props.onError(err.message, 'err')).finally(_ => this.setState({
fetchingMessages: false
}));
});
+1 -1
View File
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
+25 -33
View File
@@ -1128,7 +1128,7 @@ class DB {
return this.disabled ? Promise.resolve([]) : Promise.reject(new Error("not initialized"));
}
const trx = this.db.transaction(['message']);
const result = [];
let result = [];
if (Array.isArray(query.ranges)) {
return new Promise((resolve, reject) => {
trx.onerror = event => {
@@ -1137,18 +1137,20 @@ class DB {
};
let count = 0;
query.ranges.forEach(range => {
const key = range.hi ? IDBKeyRange.bound([topicName, range.low], [topicName, range.Hi], false, true) : IDBKeyRange.only([topicName, range.low]);
trx.objectStore('message').get(key).onsuccess = event => {
const key = range.hi ? IDBKeyRange.bound([topicName, range.low], [topicName, range.hi], false, true) : IDBKeyRange.only([topicName, range.low]);
trx.objectStore('message').getAll(key).onsuccess = event => {
const msgs = event.target.result;
if (callback) {
callback.call(context, msgs);
if (msgs) {
if (callback) {
callback.call(context, msgs);
}
if (Array.isArray(msgs)) {
result = result.concat(msgs);
} else {
result.push(msgs);
}
}
count++;
if (Array.isArray(msgs)) {
result.concat(msgs);
} else {
result.push(msgs);
}
if (count == query.ranges.length) {
resolve(result);
}
@@ -3726,9 +3728,10 @@ class MetaGetBuilder {
withLaterData(limit) {
return this.withData(this.topic._maxSeq > 0 ? this.topic._maxSeq + 1 : undefined, undefined, limit);
}
withDataRanges(ranges) {
withDataRanges(ranges, limit) {
this.what['data'] = {
ranges: (0,_utils__WEBPACK_IMPORTED_MODULE_0__.normalizeRanges)(ranges, this.topic._maxSeq)
ranges: (0,_utils__WEBPACK_IMPORTED_MODULE_0__.normalizeRanges)(ranges, this.topic._maxSeq),
limit: limit
};
return this;
}
@@ -4076,11 +4079,11 @@ class Topic {
getMeta(params) {
return this._tinode.getMeta(this.name, params);
}
getMessagesPage(limit, gaps, forward) {
console.log("getMessagesPage", gaps, forward);
let query = forward ? this.startMetaQuery().withLaterData(limit) : this.startMetaQuery().withEarlierData(limit);
getMessagesPage(limit, gaps, min, max, newer) {
let query = gaps ? this.startMetaQuery().withDataRanges(gaps, limit) : newer ? this.startMetaQuery().withData(min, undefined, limit) : this.startMetaQuery().withData(undefined, max, limit);
return this._loadMessages(this._tinode._db, query.extract('data')).then(count => {
if (count == limit) {
gaps = this.msgHasMoreMessages(min, max, newer);
if (gaps.length == 0) {
return Promise.resolve({
topic: this.name,
code: 200,
@@ -4090,16 +4093,8 @@ class Topic {
});
}
limit -= count;
query = forward ? this.startMetaQuery().withLaterData(limit) : this.startMetaQuery().withEarlierData(limit);
let promise = this.getMeta(query.build());
if (!forward) {
promise = promise.then(ctrl => {
if (ctrl && ctrl.params && !ctrl.params.count) {
this._noEarlierMsgs = true;
}
});
}
return promise;
query = this.startMetaQuery().withDataRanges(gaps, limit);
return this.getMeta(query.build());
});
}
getPinnedMessages() {
@@ -4565,7 +4560,6 @@ class Topic {
gaps.push(gap);
}
}
console.log("Gaps in cache found:", gaps, "min/max:", min, max, "haveMore:", gaps.length > 0);
return gaps;
}
isNewMessage(seqId) {
@@ -4994,6 +4988,7 @@ class Topic {
_loadMessages(db, query) {
query = query || {};
query.limit = query.limit || _config_js__WEBPACK_IMPORTED_MODULE_3__.DEFAULT_MESSAGES_PAGE;
let count = 0;
return db.readMessages(this.name, query).then(msgs => {
msgs.forEach(data => {
if (data.seq > this._maxSeq) {
@@ -5005,7 +5000,7 @@ class Topic {
this._messages.put(data);
this._maybeUpdateMessageVersionsCache(data);
});
return msgs.length;
count = msgs.length;
}).then(_ => db.readDelLog(this.name, query)).then(dellog => {
return dellog.forEach(rec => {
this._messages.put({
@@ -5016,7 +5011,7 @@ class Topic {
});
});
}).then(_ => {
this._messages.forEach(msg => console.log(msg));
return count;
});
}
_updateReceived(seq, act) {
@@ -5632,9 +5627,7 @@ class Tinode {
}
};
this._persist = config.persist;
this._db = new _db_js__WEBPACK_IMPORTED_MODULE_4__["default"](err => {
this.logger('DB', err);
}, this.logger);
this._db = new _db_js__WEBPACK_IMPORTED_MODULE_4__["default"](this.logger, this.logger);
if (this._persist) {
const prom = [];
this._db.initDatabase().then(_ => {
@@ -5654,7 +5647,6 @@ class Tinode {
this.#attachCacheToTopic(topic);
topic._cachePutSelf();
this._db.maxDelId(topic.name).then(clear => {
console.log("topic=", topic.name, "delID=", clear, "was", topic._maxDel);
topic._maxDel = Math.max(topic._maxDel, clear || 0);
});
delete topic._new;
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