1142 lines
34 KiB
TypeScript
1142 lines
34 KiB
TypeScript
// Metro module 4860 (f4861).
|
|
import { MAX_LOADED_MESSAGES, MAX_MESSAGES_PER_CHANNEL, MAX_MESSAGE_CACHE_SIZE, MessageStates, TRUNCATED_MESSAGE_VIEW_SIZE } from "../Constants";
|
|
import Logger from "../modules/debug/Logger";
|
|
import { createMessageRecord } from "../modules/messages/MessageRecordUtils";
|
|
import Module12 from "../_bundle/Module12";
|
|
import { JumpType } from "../flow/Client";
|
|
import SnowflakeUtils from "../utils/SnowflakeUtils";
|
|
import EnsureReceivedMessagesAddedInOrderExperiment from "./EnsureReceivedMessagesAddedInOrderExperiment";
|
|
import { insert } from "../utils/SortedArrayUtils";
|
|
import * as _IOSPushNotificationRawPayloadFixExperiment from "../modules/notifications/IOSPushNotificationRawPayloadFixExperiment";
|
|
import { requireSortedDescending } from "../modules/app_database/modules/messages/requireSortedDescending";
|
|
import { HermesBuiltin } from "../_hermes/prelude";
|
|
let c2993_9;
|
|
const mergeMessage = function mergeMessage(a0, a1) {
|
|
let r15 = a0.get(a1.id);
|
|
if (r15 != null) {
|
|
const r0 = r15.editedTimestamp != null ? +r15.editedTimestamp : 0;
|
|
const r1 = a1.edited_timestamp != null ? +new Date(a1.edited_timestamp) : 0;
|
|
let r23 = r1 > r0;
|
|
if (!(r0 < r1)) {
|
|
const length2 = r15.embeds.length;
|
|
let r27 = a1.embeds?.length;
|
|
if (r27 == null) {
|
|
r27 = 0;
|
|
}
|
|
r23 = length2 < r27;
|
|
}
|
|
if (!r23) {
|
|
r23 = r15.content !== a1.content;
|
|
}
|
|
if (!(!r23 && !a0.cached)) {
|
|
r15 = createMessageRecord(a1);
|
|
}
|
|
} else {
|
|
r15 = createMessageRecord(a1);
|
|
}
|
|
return r15;
|
|
};
|
|
c2993_9 = new Logger("ChannelMessages");
|
|
class MessageCache {
|
|
_messages = [];
|
|
_map = {};
|
|
_wasAtEdge = false;
|
|
constructor(a0) {
|
|
this._isCacheBefore = a0;
|
|
}
|
|
clone() {
|
|
const _isCacheBefore = this._isCacheBefore;
|
|
const r12 = {
|
|
__proto__: MessageCache.prototype
|
|
};
|
|
r12._messages = [];
|
|
r12._map = {};
|
|
r12._wasAtEdge = false;
|
|
r12._isCacheBefore = _isCacheBefore;
|
|
r12._map = {
|
|
...this._map
|
|
};
|
|
r12._messages = [...this._messages];
|
|
r12._wasAtEdge = this._wasAtEdge;
|
|
return r12;
|
|
}
|
|
get wasAtEdge() {
|
|
return this._wasAtEdge;
|
|
}
|
|
set wasAtEdge(a0) {
|
|
this._wasAtEdge = a0;
|
|
}
|
|
get length() {
|
|
return this._messages.length;
|
|
}
|
|
clear() {
|
|
this._map = {};
|
|
this._messages = [];
|
|
this._wasAtEdge = false;
|
|
}
|
|
remove(a0) {
|
|
let c14456_0 = a0;
|
|
this._messages = Module12.filter(this._messages, (a0) => a0.id !== c14456_0);
|
|
delete this._map[a0];
|
|
}
|
|
removeMany(a0) {
|
|
let c14457_0 = a0;
|
|
Module12.each(a0, (a0) => {
|
|
delete this._map[a0];
|
|
});
|
|
this._messages = this._messages.filter((_message) => c14457_0.indexOf(_message.id) === -1);
|
|
}
|
|
replace(a0, a1) {
|
|
const r5 = this._map[a0];
|
|
if (r5 != null) {
|
|
delete this._map[a0];
|
|
this._map[a1.id] = a1;
|
|
this._messages[this._messages.indexOf(r5)] = a1;
|
|
}
|
|
}
|
|
update(a0, a1) {
|
|
const r5 = this._map[a0];
|
|
if (r5 != null) {
|
|
const r8 = a1(r5);
|
|
this._map[r5.id] = r8;
|
|
this._messages[this._messages.indexOf(r5)] = r8;
|
|
}
|
|
}
|
|
has(a0) {
|
|
return this._map[a0] != null;
|
|
}
|
|
get(a0) {
|
|
return this._map[a0];
|
|
}
|
|
forEach(a0, a1) {
|
|
this._messages.forEach(a0, a1);
|
|
}
|
|
cache(a0, _wasAtEdge = false) {
|
|
let _messages2;
|
|
if (this.length === 0) {
|
|
this._wasAtEdge = _wasAtEdge;
|
|
}
|
|
if (this._messages.length + a0.length > MAX_MESSAGE_CACHE_SIZE) {
|
|
this._wasAtEdge = false;
|
|
if (a0.length > MAX_MESSAGE_CACHE_SIZE) {
|
|
const _isCacheBefore3 = this._isCacheBefore;
|
|
const slice = a0.slice;
|
|
if (_isCacheBefore3) {
|
|
this._messages = slice.call(a0, a0.length - MAX_MESSAGE_CACHE_SIZE);
|
|
} else {
|
|
this._messages = slice.call(a0, 0, MAX_MESSAGE_CACHE_SIZE);
|
|
}
|
|
this._map = {};
|
|
this._messages.forEach((_message) => {
|
|
this._map[_message.id] = _message;
|
|
return _message;
|
|
});
|
|
return void 0;
|
|
}
|
|
const r13 = MAX_MESSAGE_CACHE_SIZE - a0.length;
|
|
const _isCacheBefore = this._isCacheBefore;
|
|
const _messages = this._messages;
|
|
if (_isCacheBefore) {
|
|
this._messages = _messages.slice(Math.max(this._messages.length - r13, 0));
|
|
} else {
|
|
this._messages = _messages.slice(0, r13);
|
|
}
|
|
}
|
|
const _isCacheBefore2 = this._isCacheBefore;
|
|
const r34 = [];
|
|
if (_isCacheBefore2) {
|
|
HermesBuiltin.arraySpread(r34, a0, HermesBuiltin.arraySpread(r34, this._messages, 0));
|
|
_messages2 = r34;
|
|
} else {
|
|
HermesBuiltin.arraySpread(r34, this._messages, HermesBuiltin.arraySpread(r34, a0, 0));
|
|
_messages2 = r34;
|
|
}
|
|
this._messages = _messages2;
|
|
this._map = {};
|
|
this._messages.forEach((_message) => {
|
|
this._map[_message.id] = _message;
|
|
return _message;
|
|
});
|
|
}
|
|
extractAll() {
|
|
const _messages = this._messages;
|
|
this._messages = [];
|
|
this._map = {};
|
|
return _messages;
|
|
}
|
|
extract(a0) {
|
|
let r12;
|
|
const _isCacheBefore = this._isCacheBefore;
|
|
const r6 = Math;
|
|
if (_isCacheBefore) {
|
|
const r20 = r6.max(this.length - a0, 0);
|
|
r12 = this._messages.slice(r20, this.length);
|
|
this._messages.splice(r20);
|
|
} else {
|
|
r12 = this._messages.slice(0, r6.min(a0, this.length));
|
|
this._messages.splice(0, a0);
|
|
}
|
|
r12.forEach((item) => delete this._map[item.id]);
|
|
return r12;
|
|
}
|
|
}
|
|
class ChannelMessages {
|
|
static _channelMessages = {};
|
|
constructor(a0) {
|
|
const r12 = {
|
|
__proto__: new.target.prototype,
|
|
ready: false,
|
|
cached: false,
|
|
jumpType: JumpType.ANIMATED,
|
|
jumpTargetId: null,
|
|
jumpTargetOffset: 0,
|
|
jumpSequenceId: 1,
|
|
jumped: false,
|
|
jumpedToPresent: false,
|
|
jumpFlash: true,
|
|
jumpReturnTargetId: null,
|
|
onJumpComplete: null,
|
|
focusTargetId: null,
|
|
focusSequenceId: 1,
|
|
initialScrollSequenceId: 0,
|
|
suppressRowAnimationSequenceId: 0,
|
|
hasMoreBefore: true,
|
|
hasMoreAfter: false,
|
|
loadingMore: false,
|
|
revealedMessageId: null,
|
|
hasFetched: false,
|
|
error: false,
|
|
_array: null,
|
|
_before: null,
|
|
_after: null,
|
|
_map: null
|
|
};
|
|
r12._array = [];
|
|
const _before = {
|
|
__proto__: MessageCache.prototype
|
|
};
|
|
_before._messages = [];
|
|
_before._map = {};
|
|
_before._wasAtEdge = false;
|
|
_before._isCacheBefore = true;
|
|
r12._before = _before;
|
|
const _after = {
|
|
__proto__: MessageCache.prototype
|
|
};
|
|
_after._messages = [];
|
|
_after._map = {};
|
|
_after._wasAtEdge = false;
|
|
_after._isCacheBefore = false;
|
|
r12._after = _after;
|
|
r12._map = {};
|
|
r12.channelId = a0;
|
|
return r12;
|
|
}
|
|
static forEach(a0) {
|
|
Module12.forEach(ChannelMessages._channelMessages, a0);
|
|
}
|
|
static get(a0) {
|
|
return ChannelMessages._channelMessages[a0];
|
|
}
|
|
static hasPresent(a0) {
|
|
const r5 = ChannelMessages.get(a0);
|
|
return r5 != null && r5.hasPresent();
|
|
}
|
|
static getOrCreate(a0) {
|
|
let r10 = ChannelMessages._channelMessages[a0];
|
|
if (r10 == null) {
|
|
const r18 = {
|
|
__proto__: ChannelMessages.prototype,
|
|
ready: false,
|
|
cached: false,
|
|
jumpType: JumpType.ANIMATED,
|
|
jumpTargetId: null,
|
|
jumpTargetOffset: 0,
|
|
jumpSequenceId: 1,
|
|
jumped: false,
|
|
jumpedToPresent: false,
|
|
jumpFlash: true,
|
|
jumpReturnTargetId: null,
|
|
onJumpComplete: null,
|
|
focusTargetId: null,
|
|
focusSequenceId: 1,
|
|
initialScrollSequenceId: 0,
|
|
suppressRowAnimationSequenceId: 0,
|
|
hasMoreBefore: true,
|
|
hasMoreAfter: false,
|
|
loadingMore: false,
|
|
revealedMessageId: null,
|
|
hasFetched: false,
|
|
error: false,
|
|
_array: null,
|
|
_before: null,
|
|
_after: null,
|
|
_map: null
|
|
};
|
|
r18._array = [];
|
|
const _before = {
|
|
__proto__: MessageCache.prototype
|
|
};
|
|
_before._messages = [];
|
|
_before._map = {};
|
|
_before._wasAtEdge = false;
|
|
_before._isCacheBefore = true;
|
|
r18._before = _before;
|
|
const _after = {
|
|
__proto__: MessageCache.prototype
|
|
};
|
|
_after._messages = [];
|
|
_after._map = {};
|
|
_after._wasAtEdge = false;
|
|
_after._isCacheBefore = false;
|
|
r18._after = _after;
|
|
r18._map = {};
|
|
r18.channelId = a0;
|
|
ChannelMessages._channelMessages[a0] = r18;
|
|
r10 = r18;
|
|
}
|
|
return r10;
|
|
}
|
|
static clear(a0) {
|
|
delete ChannelMessages._channelMessages[a0];
|
|
}
|
|
static clearCache(a0) {
|
|
const r3 = ChannelMessages._channelMessages[a0];
|
|
if (r3 != null) {
|
|
r3._before.clear();
|
|
r3._after.clear();
|
|
this.commit(r3);
|
|
}
|
|
}
|
|
static commit(a0) {
|
|
ChannelMessages._channelMessages[a0.channelId] = a0;
|
|
}
|
|
mutate(a0, r5 = false) {
|
|
const channelId = this.channelId;
|
|
const r21 = {
|
|
__proto__: ChannelMessages.prototype,
|
|
ready: false,
|
|
cached: false,
|
|
jumpType: JumpType.ANIMATED,
|
|
jumpTargetId: null,
|
|
jumpTargetOffset: 0,
|
|
jumpSequenceId: 1,
|
|
jumped: false,
|
|
jumpedToPresent: false,
|
|
jumpFlash: true,
|
|
jumpReturnTargetId: null,
|
|
onJumpComplete: null,
|
|
focusTargetId: null,
|
|
focusSequenceId: 1,
|
|
initialScrollSequenceId: 0,
|
|
suppressRowAnimationSequenceId: 0,
|
|
hasMoreBefore: true,
|
|
hasMoreAfter: false,
|
|
loadingMore: false,
|
|
revealedMessageId: null,
|
|
hasFetched: false,
|
|
error: false,
|
|
_array: null,
|
|
_before: null,
|
|
_after: null,
|
|
_map: null
|
|
};
|
|
r21._array = [];
|
|
const _before2 = {
|
|
__proto__: MessageCache.prototype
|
|
};
|
|
_before2._messages = [];
|
|
_before2._map = {};
|
|
_before2._wasAtEdge = false;
|
|
_before2._isCacheBefore = true;
|
|
r21._before = _before2;
|
|
const _after2 = {
|
|
__proto__: MessageCache.prototype
|
|
};
|
|
_after2._messages = [];
|
|
_after2._map = {};
|
|
_after2._wasAtEdge = false;
|
|
_after2._isCacheBefore = false;
|
|
r21._after = _after2;
|
|
r21._map = {};
|
|
r21.channelId = channelId;
|
|
const _array2 = this._array;
|
|
r21._array = r5 ? [..._array2] : _array2;
|
|
const _map = this._map;
|
|
r21._map = r5 ? {
|
|
..._map
|
|
} : _map;
|
|
const _after = this._after;
|
|
r21._after = r5 ? _after.clone() : _after;
|
|
const _before = this._before;
|
|
r21._before = r5 ? _before.clone() : _before;
|
|
if (a0 instanceof Function) {
|
|
r21.ready = this.ready;
|
|
r21.jumpType = this.jumpType;
|
|
r21.jumpTargetId = this.jumpTargetId;
|
|
r21.jumpTargetOffset = this.jumpTargetOffset;
|
|
r21.jumpSequenceId = this.jumpSequenceId;
|
|
r21.jumped = this.jumped;
|
|
r21.jumpedToPresent = this.jumpedToPresent;
|
|
r21.jumpFlash = this.jumpFlash;
|
|
r21.jumpReturnTargetId = this.jumpReturnTargetId;
|
|
r21.onJumpComplete = this.onJumpComplete;
|
|
r21.focusTargetId = this.focusTargetId;
|
|
r21.focusSequenceId = this.focusSequenceId;
|
|
r21.hasMoreBefore = this.hasMoreBefore;
|
|
r21.hasMoreAfter = this.hasMoreAfter;
|
|
r21.loadingMore = this.loadingMore;
|
|
r21.revealedMessageId = this.revealedMessageId;
|
|
r21.cached = this.cached;
|
|
r21.hasFetched = this.hasFetched;
|
|
r21.error = this.error;
|
|
r21.initialScrollSequenceId = this.initialScrollSequenceId;
|
|
r21.suppressRowAnimationSequenceId = this.suppressRowAnimationSequenceId;
|
|
a0(r21);
|
|
} else if (typeof a0 === "object") {
|
|
r21.ready = a0.ready !== void 0 ? a0.ready === true : this.ready;
|
|
r21.jumpType = a0.jumpType !== void 0 ? a0.jumpType : this.jumpType;
|
|
r21.jumpTargetId = a0.jumpTargetId !== void 0 ? a0.jumpTargetId : this.jumpTargetId;
|
|
r21.jumpTargetOffset = a0.jumpTargetOffset !== void 0 ? a0.jumpTargetOffset : this.jumpTargetOffset;
|
|
r21.jumpSequenceId = a0.jumpSequenceId !== void 0 ? a0.jumpSequenceId : this.jumpSequenceId;
|
|
r21.jumped = a0.jumped !== void 0 ? a0.jumped === true : this.jumped;
|
|
r21.jumpedToPresent = a0.jumpedToPresent !== void 0 ? a0.jumpedToPresent === true : this.jumpedToPresent;
|
|
r21.jumpFlash = a0.jumpFlash !== void 0 ? a0.jumpFlash === true : this.jumpFlash;
|
|
r21.jumpReturnTargetId = a0.jumpReturnTargetId !== void 0 ? a0.jumpReturnTargetId : this.jumpReturnTargetId;
|
|
r21.focusTargetId = a0.focusTargetId !== void 0 ? a0.focusTargetId : this.focusTargetId;
|
|
r21.focusSequenceId = a0.focusSequenceId !== void 0 ? a0.focusSequenceId : this.focusSequenceId;
|
|
r21.hasMoreBefore = a0.hasMoreBefore !== void 0 ? a0.hasMoreBefore === true : this.hasMoreBefore;
|
|
r21.hasMoreAfter = a0.hasMoreAfter !== void 0 ? a0.hasMoreAfter === true : this.hasMoreAfter;
|
|
r21.loadingMore = a0.loadingMore !== void 0 ? a0.loadingMore : this.loadingMore;
|
|
r21.revealedMessageId = a0.revealedMessageId !== void 0 ? a0.revealedMessageId : this.revealedMessageId;
|
|
r21.cached = a0.cached !== void 0 ? a0.cached : this.cached;
|
|
r21.hasFetched = a0.hasFetched !== void 0 ? a0.hasFetched : this.hasFetched;
|
|
r21.error = a0.error !== void 0 ? a0.error : this.error;
|
|
r21.onJumpComplete = a0.onJumpComplete !== void 0 ? a0.onJumpComplete : this.onJumpComplete;
|
|
r21.initialScrollSequenceId = a0.initialScrollSequenceId !== void 0 ? a0.initialScrollSequenceId : this.initialScrollSequenceId;
|
|
r21.suppressRowAnimationSequenceId = a0.suppressRowAnimationSequenceId !== void 0 ? a0.suppressRowAnimationSequenceId : this.suppressRowAnimationSequenceId;
|
|
}
|
|
return r21;
|
|
}
|
|
get length() {
|
|
return this._array.length;
|
|
}
|
|
toArray() {
|
|
return [...this._array];
|
|
}
|
|
forEach(a0, a1, r6 = false) {
|
|
let r19;
|
|
const _array2 = this._array;
|
|
if (r6) {
|
|
let r0 = _array2.length - 1;
|
|
if (0 <= r0 && a0.call(a1, _array2[r0], r0) !== false) {
|
|
do {
|
|
const r1 = r0 - 1;
|
|
if (!(0 <= r1)) {
|
|
break;
|
|
}
|
|
r19 = a0.call(a1, _array2[r1], r1);
|
|
r0 = r1;
|
|
} while (r19 !== false);
|
|
}
|
|
} else {
|
|
_array2.forEach(a0, a1);
|
|
}
|
|
}
|
|
reduce(a0, a1) {
|
|
return this._array.reduce(a0, a1);
|
|
}
|
|
some(a0, a1) {
|
|
return this._array.some(a0, a1);
|
|
}
|
|
filter(a0, a1) {
|
|
return this._array.filter(a0, a1);
|
|
}
|
|
forAll(a0, a1) {
|
|
this._before.forEach(a0, a1);
|
|
this._array.forEach(a0, a1);
|
|
this._after.forEach(a0, a1);
|
|
}
|
|
findOldest(a0) {
|
|
let r13 = Module12.find(this._before._messages, a0);
|
|
if (r13 == null) {
|
|
r13 = Module12.find(this._array, a0);
|
|
}
|
|
if (r13 == null) {
|
|
r13 = Module12.find(this._after._messages, a0);
|
|
}
|
|
return r13;
|
|
}
|
|
findNewest(a0) {
|
|
let r13 = Module12.findLast(this._after._messages, a0);
|
|
if (r13 == null) {
|
|
r13 = Module12.findLast(this._array, a0);
|
|
}
|
|
if (r13 == null) {
|
|
r13 = Module12.findLast(this._before._messages, a0);
|
|
}
|
|
return r13;
|
|
}
|
|
map(a0, a1) {
|
|
return this._array.map(a0, a1);
|
|
}
|
|
first() {
|
|
return this._array[0];
|
|
}
|
|
last() {
|
|
return this._array[this._array.length - 1];
|
|
}
|
|
get(a0, r2 = false) {
|
|
const r4 = this._map[a0];
|
|
let r7 = r4;
|
|
if (r4 == null) {
|
|
r7 = r4;
|
|
if (r2) {
|
|
let r10 = this._before.get(a0);
|
|
if (r10 == null) {
|
|
r10 = this._after.get(a0);
|
|
}
|
|
r7 = r10;
|
|
}
|
|
}
|
|
return r7;
|
|
}
|
|
getByIndex(a0) {
|
|
return this._array[a0];
|
|
}
|
|
getAfter(a0) {
|
|
const r6 = this.get(a0);
|
|
if (r6 == null) {
|
|
return null;
|
|
}
|
|
const r9 = this._array.indexOf(r6);
|
|
return r9 !== -1 ? r9 !== this.length - 1 ? this._array[r9 + 1] : null : null;
|
|
}
|
|
getManyAfter(a0, a1, a2) {
|
|
let r16;
|
|
const r7 = this.get(a0);
|
|
if (r7 == null) {
|
|
return null;
|
|
}
|
|
const r15 = this._array.indexOf(r7);
|
|
if (r15 === -1) {
|
|
return null;
|
|
}
|
|
L12: {
|
|
r16 = [];
|
|
const r11 = r15 + 1;
|
|
if (r11 < this.length) {
|
|
const r4 = a1 === -1;
|
|
let r18 = r11;
|
|
if (!r4) {
|
|
const length2 = r16.length;
|
|
r18 = r11;
|
|
if (!(length2 < a1)) {
|
|
break L12;
|
|
}
|
|
}
|
|
while (true) {
|
|
let r20 = a2 == null;
|
|
const r21 = r18;
|
|
if (!r20) {
|
|
r20 = a2(this._array[r21]);
|
|
}
|
|
if (r20) {
|
|
r16.push(this._array[r21]);
|
|
}
|
|
const r27 = r21 + 1;
|
|
if (!(r27 < this.length)) {
|
|
break;
|
|
}
|
|
r18 = r27;
|
|
if (!r4) {
|
|
const length3 = r16.length;
|
|
r18 = r27;
|
|
if (!(length3 < a1)) {
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return r16;
|
|
}
|
|
getManyBefore(a0, a1, a2) {
|
|
let r16;
|
|
const r9 = this.get(a0);
|
|
if (r9 == null) {
|
|
return null;
|
|
}
|
|
const r15 = this._array.indexOf(r9);
|
|
if (r15 === -1) {
|
|
return null;
|
|
}
|
|
L12: {
|
|
r16 = [];
|
|
const r1 = r15 - 1;
|
|
if (0 <= r1) {
|
|
const r6 = a1 === -1;
|
|
let r18 = r1;
|
|
if (!r6) {
|
|
const length2 = r16.length;
|
|
r18 = r1;
|
|
if (!(length2 < a1)) {
|
|
break L12;
|
|
}
|
|
}
|
|
while (true) {
|
|
let r20 = a2 == null;
|
|
const r21 = r18;
|
|
if (!r20) {
|
|
r20 = a2(this._array[r21]);
|
|
}
|
|
if (r20) {
|
|
r16.unshift(this._array[r21]);
|
|
}
|
|
const r27 = r21 - 1;
|
|
if (!(0 <= r27)) {
|
|
break;
|
|
}
|
|
r18 = r27;
|
|
if (!r6) {
|
|
const length3 = r16.length;
|
|
r18 = r27;
|
|
if (!(length3 < a1)) {
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return r16;
|
|
}
|
|
hasAnyAfter(a0, a1, r8 = -1) {
|
|
const r6 = this.get(a0);
|
|
if (r6 == null) {
|
|
return false;
|
|
}
|
|
const r13 = this._array.indexOf(r6);
|
|
if (r13 === -1) {
|
|
return false;
|
|
}
|
|
L11: {
|
|
const r10 = r13 + 1;
|
|
if (r10 < this.length) {
|
|
const r15 = r8 === -1;
|
|
let r16 = r10;
|
|
if (!r15) {
|
|
const r17 = r13 + r8;
|
|
r16 = r10;
|
|
if (!(r16 <= r17)) {
|
|
break L11;
|
|
}
|
|
}
|
|
while (true) {
|
|
const r20 = a1(this._array[r16]);
|
|
const r21 = r16;
|
|
if (r20) {
|
|
return true;
|
|
}
|
|
const r22 = r21 + 1;
|
|
if (!(r22 < this.length)) {
|
|
break;
|
|
}
|
|
r16 = r22;
|
|
if (!r15) {
|
|
const r24 = r13 + r8;
|
|
r16 = r22;
|
|
if (!(r16 <= r24)) {
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
has(a0, r2 = true) {
|
|
let r9 = this._map[a0] != null;
|
|
if (!r9) {
|
|
if (r2) {
|
|
r2 = this._before.has(a0) || this._after.has(a0);
|
|
}
|
|
r9 = r2;
|
|
}
|
|
return r9;
|
|
}
|
|
indexOf(c14460_0) {
|
|
let c14460_1 = -1;
|
|
this._array.find((item, index) => {
|
|
let r0 = item.id === c14460_0;
|
|
if (r0) {
|
|
c14460_1 = index;
|
|
r0 = true;
|
|
}
|
|
return r0;
|
|
});
|
|
return c14460_1;
|
|
}
|
|
hasPresent() {
|
|
return this._after.length > 0 && this._after.wasAtEdge || !this.hasMoreAfter;
|
|
}
|
|
hasBeforeCached(a0) {
|
|
if (this.length > 0 && this._before.length > 0) {
|
|
const r8 = this.first();
|
|
return r8 != null && r8.id === a0;
|
|
}
|
|
return false;
|
|
}
|
|
hasAfterCached(a0) {
|
|
if (this.length > 0 && this._after.length > 0) {
|
|
const r8 = this.last();
|
|
return r8 != null && r8.id === a0;
|
|
}
|
|
return false;
|
|
}
|
|
update(a0, a1) {
|
|
let c14461_3;
|
|
let c14461_0 = a0;
|
|
const r6 = this._map[a0];
|
|
let c14461_2 = r6;
|
|
if (r6 == null) {
|
|
return this._before.has(a0) ? this.mutate((a0) => a0._before.update(c14461_0, a1), true) : this._after.has(a0) ? this.mutate((a0) => a0._after.update(c14461_0, a1), true) : this;
|
|
}
|
|
c14461_3 = a1(r6);
|
|
return this.mutate((a0) => {
|
|
const _map = a0._map;
|
|
const id = c14461_2.id;
|
|
_map[id] = c14461_3;
|
|
a0._array[a0._array.indexOf(c14461_2)] = c14461_3;
|
|
}, true);
|
|
}
|
|
replace(a0, c14462_1) {
|
|
let c14462_0 = a0;
|
|
const r8 = this._map[a0];
|
|
let c14462_2 = r8;
|
|
return r8 == null ? this._before.has(a0) ? this.mutate((a0) => a0._before.replace(c14462_0, c14462_1), true) : this._after.has(a0) ? this.mutate((a0) => a0._after.replace(c14462_0, c14462_1), true) : this : this.mutate((a0) => {
|
|
delete a0._map[c14462_0];
|
|
const _map = a0._map;
|
|
_map[c14462_1.id] = c14462_1;
|
|
a0._array[a0._array.indexOf(c14462_2)] = c14462_1;
|
|
}, true);
|
|
}
|
|
remove(c14463_0) {
|
|
return this.mutate((a0) => {
|
|
const _map = a0._map;
|
|
delete _map[c14463_0];
|
|
a0._array = a0._array.filter((item) => item.id !== c14463_0);
|
|
a0._before.remove(c14463_0);
|
|
a0._after.remove(c14463_0);
|
|
}, true);
|
|
}
|
|
removeMany(a0) {
|
|
let c14464_0 = a0;
|
|
return a0.some((item) => this.has(item)) ? this.mutate((a0) => {
|
|
let c25299_0 = a0;
|
|
Module12.each(c14464_0, (a0) => {
|
|
delete c25299_0._map[a0];
|
|
});
|
|
a0._array = a0._array.filter((item) => c14464_0.indexOf(item.id) === -1);
|
|
a0._before.removeMany(c14464_0);
|
|
a0._after.removeMany(c14464_0);
|
|
}, true) : this;
|
|
}
|
|
merge(c14465_0, r5 = false) {
|
|
let c14465_1 = r5;
|
|
let r6 = arguments[2];
|
|
if (r6 === void 0) {
|
|
r6 = false;
|
|
}
|
|
let c14465_2 = r6;
|
|
return this.mutate((a0) => {
|
|
a0._merge(c14465_0, c14465_1, c14465_2);
|
|
}, true);
|
|
}
|
|
_merge(a0, r4 = false, r6 = false) {
|
|
let _array2;
|
|
const r14 = a0.filter((item) => {
|
|
const r6 = this._map[item.id];
|
|
this._map[item.id] = item;
|
|
let r10 = r6 == null;
|
|
if (!r10) {
|
|
this._array[this._array.indexOf(r6)] = item;
|
|
r10 = false;
|
|
}
|
|
return r10;
|
|
});
|
|
if (r6) {
|
|
(r4 ? this._before : this._after).clear();
|
|
}
|
|
const r18 = [];
|
|
if (r4) {
|
|
HermesBuiltin.arraySpread(r18, this._array, HermesBuiltin.arraySpread(r18, r14, 0));
|
|
_array2 = r18;
|
|
} else {
|
|
HermesBuiltin.arraySpread(r18, r14, HermesBuiltin.arraySpread(r18, this._array, 0));
|
|
_array2 = r18;
|
|
}
|
|
this._array = _array2;
|
|
}
|
|
mergeDelta(r2 = []) {
|
|
let c14467_0 = r2;
|
|
let r4 = arguments[1];
|
|
if (r4 === void 0) {
|
|
r4 = [];
|
|
}
|
|
let c14467_1 = r4;
|
|
let r5 = arguments[2];
|
|
if (r5 === void 0) {
|
|
r5 = [];
|
|
}
|
|
let c14467_2 = r5;
|
|
return this.mutate((a0) => {
|
|
a0._before.clear();
|
|
a0._after.clear();
|
|
let c25300_0 = new Set(c14467_2);
|
|
c14467_0.forEach((item) => c25300_0.add(item.id));
|
|
c14467_1.forEach((item) => c25300_0.add(item.id));
|
|
a0._array = a0._array.filter((item) => !c25300_0.has(item.id)).concat(c14467_0.map((item) => createMessageRecord(item)), c14467_1.map((item) => createMessageRecord(item))).sort((a, b) => SnowflakeUtils.compare(a.id, b.id));
|
|
});
|
|
}
|
|
_clearMessages() {
|
|
this._array = [];
|
|
this._map = {};
|
|
}
|
|
reset(_array) {
|
|
return this.mutate((a0) => {
|
|
a0._array = _array;
|
|
a0._map = {};
|
|
_array.forEach((item) => {
|
|
a0._map[item.id] = item;
|
|
return item;
|
|
});
|
|
a0._before.clear();
|
|
a0._after.clear();
|
|
});
|
|
}
|
|
truncateTop(a0, r7 = true) {
|
|
const r9 = this._array.length - a0;
|
|
let c14469_0 = r9;
|
|
return r9 <= 0 ? this : this.mutate((a0) => {
|
|
let r8 = c14469_0;
|
|
let r0 = 0;
|
|
while (r0 < r8) {
|
|
delete a0._map[a0._array[r0].id];
|
|
r0 = r0 + 1;
|
|
r8 = c14469_0;
|
|
}
|
|
a0._before.cache(a0._array.slice(0, r8), !a0.hasMoreBefore);
|
|
a0._array = a0._array.slice(r8);
|
|
a0.hasMoreBefore = true;
|
|
}, r7);
|
|
}
|
|
truncateBottom(a0) {
|
|
return this;
|
|
}
|
|
jumpToPresent(c14470_0) {
|
|
return this.mutate((a0) => {
|
|
const r8 = a0._after.extractAll();
|
|
a0.hasMoreAfter = false;
|
|
const r15 = Math.max(r8.length - c14470_0, 0);
|
|
const r17 = r8.slice(r15);
|
|
r8.splice(r15);
|
|
a0._before.cache(a0._array);
|
|
a0._before.cache(r8);
|
|
a0._clearMessages();
|
|
a0._merge(r17);
|
|
a0.hasMoreBefore = a0._before.length > 0;
|
|
a0.jumped = true;
|
|
a0.jumpTargetId = null;
|
|
a0.jumpTargetOffset = 0;
|
|
a0.jumpedToPresent = true;
|
|
a0.jumpFlash = false;
|
|
a0.jumpReturnTargetId = null;
|
|
a0.jumpSequenceId = a0.jumpSequenceId + 1;
|
|
a0.onJumpComplete = null;
|
|
a0.ready = true;
|
|
a0.loadingMore = false;
|
|
}, true);
|
|
}
|
|
jumpToMessage(a0) {
|
|
const { messageId, flash = true } = a0;
|
|
const jumpFlash = flash;
|
|
const { offset, returnTargetId = null } = a0;
|
|
const jumpReturnTargetId = returnTargetId;
|
|
const { jumpType, onJumpComplete } = a0;
|
|
return this.mutate((a0) => {
|
|
a0.jumped = true;
|
|
a0.jumpedToPresent = false;
|
|
let jumpType2 = jumpType;
|
|
if (jumpType == null) {
|
|
jumpType2 = JumpType.ANIMATED;
|
|
}
|
|
a0.jumpType = jumpType2;
|
|
a0.jumpTargetId = messageId;
|
|
a0.jumpTargetOffset = messageId != null ? offset != null ? offset : 0 : 0;
|
|
a0.jumpSequenceId = a0.jumpSequenceId + 1;
|
|
let onJumpComplete2 = onJumpComplete;
|
|
if (onJumpComplete == null) {
|
|
onJumpComplete2 = null;
|
|
}
|
|
a0.onJumpComplete = onJumpComplete2;
|
|
a0.jumpFlash = jumpFlash;
|
|
a0.jumpReturnTargetId = jumpReturnTargetId;
|
|
a0.ready = true;
|
|
a0.loadingMore = false;
|
|
}, false);
|
|
}
|
|
focusOnMessage(focusTargetId) {
|
|
return this.mutate((a0) => {
|
|
a0.focusTargetId = focusTargetId;
|
|
a0.focusSequenceId = a0.focusSequenceId + 1;
|
|
a0.ready = true;
|
|
a0.loadingMore = false;
|
|
}, false);
|
|
}
|
|
loadFromCache(c14473_0, c14473_1) {
|
|
return this.mutate((a0) => {
|
|
const r5 = c14473_0 ? a0._before : a0._after;
|
|
a0._merge(r5.extract(c14473_1), c14473_0);
|
|
const hasMoreBefore = r5.length > 0 || !r5.wasAtEdge;
|
|
if (c14473_0) {
|
|
a0.hasMoreBefore = hasMoreBefore;
|
|
} else {
|
|
a0.hasMoreAfter = hasMoreBefore;
|
|
}
|
|
a0.ready = true;
|
|
a0.loadingMore = false;
|
|
}, true);
|
|
}
|
|
truncate(a0, a1) {
|
|
return this.length <= MAX_LOADED_MESSAGES ? this : a0 ? this.truncateBottom(TRUNCATED_MESSAGE_VIEW_SIZE) : a1 ? this.truncateTop(TRUNCATED_MESSAGE_VIEW_SIZE) : this;
|
|
}
|
|
receiveMessage(a0, r8 = true) {
|
|
const r17 = a0.nonce == null ? null : this.get(a0.nonce, true);
|
|
L14: {
|
|
if (r17 != null) {
|
|
if (a0.author?.id !== r17.author?.id) {
|
|
if (a0.interaction == null) {
|
|
break L14;
|
|
}
|
|
if (a0.interaction.user.id !== r17.author.id) {
|
|
break L14;
|
|
}
|
|
}
|
|
if (a0.nonce != null && r17.id === a0.nonce) {
|
|
const messageRecord2 = createMessageRecord(a0);
|
|
if (r17.interactionData != null) {
|
|
messageRecord2.interactionData = r17.interactionData;
|
|
}
|
|
return this.replace(a0.nonce, messageRecord2);
|
|
}
|
|
}
|
|
}
|
|
if (this.hasMoreAfter) {
|
|
if (this._after.wasAtEdge) {
|
|
this._after.wasAtEdge = false;
|
|
}
|
|
return this;
|
|
}
|
|
const messageRecord = createMessageRecord(a0);
|
|
const r13 = this.last();
|
|
const r53 = r13 != null && (SnowflakeUtils.compare(a0.id, r13.id) < 0 && EnsureReceivedMessagesAddedInOrderExperiment.getConfig({
|
|
location: "receiveMessage"
|
|
}).enabled) ? this.mutate((a0) => {
|
|
const r5 = a0._map[messageRecord.id];
|
|
a0._map[messageRecord.id] = messageRecord;
|
|
if (r5 != null) {
|
|
a0._array[a0._array.indexOf(r5)] = messageRecord;
|
|
} else {
|
|
insert(a0._array, messageRecord, (a0, a1) => SnowflakeUtils.compare(a0.id, a1.id));
|
|
}
|
|
}, true) : this.merge([messageRecord]);
|
|
return r8 ? r53.truncateTop(MAX_MESSAGES_PER_CHANNEL, false) : this.length > MAX_LOADED_MESSAGES ? r53.truncateBottom(MAX_MESSAGES_PER_CHANNEL, false) : r53;
|
|
}
|
|
receivePushNotification(a0, a1) {
|
|
if ((a0.nonce == null ? null : this.get(a0.nonce, true)) != null) {
|
|
return this;
|
|
}
|
|
if (this.get(a0.id, true) != null) {
|
|
return this;
|
|
}
|
|
const isIOSPushNotificationRawPayloadFixExperimentEnabled = _IOSPushNotificationRawPayloadFixExperiment.isIOSPushNotificationRawPayloadFixExperimentEnabled();
|
|
return this.mutate({
|
|
ready: true,
|
|
cached: isIOSPushNotificationRawPayloadFixExperimentEnabled ? !a1 : !isIOSPushNotificationRawPayloadFixExperimentEnabled
|
|
}).merge([mergeMessage(this, a0)]);
|
|
}
|
|
receiveReactionInAppNotification(a0) {
|
|
return (a0.nonce == null ? null : this.get(a0.nonce, true)) == null ? this.mutate({
|
|
ready: true,
|
|
cached: true
|
|
}).merge([mergeMessage(this, a0)]) : this;
|
|
}
|
|
loadStart(a0) {
|
|
const mutate2 = this.mutate;
|
|
let jumpedToPresent = a0?.present;
|
|
if (jumpedToPresent == null) {
|
|
jumpedToPresent = false;
|
|
}
|
|
let jumpTargetId = a0?.messageId;
|
|
if (jumpTargetId == null) {
|
|
jumpTargetId = null;
|
|
}
|
|
let jumpTargetOffset = a0?.offset;
|
|
if (jumpTargetOffset == null) {
|
|
jumpTargetOffset = 0;
|
|
}
|
|
let jumpReturnTargetId2 = a0?.returnMessageId;
|
|
if (jumpReturnTargetId2 == null) {
|
|
jumpReturnTargetId2 = null;
|
|
}
|
|
let onJumpComplete2 = a0?.onJumpComplete;
|
|
if (onJumpComplete2 == null) {
|
|
onJumpComplete2 = null;
|
|
}
|
|
return mutate2.call(this, {
|
|
loadingMore: true,
|
|
jumped: a0 != null,
|
|
jumpedToPresent,
|
|
jumpTargetId,
|
|
jumpTargetOffset,
|
|
jumpReturnTargetId: jumpReturnTargetId2,
|
|
onJumpComplete: onJumpComplete2,
|
|
ready: a0 == null && this.ready
|
|
});
|
|
}
|
|
loadComplete(a0) {
|
|
let r62;
|
|
const r8 = [...a0.newMessages];
|
|
let isBefore = a0.isBefore;
|
|
if (isBefore == null) {
|
|
isBefore = false;
|
|
}
|
|
let isAfter = a0.isAfter;
|
|
if (isAfter == null) {
|
|
isAfter = false;
|
|
}
|
|
let jump = a0.jump;
|
|
if (jump == null) {
|
|
jump = null;
|
|
}
|
|
let hasMoreBefore = a0.hasMoreBefore;
|
|
if (hasMoreBefore == null) {
|
|
hasMoreBefore = false;
|
|
}
|
|
let hasMoreAfter = a0.hasMoreAfter;
|
|
if (hasMoreAfter == null) {
|
|
hasMoreAfter = false;
|
|
}
|
|
let avoidInitialScroll = a0.avoidInitialScroll;
|
|
if (avoidInitialScroll == null) {
|
|
avoidInitialScroll = false;
|
|
}
|
|
let cached = a0.cached;
|
|
if (cached == null) {
|
|
cached = false;
|
|
}
|
|
L35: {
|
|
const r38 = Module12(r8).reverse().map((item) => createMessageRecord(item)).value();
|
|
if (!(!isBefore && !isAfter) && (jump == null && this.ready)) {
|
|
r62 = this.merge(r38, isBefore, true);
|
|
} else {
|
|
const r42 = this._array.filter((item) => item.state === MessageStates.SENDING);
|
|
const r45 = this._array.filter((item) => item.state === MessageStates.SEND_FAILED);
|
|
const r2 = r42.length > 0 || r45.length > 0;
|
|
const r49 = this.reset(r38);
|
|
if (r2 && !isBefore && !isAfter && jump?.messageId == null && jump?.offset == null) {
|
|
const length2 = r45.length;
|
|
let r22 = r49;
|
|
if (length2 > 0) {
|
|
c2993_9.info(`loadComplete: merging with SEND_FAILED messages for channelId=${this.channelId}`);
|
|
r22 = r49.merge(r45);
|
|
}
|
|
const length3 = r42.length;
|
|
r62 = r22;
|
|
if (!(length3 > 0)) {
|
|
break L35;
|
|
}
|
|
c2993_9.info(`loadComplete: merging with SENDING messages for channelId=${this.channelId}`);
|
|
r62 = r22.merge(r42);
|
|
break L35;
|
|
}
|
|
c2993_9.info(`loadComplete: resetting state for channelId=${this.channelId}, sending.length=${r42.length}`);
|
|
r62 = r49;
|
|
}
|
|
}
|
|
const r86 = (cached ? !cached : r62.cached) && !avoidInitialScroll;
|
|
const mutate2 = r62.mutate;
|
|
let jumpType2 = jump?.jumpType;
|
|
if (jumpType2 == null) {
|
|
jumpType2 = JumpType.ANIMATED;
|
|
}
|
|
let jumpFlash2 = jump?.flash;
|
|
if (jumpFlash2 == null) {
|
|
jumpFlash2 = false;
|
|
}
|
|
let jumpedToPresent = jump?.present;
|
|
if (jumpedToPresent == null) {
|
|
jumpedToPresent = false;
|
|
}
|
|
let jumpTargetId = jump?.messageId;
|
|
if (jumpTargetId == null) {
|
|
jumpTargetId = null;
|
|
}
|
|
const jumpTargetOffset = jump != null ? jump.messageId != null ? jump.offset != null ? jump.offset : 0 : 0 : 0;
|
|
const jumpSequenceId = jump != null && !avoidInitialScroll ? r62.jumpSequenceId + 1 : r62.jumpSequenceId;
|
|
let jumpReturnTargetId2 = jump?.returnMessageId;
|
|
if (jumpReturnTargetId2 == null) {
|
|
jumpReturnTargetId2 = null;
|
|
}
|
|
let onJumpComplete2 = jump?.onJumpComplete;
|
|
if (onJumpComplete2 == null) {
|
|
onJumpComplete2 = null;
|
|
}
|
|
const hasMoreBefore2 = jump == null ? isAfter ? r62.hasMoreBefore : hasMoreBefore : hasMoreBefore;
|
|
const hasMoreAfter2 = jump == null ? isBefore ? r62.hasMoreAfter : hasMoreAfter : hasMoreAfter;
|
|
const initialScrollSequenceId = r62.initialScrollSequenceId;
|
|
const initialScrollSequenceId2 = r86 ? initialScrollSequenceId + 1 : initialScrollSequenceId;
|
|
const suppressRowAnimationSequenceId = r62.suppressRowAnimationSequenceId;
|
|
return mutate2.call(r62, {
|
|
ready: true,
|
|
loadingMore: false,
|
|
jumpType: jumpType2,
|
|
jumpFlash: jumpFlash2,
|
|
jumped: jump != null,
|
|
jumpedToPresent,
|
|
jumpTargetId,
|
|
jumpTargetOffset,
|
|
jumpSequenceId,
|
|
jumpReturnTargetId: jumpReturnTargetId2,
|
|
onJumpComplete: onJumpComplete2,
|
|
hasMoreBefore: hasMoreBefore2,
|
|
hasMoreAfter: hasMoreAfter2,
|
|
cached,
|
|
hasFetched: a0.hasFetched,
|
|
error: false,
|
|
initialScrollSequenceId: initialScrollSequenceId2,
|
|
suppressRowAnimationSequenceId: r86 ? suppressRowAnimationSequenceId + 1 : suppressRowAnimationSequenceId
|
|
});
|
|
}
|
|
addCachedMessages(a0, a1) {
|
|
let c14475_0;
|
|
requireSortedDescending(a0);
|
|
const r18 = a0.map((item) => mergeMessage(this, item)).reverse();
|
|
c14475_0 = r18;
|
|
this._array.filter((c25302_0) => !c14475_0.some((item) => item.id === c25302_0.id)).forEach((item) => insert(c14475_0, item, (a0, a1) => SnowflakeUtils.compare(a0.id, a1.id)));
|
|
const r25 = a1 ? !a1 : this.cached;
|
|
const r27 = this.reset(r18);
|
|
const initialScrollSequenceId = this.initialScrollSequenceId;
|
|
return r27.mutate({
|
|
ready: true,
|
|
cached: a1,
|
|
error: false,
|
|
initialScrollSequenceId: r25 ? initialScrollSequenceId + 1 : initialScrollSequenceId
|
|
});
|
|
}
|
|
}
|
|
export default ChannelMessages;
|
|
export function flatMapChannelMessages(a0) {
|
|
return a0.flatMap((item) => item._array);
|
|
}
|