Compare commits
No commits in common. "268a6546171c6b99a37f8e3af445af1b28dc438c" and "15cdf8033b46a0226e558e3f56e2c6f8c23ff1f7" have entirely different histories.
268a654617
...
15cdf8033b
1 changed files with 11 additions and 17 deletions
|
@ -14,10 +14,6 @@ class Store {
|
|||
this.name = name;
|
||||
}
|
||||
|
||||
log(...e) {
|
||||
return storeLog(`[${this.name}]`, ...e);
|
||||
}
|
||||
|
||||
// like subscribe, but without initially calling the handler
|
||||
watch(handler) {
|
||||
storeLog(`[Watch] (${this.name})`, "handler:", handler);
|
||||
|
@ -178,18 +174,13 @@ class MessageStore extends Store {
|
|||
}
|
||||
|
||||
_recomputeMessages() {
|
||||
const start = performance.now();
|
||||
for (let i = 0; i < this.value.length; i++) {
|
||||
this.value[i] = this._processMessage(this.value[i], this.value[i - 1]);
|
||||
}
|
||||
const delta = performance.now() - start;
|
||||
this.log(`[_recomputeMessages] Computed ${this.value.length} messages in ${delta}ms`);
|
||||
this.value = this.value.map((e, i) => this._processMessage(e, this.value[i - 1]));
|
||||
}
|
||||
|
||||
_processMessage(message, previous=null) {
|
||||
message._createdAtDate = message._createdAtDate || new Date(parseInt(message.created_at));
|
||||
message._createdAtTimeString = message._createdAtTimeString || new Intl.DateTimeFormat(getItem("ui:locale"), { hour: "numeric", minute: "numeric" }).format(message._createdAtDate);
|
||||
message._createdAtDateString = message._createdAtDateString || message._createdAtDate.toLocaleDateString();
|
||||
message._createdAtDate = new Date(parseInt(message.created_at));
|
||||
message._createdAtTimeString = new Intl.DateTimeFormat(getItem("ui:locale"), { hour: "numeric", minute: "numeric" }).format(message._createdAtDate);
|
||||
message._createdAtDateString = message._createdAtDate.toLocaleDateString();
|
||||
message._mentions = false;
|
||||
message._editable = false;
|
||||
message._clumped = false;
|
||||
|
@ -203,7 +194,7 @@ class MessageStore extends Store {
|
|||
if (previous && (message._createdAtDate.getTime() - previous._createdAtDate.getTime()) <= 100 * 1000 && message.author_id === previous.author_id) {
|
||||
message._clumped = true;
|
||||
}
|
||||
if (!previous || (previous._createdAtDateString !== message._createdAtDateString && !message._aboveDateMarker)) {
|
||||
if (previous && (previous._createdAtDateString !== message._createdAtDateString)) {
|
||||
message._aboveDateMarker = new Intl.DateTimeFormat(getItem("ui:locale"), { month: "long", day: "numeric", year: "numeric" }).format(message._createdAtDate);
|
||||
}
|
||||
return message;
|
||||
|
@ -271,11 +262,10 @@ class MessageStore extends Store {
|
|||
if (!this.isCollectingOldMessages)
|
||||
return false;
|
||||
|
||||
const target = 25;
|
||||
const target = 50;
|
||||
const delta = this.value.length - target;
|
||||
if (delta >= 1) {
|
||||
this.value.splice(0, delta);
|
||||
this._recomputeMessages();
|
||||
this.updated();
|
||||
return true;
|
||||
} else {
|
||||
|
@ -301,8 +291,12 @@ class MessageStore extends Store {
|
|||
if (beforeCommitToStore)
|
||||
beforeCommitToStore(res.json);
|
||||
res.json.reverse();
|
||||
for (let i = 0; i < res.json.length; i++) {
|
||||
const message = res.json[i];
|
||||
const previous = res.json[i - 1];
|
||||
res.json[i] = this._processMessage(message, previous);
|
||||
}
|
||||
this.value = res.json.concat(this.value);
|
||||
this._recomputeMessages();
|
||||
this.updated();
|
||||
} else {
|
||||
overlayStore.toast("Messages failed to load");
|
||||
|
|
Loading…
Reference in a new issue