// Metro module 3826 (f3827). import _slicedToArray from "../_bundle/_slicedToArray"; import MessageRecord from "../records/MessageRecord"; import UserStore from "./UserStore"; import { RelationshipTypes } from "../Constants"; import Dispatcher from "../Dispatcher"; import Module589 from "../_bundle/Module589"; let c2163_6, c2163_7, c2163_8, c2163_9, c2163_10, c2163_11, c2163_12, c2163_13, c2163_14, c2163_15, c2163_16, size, size2, c2163_19, c2163_20, removeRelationship, recountPending; const upsertRelationship = function upsertRelationship(a0, a1) { const r6 = c2163_6.get(a0); if (r6 !== a1) { if (r6 != null) { const r14 = c2163_20.get(r6); if (r14 != null) { r14.delete(a0); } } c2163_6.set(a0, a1); const r21 = c2163_20.get(a1); if (r21 != null) { r21.add(a0); } else { c2163_20.set(a1, new Set([a0])); } c2163_19.friends = void 0; c2163_19.blocked = void 0; c2163_19.ignored = void 0; c2163_19.blockedOrIgnored = void 0; } }; removeRelationship = function removeRelationship(item) { const r5 = c2163_6.get(item); if (r5 != null) { c2163_6.delete(item); const r10 = c2163_20.get(r5); if (r10 != null) { r10.delete(item); } c2163_19.friends = void 0; c2163_19.blocked = void 0; c2163_19.ignored = void 0; c2163_19.blockedOrIgnored = void 0; } }; recountPending = function recountPending() { size = c2163_10.size; size2 = c2163_12.size; const r7 = Math; let r17 = c2163_20.get(RelationshipTypes.PENDING_INCOMING)?.size; if (r17 == null) { r17 = 0; } c2163_16 = r7.max(r17 - size - size2, 0); c2163_14 = c2163_14 + 1; }; c2163_6 = new Map(); c2163_7 = {}; c2163_8 = {}; c2163_9 = {}; c2163_10 = new Set(); c2163_11 = new Set(); c2163_12 = new Set(); c2163_13 = {}; c2163_14 = 0; c2163_15 = {}; c2163_16 = 0; size = 0; size2 = 0; c2163_19 = { friends: void 0, blocked: void 0, ignored: void 0, blockedOrIgnored: void 0 }; c2163_20 = new Map(); class RelationshipStore extends Module589.Store { static displayName = "RelationshipStore"; initialize() { this.waitFor(UserStore); } isFriend(a0) { return a0 != null && c2163_6.get(a0) === RelationshipTypes.FRIEND; } isBlockedOrIgnored(a0) { return this.isBlocked(a0) || this.isIgnored(a0); } isBlockedOrIgnoredForMessage(a0) { return this.isBlockedForMessage(a0) || this.isIgnoredForMessage(a0); } isBlocked(a0) { return a0 != null && c2163_6.get(a0) === RelationshipTypes.BLOCKED; } isBlockedForMessage(a0) { if (a0.author != null && c2163_6.get(a0.author.id) === RelationshipTypes.BLOCKED) { return true; } const r1 = a0 instanceof MessageRecord; const isBlocked2 = this.isBlocked; if (r1) { const interactionMetadata = a0.interactionMetadata; if (isBlocked2.call(this, interactionMetadata == null ? void 0 : interactionMetadata.user?.id)) { return true; } } else { const interaction_metadata = a0.interaction_metadata; if (isBlocked2.call(this, interaction_metadata == null ? void 0 : interaction_metadata.user?.id)) { return true; } } return false; } isIgnored(a0) { return a0 != null && (c2163_6.get(a0) !== RelationshipTypes.BLOCKED && c2163_11.has(a0)); } isIgnoredForMessage(a0) { if (a0.author != null && this.isIgnored(a0.author.id)) { return true; } const r1 = a0 instanceof MessageRecord; const isIgnored2 = this.isIgnored; if (r1) { const interactionMetadata = a0.interactionMetadata; if (isIgnored2.call(this, interactionMetadata == null ? void 0 : interactionMetadata.user?.id)) { return true; } } else { const interaction_metadata = a0.interaction_metadata; if (isIgnored2.call(this, interaction_metadata == null ? void 0 : interaction_metadata.user?.id)) { return true; } } return false; } isUnfilteredPendingIncoming(a0) { return c2163_6.get(a0) === RelationshipTypes.PENDING_INCOMING && !this.isSpam(a0) && !this.isIgnored(a0); } getPendingCount() { return c2163_16; } getSpamCount() { return size; } getPendingIgnoredCount() { return size2; } getOutgoingCount() { let r9 = c2163_20.get(RelationshipTypes.PENDING_OUTGOING)?.size; if (r9 == null) { r9 = 0; } return r9; } getFriendCount() { let r9 = c2163_20.get(RelationshipTypes.FRIEND)?.size; if (r9 == null) { r9 = 0; } return r9; } getRelationshipCount() { return c2163_6.size; } getMutableRelationships() { return c2163_6; } getVersion() { return c2163_14; } isSpam(a0) { return c2163_10.has(a0); } getRelationshipType(a0) { let r5 = c2163_6.get(a0); if (r5 == null) { r5 = RelationshipTypes.NONE; } return r5; } getNickname(a0) { return c2163_7[a0]; } getSince(a0) { return c2163_8[a0]; } getSinces() { return c2163_8; } getNote(a0) { return c2163_9[a0]; } getFriendIDs() { if (c2163_19.friends == null) { const r4 = Array; let r11 = c2163_20.get(RelationshipTypes.FRIEND); if (r11 == null) { r11 = []; } c2163_19.friends = r4.from(r11); } return c2163_19.friends; } getBlockedIDs() { if (c2163_19.blocked == null) { const r4 = Array; let r11 = c2163_20.get(RelationshipTypes.BLOCKED); if (r11 == null) { r11 = []; } c2163_19.blocked = r4.from(r11); } return c2163_19.blocked; } getIgnoredIDs() { if (c2163_19.ignored == null) { c2163_19.ignored = Array.from(c2163_11.values()).filter((item) => this.isIgnored(item)); } return c2163_19.ignored; } getBlockedOrIgnoredIDs() { if (c2163_19.blockedOrIgnored == null) { const set = new Set(c2163_11); const r25 = c2163_20.get(RelationshipTypes.BLOCKED); if (r25 != null) { for (const item of r25) { set.add(item); } } c2163_19.blockedOrIgnored = Array.from(set.values()); } return c2163_19.blockedOrIgnored; } getOriginApplicationId(a0) { return c2163_13[a0]; } isStranger(a0) { if (c2163_15[a0] != null) { if (!(c2163_15[a0].expiry < Date.now())) { return c2163_15[a0].isStranger; } delete c2163_15[a0]; } } } const relationshipStore = new RelationshipStore(Dispatcher, { CONNECTION_OPEN: function handleConnectionOpen(a0) { c2163_6.clear(); c2163_20.clear(); c2163_7 = {}; c2163_8 = {}; c2163_9 = {}; c2163_11.clear(); c2163_10.clear(); c2163_12.clear(); c2163_19.friends = void 0; c2163_19.blocked = void 0; c2163_19.ignored = void 0; c2163_19.blockedOrIgnored = void 0; c2163_13 = {}; c2163_15 = {}; a0.relationships.forEach((relationship) => { const { id, type } = relationship; const r7 = c2163_6.get(id); if (r7 !== type) { if (r7 != null) { const r15 = c2163_20.get(r7); if (r15 != null) { r15.delete(id); } } c2163_6.set(id, type); const r22 = c2163_20.get(type); if (r22 != null) { r22.add(id); } else { c2163_20.set(type, new Set([id])); } c2163_19.friends = void 0; c2163_19.blocked = void 0; c2163_19.ignored = void 0; c2163_19.blockedOrIgnored = void 0; } if (relationship.nickname != null) { c2163_7[relationship.id] = relationship.nickname; } if (relationship.since != null) { c2163_8[relationship.id] = relationship.since; } if (relationship.note != null) { c2163_9[relationship.id] = relationship.note; } if (relationship.is_spam_request) { c2163_10.add(relationship.id); } if (relationship.origin_application_id != null) { c2163_13[relationship.id] = relationship.origin_application_id; } if (relationship.user_ignored) { c2163_11.add(relationship.id); if (relationship.type === RelationshipTypes.PENDING_INCOMING) { c2163_12.add(relationship.id); } } }); size = c2163_10.size; size2 = c2163_12.size; const r34 = Math; let r40 = c2163_20.get(RelationshipTypes.PENDING_INCOMING)?.size; if (r40 == null) { r40 = 0; } c2163_16 = r34.max(r40 - size - size2, 0); c2163_14 = c2163_14 + 1; }, OVERLAY_INITIALIZE: function handleOverlayInitialize(a0) { c2163_6.clear(); c2163_20.clear(); for (const relationship of a0.relationships) { const r32 = _slicedToArray(relationship, 2); upsertRelationship(r32[0], r32[1]); } recountPending(); }, RELATIONSHIP_ADD: function handleRelationshipAdd(a0) { const r19 = c2163_6.get(a0.relationship.id); const id = a0.relationship.id; const type = a0.relationship.type; const r11 = c2163_6.get(id); if (r11 !== type) { if (r11 != null) { const r24 = c2163_20.get(r11); if (r24 != null) { r24.delete(id); } } c2163_6.set(id, type); const r31 = c2163_20.get(type); if (r31 != null) { r31.add(id); } else { c2163_20.set(type, new Set([id])); } c2163_19.friends = void 0; c2163_19.blocked = void 0; c2163_19.ignored = void 0; c2163_19.blockedOrIgnored = void 0; } if (a0.relationship.nickname != null) { const r44 = { ...c2163_7 }; r44[a0.relationship.id] = a0.relationship.nickname; c2163_7 = r44; } if (a0.relationship.since != null) { const r53 = { ...c2163_8 }; r53[a0.relationship.id] = a0.relationship.since; c2163_8 = r53; } if (a0.relationship.note != null) { const r63 = { ...c2163_9 }; r63[a0.relationship.id] = a0.relationship.note; c2163_9 = r63; } if (a0.relationship.originApplicationId != null) { const r73 = { ...c2163_13 }; r73[a0.relationship.id] = a0.relationship.originApplicationId; c2163_13 = r73; } if (a0.relationship.isSpamRequest) { c2163_10.add(a0.relationship.id); } else { c2163_10.delete(a0.relationship.id); } if (a0.relationship.userIgnored) { c2163_11.add(a0.relationship.id); if (a0.relationship.type === RelationshipTypes.PENDING_INCOMING) { c2163_12.add(a0.relationship.id); } else if (a0.relationship.type === RelationshipTypes.FRIEND) { c2163_12.delete(a0.relationship.id); } } else { c2163_11.delete(a0.relationship.id); c2163_12.delete(a0.relationship.id); } size = c2163_10.size; size2 = c2163_12.size; const r131 = Math; let r139 = c2163_20.get(RelationshipTypes.PENDING_INCOMING)?.size; if (r139 == null) { r139 = 0; } c2163_16 = r131.max(r139 - size - size2, 0); c2163_14 = c2163_14 + 1; if (a0.relationship.type === RelationshipTypes.FRIEND && r19 === RelationshipTypes.PENDING_OUTGOING) { Dispatcher.dispatch({ type: "FRIEND_REQUEST_ACCEPTED", user: a0.relationship.user }); } }, RELATIONSHIP_REMOVE: function handleRelationshipRemove(a0) { const id = a0.relationship.id; const r9 = c2163_6.get(id); if (r9 != null) { c2163_6.delete(id); const r17 = c2163_20.get(r9); if (r17 != null) { r17.delete(id); } c2163_19.friends = void 0; c2163_19.blocked = void 0; c2163_19.ignored = void 0; c2163_19.blockedOrIgnored = void 0; } if (c2163_7[a0.relationship.id] != null) { const r25 = { ...c2163_7 }; c2163_7 = r25; delete r25[a0.relationship.id]; } if (c2163_8[a0.relationship.id] != null) { const r34 = { ...c2163_8 }; c2163_8 = r34; delete r34[a0.relationship.id]; } if (c2163_9[a0.relationship.id] != null) { const r45 = { ...c2163_9 }; c2163_9 = r45; delete r45[a0.relationship.id]; } if (c2163_13[a0.relationship.id] != null) { const r56 = { ...c2163_13 }; c2163_13 = r56; delete r56[a0.relationship.id]; } if (!a0.relationship.userIgnored) { c2163_11.delete(a0.relationship.id); } c2163_12.delete(a0.relationship.id); c2163_10.delete(a0.relationship.id); size = c2163_10.size; size2 = c2163_12.size; const r83 = Math; let r91 = c2163_20.get(RelationshipTypes.PENDING_INCOMING)?.size; if (r91 == null) { r91 = 0; } c2163_16 = r83.max(r91 - size - size2, 0); c2163_14 = c2163_14 + 1; }, RELATIONSHIP_UPDATE: function handleRelationshipUpdate({ relationship }) { const { id, type } = relationship; const r10 = c2163_6.get(id); if (r10 !== type) { if (r10 != null) { const r19 = c2163_20.get(r10); if (r19 != null) { r19.delete(id); } } c2163_6.set(id, type); const r26 = c2163_20.get(type); if (r26 != null) { r26.add(id); } else { c2163_20.set(type, new Set([id])); } c2163_19.friends = void 0; c2163_19.blocked = void 0; c2163_19.ignored = void 0; c2163_19.blockedOrIgnored = void 0; } if (relationship.since == null) { delete c2163_8[relationship.id]; } else { c2163_8[relationship.id] = relationship.since; } if (relationship.nickname == null) { delete c2163_7[relationship.id]; } else { c2163_7[relationship.id] = relationship.nickname; } if (relationship.note == null) { delete c2163_9[relationship.id]; } else { c2163_9[relationship.id] = relationship.note; } if (relationship.isSpamRequest) { c2163_10.add(relationship.id); } else { c2163_10.delete(relationship.id); } if (c2163_15[relationship.id] != null) { delete c2163_15[relationship.id]; } if (relationship.originApplicationId == null) { delete c2163_13[relationship.id]; } else { c2163_13[relationship.id] = relationship.originApplicationId; } if (relationship.userIgnored) { c2163_11.add(relationship.id); if (relationship.type === RelationshipTypes.PENDING_INCOMING) { c2163_12.add(relationship.id); } } else { c2163_11.delete(relationship.id); c2163_12.delete(relationship.id); } size = c2163_10.size; size2 = c2163_12.size; const r104 = Math; let r112 = c2163_20.get(RelationshipTypes.PENDING_INCOMING)?.size; if (r112 == null) { r112 = 0; } c2163_16 = r104.max(r112 - size - size2, 0); c2163_14 = c2163_14 + 1; }, RELATIONSHIP_PENDING_INCOMING_REMOVED: function handlePendingIncomingRemoved() { for (const item of c2163_6.keys()) { if (c2163_6.get(item) === RelationshipTypes.PENDING_INCOMING) { removeRelationship(item); c2163_10.delete(item); c2163_12.delete(item); delete c2163_15[item]; } } recountPending(); }, UPDATE_STRANGER_STATUS: function handleUpdateStrangerStatus(a0) { c2163_15[a0.userId] = { expiry: Date.now() + 300000, isStranger: a0.isStranger }; } }); export default relationshipStore;