Files
discord-decomp/modules/search/SearchMessageStore.tsx
T
2026-11-01 12:12:55 +02:00

489 lines
13 KiB
TypeScript

// Metro module 5875 (f5876).
import AuthenticationStore from "../../stores/AuthenticationStore";
import RelationshipStore from "../../stores/RelationshipStore";
import { APIError } from "../../errors/index";
import { createMessageRecord, updateMessageRecord } from "../messages/MessageRecordUtils";
import { shouldApplyReaction } from "../reactions/ReactionUtils";
import Module589 from "../../_bundle/Module589";
import Dispatcher from "../../Dispatcher";
let c3677_5, c3677_6, c3677_7;
const handleReaction = function handleReaction(a0) {
const { type, messageId, userId, emoji } = a0;
if (shouldApplyReaction(a0)) {
const id = AuthenticationStore.getId();
const r25 = c3677_6.get(messageId);
const r1 = r25 == null;
let r27 = false;
if (!r1) {
const r28 = id === userId;
const reactionType = a0.reactionType;
c3677_6.set(messageId, type === "MESSAGE_REACTION_ADD" ? r25.addReaction(emoji, r28, a0.colors, reactionType) : r25.removeReaction(emoji, r28, reactionType));
r27 = true;
}
return r27;
}
return false;
};
class SearchState {
constructor() {
return {
__proto__: new.target.prototype,
isIndexing: false,
isHistoricalIndexing: false,
isFetching: false,
analyticsId: null,
error: null,
messages: null,
documentsIndexed: 0,
totalResults: null,
messageIds: new Set(),
isInitialFetchComplete: false,
cursor: null
};
}
handleSearchStart() {
this.isFetching = true;
this.isIndexing = false;
this.analyticsId = null;
this.error = null;
}
handleSearchIndexing() {
this.isInitialFetchComplete = true;
this.isIndexing = true;
this.isHistoricalIndexing = true;
this.isFetching = false;
this.error = null;
}
handleSearchFailure(a0) {
this.isFetching = false;
this.isIndexing = false;
this.isInitialFetchComplete = true;
this.isHistoricalIndexing = false;
this.error = new APIError(a0);
this.analyticsId = null;
this.documentsIndexed = 0;
}
handleSearchSuccess({ analyticsId, cursor, totalResults, doingHistoricalIndex, documentsIndexed }, a1) {
this.analyticsId = analyticsId;
this.isFetching = false;
this.isIndexing = false;
this.isInitialFetchComplete = true;
this.isHistoricalIndexing = doingHistoricalIndex;
this.error = null;
this.documentsIndexed = documentsIndexed;
this.cursor = cursor;
let messages = this.messages;
if (messages == null) {
messages = [];
}
const messages2 = [...messages];
let c15229_1 = messages2;
const r19 = [];
let c15229_0 = r19;
a1.forEach((item) => {
if (!(this.messageIds.has(item.id) || RelationshipStore.isBlockedOrIgnoredForMessage(item))) {
this.messageIds.add(item.id);
c15229_1.push(item);
c15229_0.push(item);
}
});
this.messages = messages2;
this.totalResults = totalResults;
return r19;
}
}
c3677_5 = new Map();
c3677_6 = new Map();
c3677_7 = new Map();
class SearchMessageStore extends Module589.Store {
static displayName = "SearchMessageStore";
initialize() {
this.waitFor(AuthenticationStore, RelationshipStore);
}
getMessage(a0) {
return c3677_6.get(a0);
}
getTotalCount(a0) {
let r7 = c3677_5.get(a0);
if (r7 == null) {
r7 = {
__proto__: SearchState.prototype,
isIndexing: false,
isHistoricalIndexing: false,
isFetching: false,
analyticsId: null,
error: null,
messages: null,
documentsIndexed: 0,
totalResults: null,
messageIds: new Set(),
isInitialFetchComplete: false,
cursor: null
};
}
return r7.totalResults;
}
getIsInitialFetchComplete(a0) {
let r7 = c3677_5.get(a0);
if (r7 == null) {
r7 = {
__proto__: SearchState.prototype,
isIndexing: false,
isHistoricalIndexing: false,
isFetching: false,
analyticsId: null,
error: null,
messages: null,
documentsIndexed: 0,
totalResults: null,
messageIds: new Set(),
isInitialFetchComplete: false,
cursor: null
};
}
return r7.isInitialFetchComplete;
}
getIsIndexing(a0) {
let r7 = c3677_5.get(a0);
if (r7 == null) {
r7 = {
__proto__: SearchState.prototype,
isIndexing: false,
isHistoricalIndexing: false,
isFetching: false,
analyticsId: null,
error: null,
messages: null,
documentsIndexed: 0,
totalResults: null,
messageIds: new Set(),
isInitialFetchComplete: false,
cursor: null
};
}
return r7.isIndexing;
}
getIsHistoricalIndexing(a0) {
let r7 = c3677_5.get(a0);
if (r7 == null) {
r7 = {
__proto__: SearchState.prototype,
isIndexing: false,
isHistoricalIndexing: false,
isFetching: false,
analyticsId: null,
error: null,
messages: null,
documentsIndexed: 0,
totalResults: null,
messageIds: new Set(),
isInitialFetchComplete: false,
cursor: null
};
}
return r7.isHistoricalIndexing;
}
getDocumentsIndexed(a0) {
let r7 = c3677_5.get(a0);
if (r7 == null) {
r7 = {
__proto__: SearchState.prototype,
isIndexing: false,
isHistoricalIndexing: false,
isFetching: false,
analyticsId: null,
error: null,
messages: null,
documentsIndexed: 0,
totalResults: null,
messageIds: new Set(),
isInitialFetchComplete: false,
cursor: null
};
}
return r7.documentsIndexed;
}
getIsFetching(a0) {
let r7 = c3677_5.get(a0);
if (r7 == null) {
r7 = {
__proto__: SearchState.prototype,
isIndexing: false,
isHistoricalIndexing: false,
isFetching: false,
analyticsId: null,
error: null,
messages: null,
documentsIndexed: 0,
totalResults: null,
messageIds: new Set(),
isInitialFetchComplete: false,
cursor: null
};
}
return r7.isFetching;
}
getError(a0) {
let r7 = c3677_5.get(a0);
if (r7 == null) {
r7 = {
__proto__: SearchState.prototype,
isIndexing: false,
isHistoricalIndexing: false,
isFetching: false,
analyticsId: null,
error: null,
messages: null,
documentsIndexed: 0,
totalResults: null,
messageIds: new Set(),
isInitialFetchComplete: false,
cursor: null
};
}
return r7.error;
}
getMessages(a0) {
let r7 = c3677_5.get(a0);
if (r7 == null) {
r7 = {
__proto__: SearchState.prototype,
isIndexing: false,
isHistoricalIndexing: false,
isFetching: false,
analyticsId: null,
error: null,
messages: null,
documentsIndexed: 0,
totalResults: null,
messageIds: new Set(),
isInitialFetchComplete: false,
cursor: null
};
}
return r7.messages;
}
getCursor(a0) {
let r7 = c3677_5.get(a0);
if (r7 == null) {
r7 = {
__proto__: SearchState.prototype,
isIndexing: false,
isHistoricalIndexing: false,
isFetching: false,
analyticsId: null,
error: null,
messages: null,
documentsIndexed: 0,
totalResults: null,
messageIds: new Set(),
isInitialFetchComplete: false,
cursor: null
};
}
return r7.cursor;
}
getAnalyticsId(a0) {
let r7 = c3677_5.get(a0);
if (r7 == null) {
r7 = {
__proto__: SearchState.prototype,
isIndexing: false,
isHistoricalIndexing: false,
isFetching: false,
analyticsId: null,
error: null,
messages: null,
documentsIndexed: 0,
totalResults: null,
messageIds: new Set(),
isInitialFetchComplete: false,
cursor: null
};
}
return r7.analyticsId;
}
hasSearchState(a0) {
return c3677_5.has(a0);
}
}
const searchMessageStore = new SearchMessageStore(Dispatcher, {
SEARCH_MESSAGES_START: function handleSearchMessagesStart(a0) {
a0.ids.forEach((id) => {
let r10 = c3677_5.get(id);
if (r10 == null) {
r10 = {
__proto__: SearchState.prototype,
isIndexing: false,
isHistoricalIndexing: false,
isFetching: false,
analyticsId: null,
error: null,
messages: null,
documentsIndexed: 0,
totalResults: null,
messageIds: new Set(),
isInitialFetchComplete: false,
cursor: null
};
}
c3677_5.set(id, r10);
r10.handleSearchStart();
});
},
SEARCH_MESSAGES_SUCCESS: function handleSearchMessagesSuccess(a0) {
a0.data.forEach((a0) => {
const id = a0.id;
let r4 = c3677_5.get(id);
if (r4 == null) {
r4 = {
__proto__: SearchState.prototype,
isIndexing: false,
isHistoricalIndexing: false,
isFetching: false,
analyticsId: null,
error: null,
messages: null,
documentsIndexed: 0,
totalResults: null,
messageIds: new Set(),
isInitialFetchComplete: false,
cursor: null
};
}
c3677_5.set(id, r4);
r4.handleSearchSuccess(a0, a0.messages.map((message) => {
const [r18] = message;
return createMessageRecord(r18);
})).forEach((item) => {
c3677_6.set(item.id, item);
let r11 = c3677_7.get(item.id);
if (r11 == null) {
r11 = 0;
}
c3677_7.set(item.id, r11 + 1);
});
});
},
SEARCH_MESSAGES_INDEXING: function handleSearchMessagesIndexing(a0) {
a0.ids.forEach((id) => {
let r10 = c3677_5.get(id);
if (r10 == null) {
r10 = {
__proto__: SearchState.prototype,
isIndexing: false,
isHistoricalIndexing: false,
isFetching: false,
analyticsId: null,
error: null,
messages: null,
documentsIndexed: 0,
totalResults: null,
messageIds: new Set(),
isInitialFetchComplete: false,
cursor: null
};
}
c3677_5.set(id, r10);
r10.handleSearchIndexing();
});
},
SEARCH_MESSAGES_FAILURE: function handleSearchMessagesFailure(a0) {
a0.ids.forEach((id) => {
let r10 = c3677_5.get(id);
if (r10 == null) {
r10 = {
__proto__: SearchState.prototype,
isIndexing: false,
isHistoricalIndexing: false,
isFetching: false,
analyticsId: null,
error: null,
messages: null,
documentsIndexed: 0,
totalResults: null,
messageIds: new Set(),
isInitialFetchComplete: false,
cursor: null
};
}
c3677_5.set(id, r10);
r10.handleSearchFailure(a0.error);
});
},
SEARCH_MESSAGES_CLEAR: function handleSearchMessagesClear(a0) {
const r6 = c3677_5.get(a0.id);
if (r6 == null) {
return false;
}
r6.messageIds.forEach((messageId) => {
let r6 = c3677_7.get(messageId);
if (r6 == null) {
r6 = 0;
}
if (r6 <= 1) {
c3677_6.delete(messageId);
c3677_7.delete(messageId);
} else {
c3677_7.set(messageId, r6 - 1);
}
});
c3677_5.delete(a0.id);
},
SEARCH_MESSAGES_CLEAR_ALL: function handleSearchMessagesClearAll() {
c3677_5 = new Map();
c3677_6 = new Map();
c3677_7 = new Map();
},
MESSAGE_UPDATE: function handleMessageUpdate(a0) {
const id = a0.message.id;
if (id == null) {
return false;
}
const r6 = c3677_6.get(id);
if (r6 == null) {
return false;
}
c3677_6.set(id, updateMessageRecord(r6, a0.message));
},
MESSAGE_REACTION_ADD: handleReaction,
MESSAGE_REACTION_ADD_MANY: function handleReactionBatch({ messageId, reactions }) {
const id = AuthenticationStore.getId();
const r11 = c3677_6.get(messageId);
const r1 = r11 == null;
let r12 = false;
if (!r1) {
c3677_6.set(messageId, r11.addReactionBatch(reactions, id));
r12 = true;
}
return r12;
},
MESSAGE_REACTION_REMOVE: handleReaction,
MESSAGE_REACTION_REMOVE_ALL: function handleRemoveAllReactions({ messageId }) {
const r7 = c3677_6.get(messageId);
const r1 = r7 == null;
let r9 = false;
if (!r1) {
c3677_6.set(messageId, r7.set("reactions", []));
r9 = true;
}
return r9;
},
MESSAGE_REACTION_REMOVE_EMOJI: function handleRemoveEmojiReactions({ messageId, emoji }) {
const r8 = c3677_6.get(messageId);
const r1 = r8 == null;
let r9 = false;
if (!r1) {
c3677_6.set(messageId, r8.removeReactionsForEmoji(emoji));
r9 = true;
}
return r9;
},
CONNECTION_OPEN: function handleConnectionOpen() {
c3677_5 = new Map();
c3677_6 = new Map();
c3677_7 = new Map();
}
});
export default searchMessageStore;