445 lines
17 KiB
TypeScript
445 lines
17 KiB
TypeScript
// Metro module 5925 (f5926).
|
|
import ExperimentStore from "../experiments/ExperimentStore";
|
|
import { isGuildEventEnded } from "../guild_scheduled_events/GuildScheduledEventStore";
|
|
import MessageRecord from "../../records/MessageRecord";
|
|
import RelationshipStore from "../../stores/RelationshipStore";
|
|
import UserStore from "../../stores/UserStore";
|
|
import { RelationshipTypes } from "../../Constants";
|
|
import { ItemEnum, NotificationCenterItems, NotificationCenterLocalItems } from "./NotificationCenterItemsTypes";
|
|
import { createMessageRecord } from "../messages/MessageRecordUtils";
|
|
import { incomingFriendRequestLocalItem, incomingGameFriendRequestLocalItem, mobileNativeUpdateAvailableLocalItem } from "./NotificationCenterUtils";
|
|
import SnowflakeUtils from "../../utils/SnowflakeUtils";
|
|
import Module589 from "../../_bundle/Module589";
|
|
import Dispatcher from "../../Dispatcher";
|
|
function $mk77386($env) {
|
|
return (a0) => {
|
|
const r3 = $env;
|
|
return r3[0].includes(a0.id) ? {
|
|
...a0,
|
|
acked: r3[1]
|
|
} : a0;
|
|
};
|
|
}
|
|
function $mk77389($env) {
|
|
return (a0) => {
|
|
const type = a0.type;
|
|
const r1 = $env.$parent;
|
|
return type === (0, r1[0])(r1[2][6]).NotificationCenterItems.GUILD_SCHEDULED_EVENT_STARTED ? a0.guild_scheduled_event_id === $env[0].id ? {
|
|
...a0,
|
|
disable_action: true
|
|
} : a0 : a0;
|
|
};
|
|
}
|
|
let toNotificationCenterItem, c3711_12;
|
|
let env3711 = {};
|
|
const _validate = function _validate(a0) {
|
|
return a0.id != null && a0.type != null;
|
|
};
|
|
toNotificationCenterItem = function toNotificationCenterItem(a0) {
|
|
if (a0.item_enum === ItemEnum.FIRST_MESSAGE && a0.type === NotificationCenterItems.LIFECYCLE_ITEM) {
|
|
a0.deeplink = "https://discord.com/feature/composeMessage";
|
|
}
|
|
return {
|
|
...a0,
|
|
kind: "notification-center-item",
|
|
message: a0.message != null ? createMessageRecord(a0.message) : void 0,
|
|
applicationId: a0.application != null ? a0.application.id : void 0
|
|
};
|
|
};
|
|
const handleAddItem = function handleAddItem(a0) {
|
|
let r15;
|
|
if (a0.type === "NOTIFICATION_CENTER_ITEM_CREATE") {
|
|
const item = a0.item;
|
|
if (item.item_enum === ItemEnum.FIRST_MESSAGE && item.type === NotificationCenterItems.LIFECYCLE_ITEM) {
|
|
item.deeplink = "https://discord.com/feature/composeMessage";
|
|
}
|
|
r15 = {
|
|
...item,
|
|
kind: "notification-center-item",
|
|
message: item.message != null ? createMessageRecord(item.message) : void 0,
|
|
applicationId: item.application != null ? item.application.id : void 0
|
|
};
|
|
} else {
|
|
r15 = a0.item;
|
|
}
|
|
if (env3711[9].initialized && r15.id != null && r15.type != null && !env3711[9].notifCenterIds.has(r15.id)) {
|
|
env3711[9].notifCenterIds.add(r15.id);
|
|
const r56 = env3711[9];
|
|
r56.notifCenterItems = [r15, ...r56.notifCenterItems];
|
|
env3711[9].notifCenterItems.sort((a, b) => SnowflakeUtils.compare(b.id, a.id));
|
|
return void 0;
|
|
}
|
|
return false;
|
|
};
|
|
const handleRelationshipAddOrUpdate = function handleRelationshipAddOrUpdate({ relationship }) {
|
|
const { id, type, isSpamRequest, userIgnored, user, since, originApplicationId } = relationship;
|
|
if (type === RelationshipTypes.PENDING_INCOMING && !isSpamRequest && !userIgnored) {
|
|
if (since == null) {
|
|
return null;
|
|
}
|
|
if (user != null) {
|
|
const user2 = UserStore.getUser(user.id);
|
|
if (user2 != null) {
|
|
const r24 = env3711[9];
|
|
r24.notifCenterLocalItems = [...r24.notifCenterLocalItems, incomingFriendRequestLocalItem(user2, since, originApplicationId)];
|
|
}
|
|
}
|
|
}
|
|
if (!(type !== RelationshipTypes.FRIEND || relationship.user == null || userIgnored)) {
|
|
const r35 = env3711[9];
|
|
r35.notifCenterLocalItems = r35.notifCenterLocalItems.map((notifCenterLocalItem) => {
|
|
const INCOMING_FRIEND_REQUESTS = NotificationCenterLocalItems.INCOMING_FRIEND_REQUESTS;
|
|
const id4 = relationship.user.id;
|
|
return notifCenterLocalItem.type === INCOMING_FRIEND_REQUESTS && notifCenterLocalItem.other_user?.id === id4 ? {
|
|
...notifCenterLocalItem,
|
|
acked: true,
|
|
forceUnacked: false,
|
|
local_id: `incoming_friend_requests_accepted_${user.id}_${notifCenterLocalItem.id}`,
|
|
type: NotificationCenterLocalItems.INCOMING_FRIEND_REQUESTS_ACCEPTED
|
|
} : notifCenterLocalItem;
|
|
});
|
|
}
|
|
if (type === RelationshipTypes.BLOCKED || userIgnored) {
|
|
const r42 = env3711[9];
|
|
r42.notifCenterLocalItems = r42.notifCenterLocalItems.filter((notifCenterLocalItem) => !(notifCenterLocalItem.type === NotificationCenterLocalItems.INCOMING_FRIEND_REQUESTS && notifCenterLocalItem.other_user?.id === id || notifCenterLocalItem.type === NotificationCenterLocalItems.INCOMING_FRIEND_REQUESTS_ACCEPTED && notifCenterLocalItem.other_user?.id === id || notifCenterLocalItem.type === NotificationCenterLocalItems.INCOMING_GAME_FRIEND_REQUESTS && notifCenterLocalItem.other_user?.id === id || notifCenterLocalItem.type === NotificationCenterLocalItems.INCOMING_GAME_FRIEND_REQUESTS_ACCEPTED && notifCenterLocalItem.other_user?.id === id));
|
|
}
|
|
};
|
|
env3711[9] = {
|
|
loading: false,
|
|
initialized: false,
|
|
errored: false,
|
|
isDataStale: false,
|
|
notifCenterItems: [],
|
|
staleNotifCenterItems: [],
|
|
notifCenterIds: new Set(),
|
|
notifCenterLocalItems: [],
|
|
paginationHasMore: true,
|
|
paginationCursor: void 0,
|
|
notifCenterActive: false,
|
|
notifCenterTabFocused: false
|
|
};
|
|
class NotificationCenterItemsStore extends Module589.PersistedStore {
|
|
static displayName = "NotificationCenterItemsStore";
|
|
static persistKey = "NotificationCenterItemsStore_v2";
|
|
constructor() {
|
|
super(...arguments);
|
|
}
|
|
initialize(a0) {
|
|
this.waitFor(UserStore, RelationshipStore, ExperimentStore);
|
|
if (a0 != null) {
|
|
const staleNotifCenterItems = a0.notifCenterItems.map(function(notifCenterItem) {
|
|
return {
|
|
...notifCenterItem,
|
|
message: notifCenterItem.message != null ? new MessageRecord(notifCenterItem.message) : void 0
|
|
};
|
|
});
|
|
if (staleNotifCenterItems.length > 0) {
|
|
env3711[9] = {
|
|
...env3711[9],
|
|
initialized: true,
|
|
isDataStale: true,
|
|
notifCenterItems: [],
|
|
staleNotifCenterItems
|
|
};
|
|
}
|
|
}
|
|
}
|
|
getState() {
|
|
const pack = function pack(a0) {
|
|
return {
|
|
...a0,
|
|
message: a0.message != null ? a0.message.toJS() : void 0
|
|
};
|
|
};
|
|
return {
|
|
...env3711[9],
|
|
notifCenterItems: env3711[9].notifCenterItems.map(pack),
|
|
staleNotifCenterItems: env3711[9].staleNotifCenterItems.map(pack)
|
|
};
|
|
}
|
|
get loading() {
|
|
return env3711[9].loading;
|
|
}
|
|
get initialized() {
|
|
return env3711[9].initialized;
|
|
}
|
|
get items() {
|
|
const isDataStale = env3711[9].isDataStale;
|
|
const r3 = env3711[9];
|
|
return isDataStale ? r3.staleNotifCenterItems : r3.notifCenterItems;
|
|
}
|
|
get hasMore() {
|
|
return env3711[9].paginationHasMore;
|
|
}
|
|
get cursor() {
|
|
return env3711[9].paginationCursor;
|
|
}
|
|
get errored() {
|
|
return env3711[9].errored;
|
|
}
|
|
get active() {
|
|
return env3711[9].notifCenterActive;
|
|
}
|
|
get localItems() {
|
|
return env3711[9].notifCenterLocalItems;
|
|
}
|
|
get tabFocused() {
|
|
return env3711[9].notifCenterTabFocused;
|
|
}
|
|
}
|
|
c3711_12 = NotificationCenterItemsStore;
|
|
const r94 = new NotificationCenterItemsStore(Dispatcher, {
|
|
CONNECTION_OPEN: function handleConnectionOpen(a0) {
|
|
const notifCenterLocalItems = [];
|
|
let c15277_0 = notifCenterLocalItems;
|
|
let c15277_1 = new Set();
|
|
a0.relationships.forEach(({ id: id4, type, since, is_spam_request, user_ignored, origin_application_id }) => {
|
|
if (user_ignored) {
|
|
c15277_1.add(id4);
|
|
}
|
|
if (type === RelationshipTypes.PENDING_INCOMING && !is_spam_request && !user_ignored && since != null) {
|
|
const user2 = UserStore.getUser(id4);
|
|
if (user2 == null) {
|
|
return null;
|
|
}
|
|
c15277_0.push(incomingFriendRequestLocalItem(user2, since, origin_application_id));
|
|
return void 0;
|
|
}
|
|
return null;
|
|
});
|
|
a0.gameRelationships.forEach(({ type, id: id4, application_id, since }) => {
|
|
if (type === RelationshipTypes.PENDING_INCOMING && !c15277_1.has(id4)) {
|
|
const user2 = UserStore.getUser(id4);
|
|
if (user2 != null) {
|
|
c15277_0.push(incomingGameFriendRequestLocalItem(user2, since, application_id));
|
|
}
|
|
}
|
|
});
|
|
a0.guilds.forEach((guild) => {
|
|
guild.guild_scheduled_events.forEach((guild_scheduled_event) => {
|
|
let env29635;
|
|
const r1 = env29635 = {
|
|
$parent: env3711
|
|
};
|
|
env29635[0] = guild_scheduled_event;
|
|
if ((0, isGuildEventEnded)(guild_scheduled_event)) {
|
|
const r6 = env3711[9];
|
|
r6.notifCenterItems = r6.notifCenterItems.map($mk77389(r1));
|
|
}
|
|
});
|
|
});
|
|
env3711[9].notifCenterLocalItems = notifCenterLocalItems;
|
|
},
|
|
LOGOUT: () => {
|
|
let keepLocalItems = ({}).keepLocalItems;
|
|
if (keepLocalItems === void 0) {
|
|
keepLocalItems = false;
|
|
}
|
|
env3711[9] = {
|
|
loading: false,
|
|
initialized: false,
|
|
errored: false,
|
|
isDataStale: false,
|
|
notifCenterItems: [],
|
|
staleNotifCenterItems: [],
|
|
notifCenterIds: new Set(),
|
|
notifCenterLocalItems: keepLocalItems ? env3711[9].notifCenterLocalItems : [],
|
|
paginationHasMore: true,
|
|
paginationCursor: void 0,
|
|
notifCenterActive: false,
|
|
notifCenterTabFocused: false
|
|
};
|
|
},
|
|
NOTIFICATION_CENTER_ITEMS_ACK: function handleAck({ ids }) {
|
|
let env15278;
|
|
const r3 = env15278 = {};
|
|
env15278[0] = ids;
|
|
env15278[1] = true;
|
|
const r7 = env3711[9];
|
|
r7.notifCenterItems = r7.notifCenterItems.map($mk77386(r3)).filter(_validate);
|
|
},
|
|
NOTIFICATION_CENTER_ITEMS_ACK_FAILURE: function handleAckFailure({ ids }) {
|
|
let env15279;
|
|
const r3 = env15279 = {};
|
|
env15279[0] = ids;
|
|
env15279[1] = false;
|
|
const r7 = env3711[9];
|
|
r7.notifCenterItems = r7.notifCenterItems.map($mk77386(r3)).filter(_validate);
|
|
},
|
|
GUILD_SCHEDULED_EVENT_UPDATE: function handleGuildScheduledEventUpdate({ guildScheduledEvent }) {
|
|
let env15280;
|
|
const r5 = env15280 = {
|
|
$parent: env3711
|
|
};
|
|
env15280[0] = guildScheduledEvent;
|
|
if ((0, isGuildEventEnded)(guildScheduledEvent)) {
|
|
const r7 = env3711[9];
|
|
r7.notifCenterItems = r7.notifCenterItems.map($mk77389(r5));
|
|
}
|
|
},
|
|
NOTIFICATION_CENTER_ITEM_CREATE: handleAddItem,
|
|
NOTIFICATION_CENTER_ITEM_DELETE: function handleDelete({ id: id2 }) {
|
|
if (env3711[9].notifCenterIds.has(id2)) {
|
|
env3711[9].notifCenterIds.delete(id2);
|
|
const r13 = env3711[9];
|
|
r13.notifCenterItems = r13.notifCenterItems.filter((notifCenterItem) => notifCenterItem.id !== id2);
|
|
return void 0;
|
|
}
|
|
return false;
|
|
},
|
|
NOTIFICATION_CENTER_ITEM_DELETE_FAILURE: handleAddItem,
|
|
LOAD_NOTIFICATION_CENTER_ITEMS: function handleLoad() {
|
|
env3711[9].loading = true;
|
|
},
|
|
LOAD_NOTIFICATION_CENTER_ITEMS_FAILURE: function handleLoadFailure() {
|
|
env3711[9].loading = false;
|
|
env3711[9].initialized = true;
|
|
env3711[9].errored = true;
|
|
},
|
|
LOAD_NOTIFICATION_CENTER_ITEMS_SUCCESS: function handleLoadSuccess({ items: items2, hasMore: hasMore2, cursor: cursor2 }) {
|
|
if (env3711[9].loading) {
|
|
env3711[9].loading = false;
|
|
env3711[9].initialized = true;
|
|
env3711[9].errored = false;
|
|
env3711[9].isDataStale = false;
|
|
if (!(cursor2 != null && env3711[9].notifCenterIds.has(cursor2))) {
|
|
env3711[9].paginationHasMore = items2.length > 0 && hasMore2;
|
|
env3711[9].paginationCursor = items2.length > 0 ? cursor2 : void 0;
|
|
}
|
|
const r29 = env3711[9];
|
|
r29.notifCenterItems = [...r29.notifCenterItems, ...items2.map(toNotificationCenterItem).filter((item) => !env3711[9].notifCenterIds.has(item.id))];
|
|
env3711[9].notifCenterItems.sort((a, b) => SnowflakeUtils.compare(b.id, a.id));
|
|
items2.forEach((item) => env3711[9].notifCenterIds.add(item.id));
|
|
}
|
|
},
|
|
RESET_NOTIFICATION_CENTER: () => {
|
|
let keepLocalItems = ({
|
|
keepLocalItems: true
|
|
}).keepLocalItems;
|
|
if (keepLocalItems === void 0) {
|
|
keepLocalItems = false;
|
|
}
|
|
env3711[9] = {
|
|
loading: false,
|
|
initialized: false,
|
|
errored: false,
|
|
isDataStale: false,
|
|
notifCenterItems: [],
|
|
staleNotifCenterItems: [],
|
|
notifCenterIds: new Set(),
|
|
notifCenterLocalItems: keepLocalItems ? env3711[9].notifCenterLocalItems : [],
|
|
paginationHasMore: true,
|
|
paginationCursor: void 0,
|
|
notifCenterActive: false,
|
|
notifCenterTabFocused: false
|
|
};
|
|
},
|
|
NOTIFICATION_CENTER_SET_ACTIVE: function handleSetActive(a0) {
|
|
env3711[9].notifCenterActive = a0.active;
|
|
},
|
|
NOTIFICATION_CENTER_TAB_FOCUSED: function handleTabFocused(a0) {
|
|
env3711[9].notifCenterTabFocused = a0.focused;
|
|
},
|
|
RELATIONSHIP_ADD: handleRelationshipAddOrUpdate,
|
|
RELATIONSHIP_UPDATE: handleRelationshipAddOrUpdate,
|
|
RELATIONSHIP_REMOVE: function handleRelationshipRemove(c15282_0) {
|
|
const r6 = env3711[9];
|
|
r6.notifCenterLocalItems = r6.notifCenterLocalItems.filter((notifCenterLocalItem) => {
|
|
const INCOMING_FRIEND_REQUESTS = NotificationCenterLocalItems.INCOMING_FRIEND_REQUESTS;
|
|
const id4 = c15282_0.relationship.id;
|
|
const r0 = notifCenterLocalItem.type === INCOMING_FRIEND_REQUESTS && notifCenterLocalItem.other_user?.id === id4;
|
|
let r20 = !r0;
|
|
if (!r0) {
|
|
const INCOMING_FRIEND_REQUESTS_ACCEPTED = NotificationCenterLocalItems.INCOMING_FRIEND_REQUESTS_ACCEPTED;
|
|
const id5 = c15282_0.relationship.id;
|
|
r20 = !(notifCenterLocalItem.type === INCOMING_FRIEND_REQUESTS_ACCEPTED && notifCenterLocalItem.other_user?.id === id5);
|
|
}
|
|
return r20;
|
|
});
|
|
},
|
|
GAME_RELATIONSHIP_ADD: function handleGameRelationshipAddOrUpdate({ gameRelationship }) {
|
|
const { id: id3, type, since, applicationId } = gameRelationship;
|
|
if (RelationshipStore.isBlockedOrIgnored(id3)) {
|
|
return false;
|
|
}
|
|
if (type === RelationshipTypes.PENDING_INCOMING) {
|
|
const user2 = UserStore.getUser(id3);
|
|
if (since != null && user2 != null) {
|
|
const r30 = env3711[9];
|
|
r30.notifCenterLocalItems = [...r30.notifCenterLocalItems, incomingGameFriendRequestLocalItem(user2, since, applicationId)];
|
|
}
|
|
} else {
|
|
if (type !== RelationshipTypes.FRIEND) {
|
|
return false;
|
|
}
|
|
const r21 = env3711[9];
|
|
r21.notifCenterLocalItems = r21.notifCenterLocalItems.map((notifCenterLocalItem) => notifCenterLocalItem.type === NotificationCenterLocalItems.INCOMING_GAME_FRIEND_REQUESTS && notifCenterLocalItem.other_user?.id === id3 && notifCenterLocalItem.applicationId === applicationId ? {
|
|
...notifCenterLocalItem,
|
|
acked: true,
|
|
forceUnacked: false,
|
|
local_id: `incoming_game_friend_requests_accepted_${id3}_${notifCenterLocalItem.id}`,
|
|
type: NotificationCenterLocalItems.INCOMING_GAME_FRIEND_REQUESTS_ACCEPTED
|
|
} : notifCenterLocalItem);
|
|
}
|
|
},
|
|
GAME_RELATIONSHIP_REMOVE: function handleGameRelationshipRemove({ userId, applicationId: applicationId2 }) {
|
|
const r7 = env3711[9];
|
|
r7.notifCenterLocalItems = r7.notifCenterLocalItems.filter((notifCenterLocalItem) => {
|
|
const r0 = notifCenterLocalItem.type === NotificationCenterLocalItems.INCOMING_GAME_FRIEND_REQUESTS && notifCenterLocalItem.other_user?.id === userId && notifCenterLocalItem.applicationId === applicationId2;
|
|
return r0 ? !r0 : !(notifCenterLocalItem.type === NotificationCenterLocalItems.INCOMING_GAME_FRIEND_REQUESTS_ACCEPTED && notifCenterLocalItem.other_user?.id === userId && notifCenterLocalItem.applicationId === applicationId2);
|
|
});
|
|
},
|
|
NOTIFICATION_CENTER_ITEM_COMPLETED: function handleCompleted({ item_enum }) {
|
|
const r7 = env3711[9];
|
|
r7.notifCenterItems = r7.notifCenterItems.map((notifCenterItem) => notifCenterItem.item_enum === item_enum ? {
|
|
...notifCenterItem,
|
|
completed: true,
|
|
acked: true
|
|
} : notifCenterItem).filter(_validate);
|
|
},
|
|
SET_RECENT_MENTIONS_FILTER: () => {
|
|
let keepLocalItems = ({
|
|
keepLocalItems: true
|
|
}).keepLocalItems;
|
|
if (keepLocalItems === void 0) {
|
|
keepLocalItems = false;
|
|
}
|
|
env3711[9] = {
|
|
loading: false,
|
|
initialized: false,
|
|
errored: false,
|
|
isDataStale: false,
|
|
notifCenterItems: [],
|
|
staleNotifCenterItems: [],
|
|
notifCenterIds: new Set(),
|
|
notifCenterLocalItems: keepLocalItems ? env3711[9].notifCenterLocalItems : [],
|
|
paginationHasMore: true,
|
|
paginationCursor: void 0,
|
|
notifCenterActive: false,
|
|
notifCenterTabFocused: false
|
|
};
|
|
},
|
|
MOBILE_NATIVE_UPDATE_CHECK_FINISHED: function handleMobileNativeUpdate({ newBuild }) {
|
|
let c15286_0;
|
|
c15286_0 = void 0;
|
|
if (newBuild !== null) {
|
|
const r16 = mobileNativeUpdateAvailableLocalItem(newBuild);
|
|
c15286_0 = r16;
|
|
if (env3711[9].notifCenterLocalItems.find((notifCenterLocalItem) => notifCenterLocalItem.local_id === c15286_0.local_id) === void 0) {
|
|
const r21 = env3711[9];
|
|
r21.notifCenterLocalItems = [...r21.notifCenterLocalItems.filter((notifCenterLocalItem) => notifCenterLocalItem.type !== c15286_0.type), r16];
|
|
}
|
|
}
|
|
},
|
|
APPLICATIONS_FETCH_SUCCESS: function handleFetchApplicationsSuccess({ unknownApplicationIds }) {
|
|
let c15287_0;
|
|
c15287_0 = void 0;
|
|
if (unknownApplicationIds != null) {
|
|
c15287_0 = new Set(unknownApplicationIds);
|
|
const r13 = env3711[9];
|
|
r13.notifCenterLocalItems = r13.notifCenterLocalItems.filter((notifCenterLocalItem) => notifCenterLocalItem.applicationId == null || !c15287_0.has(notifCenterLocalItem.applicationId));
|
|
}
|
|
}
|
|
});
|
|
export default r94;
|