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