283 lines
8.4 KiB
TypeScript
283 lines
8.4 KiB
TypeScript
// Metro module 9270 (f9271).
|
|
import ConversationsStore from "./ConversationsStore";
|
|
import TopicalNavigationSurveyStore from "./TopicalNavigationSurveyStore";
|
|
import { FETCH_LIMIT } from "./ConversationConstants";
|
|
import { Endpoints } from "../../Constants";
|
|
import { isTopicalNavEnabled } from "./ConversationExperiments";
|
|
import Dispatcher from "../../Dispatcher";
|
|
import { HTTP } from "../../_bundle/sendRequest";
|
|
import MessageActionCreators from "../../actions/MessageActionCreators";
|
|
import { ConversationsAnalytics } from "./ConversationsAnalytics";
|
|
import QualtricsActionCreators from "../qualtrics/QualtricsActionCreators";
|
|
import { SurveyActionTypes } from "../../_bundle/Module9280";
|
|
const fetchConversationMessages = async function fetchConversationMessages(channelId, c26408_1, conversationId, c26408_3) {
|
|
let c26408_4;
|
|
let c26408_8 = 0;
|
|
let c30076_0, c30076_1, c30076_2, c30076_3;
|
|
L24: {
|
|
L21: {
|
|
try {
|
|
c30076_0 = channelId;
|
|
c30076_1 = conversationId;
|
|
c30076_2 = void 0;
|
|
c30076_3 = void 0;
|
|
if (!isTopicalNavEnabled(c26408_1, "fetch_conversation")) {
|
|
break L24;
|
|
}
|
|
c26408_4 = c26408_3;
|
|
if (c26408_3 == null) {
|
|
c26408_4 = {};
|
|
}
|
|
const r42 = c26408_4;
|
|
const { previewLimit, includeMessageReferences, includeReactions } = r42;
|
|
const full = previewLimit == null;
|
|
c30076_2 = full;
|
|
const conversationMetadata = ConversationsStore.getConversationMetadata(channelId, conversationId);
|
|
const r27 = conversationMetadata == null;
|
|
if (!(full ? (r27 ? void 0 : conversationMetadata.fullyHydrated) !== true : (r27 ? void 0 : conversationMetadata.hydratedMessages) == null)) {
|
|
break L24;
|
|
}
|
|
if (ConversationsStore.isConversationFetchPending(conversationId, full)) {
|
|
break L24;
|
|
}
|
|
Dispatcher.dispatch({
|
|
type: "CONVERSATION_FETCH_START",
|
|
channelId,
|
|
conversationId,
|
|
full
|
|
});
|
|
c26408_8 = 1;
|
|
c30076_3 = await HTTP.get({
|
|
url: Endpoints.CHANNEL_CONVERSATION_MESSAGES(channelId, conversationId),
|
|
query: {
|
|
limit: previewLimit,
|
|
include_ancestors: includeMessageReferences,
|
|
include_reactions: includeReactions
|
|
},
|
|
oldFormErrors: true,
|
|
rejectWithError: true
|
|
});
|
|
Dispatcher.dispatch({
|
|
type: "CONVERSATION_FETCH_SUCCESS",
|
|
channelId: c30076_0,
|
|
conversationId: c30076_1,
|
|
messages: c30076_3.body.messages,
|
|
messageReferences: c30076_3.body.ancestors,
|
|
fullyHydrated: c30076_2
|
|
});
|
|
c26408_8 = 0;
|
|
} catch ($e) {
|
|
let r8 = $e;
|
|
if (c26408_8 !== 0) {
|
|
while (true) {
|
|
try {
|
|
c26408_8 = 0;
|
|
Dispatcher.dispatch({
|
|
type: "CONVERSATION_FETCH_FAILURE",
|
|
channelId: c30076_0,
|
|
conversationId: c30076_1,
|
|
full: c30076_2
|
|
});
|
|
break L21;
|
|
} catch ($e) {
|
|
r8 = $e;
|
|
if (c26408_8 === 0) {
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
throw r8;
|
|
}
|
|
}
|
|
return void 0;
|
|
}
|
|
};
|
|
export async function fetchChannelConversations(c26407_0) {
|
|
let r198;
|
|
let isJump, limit, isJump2;
|
|
let c26407_6 = 0;
|
|
let c30075_0, c30075_1, c30075_2, c30075_3, c30075_4, c30075_5, c30075_6, c30075_7, c30075_8, c30075_9, c30075_10;
|
|
L36: {
|
|
try {
|
|
c30075_0 = void 0;
|
|
c30075_1 = void 0;
|
|
c30075_2 = void 0;
|
|
c30075_3 = void 0;
|
|
c30075_4 = void 0;
|
|
c30075_5 = void 0;
|
|
c30075_6 = void 0;
|
|
c30075_7 = void 0;
|
|
c30075_0 = c26407_0.channelId;
|
|
c30075_1 = c26407_0.guildId;
|
|
c30075_2 = c26407_0.direction;
|
|
c30075_3 = c26407_0.anchor;
|
|
let limit2 = c26407_0.limit;
|
|
if (limit2 === void 0) {
|
|
limit2 = FETCH_LIMIT;
|
|
}
|
|
c30075_4 = limit2;
|
|
c30075_5 = c26407_0.isJump;
|
|
const throwOnError = c26407_0.throwOnError;
|
|
if (throwOnError !== void 0) {
|
|
c30075_6 = throwOnError;
|
|
c30075_7 = c26407_0.hydrateMessages;
|
|
c30075_8 = void 0;
|
|
c30075_9 = void 0;
|
|
c30075_10 = void 0;
|
|
} else {
|
|
c30075_6 = false;
|
|
c30075_7 = c26407_0.hydrateMessages;
|
|
c30075_8 = void 0;
|
|
c30075_9 = void 0;
|
|
c30075_10 = void 0;
|
|
}
|
|
await void 0;
|
|
if (!isTopicalNavEnabled(c30075_1, "fetch_channel_conversations")) {
|
|
break L36;
|
|
}
|
|
c30075_8 = `${c30075_2}:${c30075_3}:${c30075_4}:${c30075_5 === true}`;
|
|
if (ConversationsStore.isListFetchPending(c30075_0, c30075_8)) {
|
|
break L36;
|
|
}
|
|
const r112 = c30075_5;
|
|
isJump = r112;
|
|
if (r112 == null) {
|
|
isJump = false;
|
|
}
|
|
Dispatcher.dispatch({
|
|
type: "CONVERSATIONS_FETCH_START",
|
|
channelId: c30075_0,
|
|
direction: c30075_2,
|
|
requestKey: c30075_8,
|
|
isJump
|
|
});
|
|
c30075_9 = {
|
|
limit: c30075_4
|
|
};
|
|
if (c30075_3 != null) {
|
|
if (c30075_2 === "before") {
|
|
c30075_9.before = c30075_3;
|
|
} else if (c30075_2 === "after") {
|
|
c30075_9.after = c30075_3;
|
|
} else {
|
|
c30075_9.around = c30075_3;
|
|
}
|
|
}
|
|
if (c30075_7 != null) {
|
|
c30075_9.include_messages = true;
|
|
const r146 = c30075_9;
|
|
limit = c30075_7.limit;
|
|
if (limit == null) {
|
|
limit = void 0;
|
|
}
|
|
r146.message_limit = limit;
|
|
}
|
|
c26407_6 = 1;
|
|
c30075_10 = (await HTTP.get({
|
|
url: Endpoints.CHANNEL_CONVERSATIONS(c30075_0),
|
|
query: c30075_9,
|
|
oldFormErrors: true,
|
|
rejectWithError: true
|
|
})).body.conversations;
|
|
const r189 = c30075_5;
|
|
isJump2 = r189;
|
|
if (r189 == null) {
|
|
isJump2 = false;
|
|
}
|
|
Dispatcher.dispatch({
|
|
type: "CONVERSATIONS_FETCH_SUCCESS",
|
|
channelId: c30075_0,
|
|
rawConversations: c30075_10,
|
|
direction: c30075_2,
|
|
requestKey: c30075_8,
|
|
anchor: c30075_3,
|
|
isJump: isJump2,
|
|
fullyHydrated: c30075_7?.limit == null
|
|
});
|
|
r198 = c30075_10;
|
|
c26407_6 = 0;
|
|
} catch ($e) {
|
|
let r44 = $e;
|
|
if (c26407_6 !== 0) {
|
|
while (true) {
|
|
try {
|
|
c26407_6 = 0;
|
|
Dispatcher.dispatch({
|
|
type: "CONVERSATIONS_FETCH_FAILURE",
|
|
channelId: c30075_0,
|
|
requestKey: c30075_8
|
|
});
|
|
if (!c30075_6) {
|
|
break L36;
|
|
}
|
|
throw new Error("Failed to fetch conversations");
|
|
} catch ($e) {
|
|
r44 = $e;
|
|
if (c26407_6 === 0) {
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
throw r44;
|
|
}
|
|
return r198;
|
|
}
|
|
}
|
|
export function toggleConversationHighlighting() {
|
|
Dispatcher.dispatch({
|
|
type: "CONVERSATIONS_TOGGLE_HIGHLIGHTING"
|
|
});
|
|
}
|
|
export function setSelectedConversation(a0, a1, a2, r5 = true) {
|
|
Dispatcher.dispatch({
|
|
type: "SET_SELECTED_CONVERSATION",
|
|
channelId: a0,
|
|
conversationId: a2
|
|
});
|
|
fetchConversationMessages(a0, a1, a2, {
|
|
includeReactions: true,
|
|
includeMessageReferences: true
|
|
});
|
|
const conversationMetadata = ConversationsStore.getConversationMetadata(a0, a2);
|
|
if (r5) {
|
|
r5 = (conversationMetadata == null ? void 0 : conversationMetadata.conversation.startMessageId) != null;
|
|
}
|
|
if (r5) {
|
|
MessageActionCreators.jumpToMessage({
|
|
channelId: a0,
|
|
messageId: conversationMetadata.conversation.startMessageId,
|
|
flash: false
|
|
});
|
|
}
|
|
}
|
|
export function clearConversationSelection(a0, a1) {
|
|
Dispatcher.dispatch({
|
|
type: "CLEAR_CONVERSATION_SELECTION",
|
|
channelId: a0,
|
|
conversationId: a1
|
|
});
|
|
}
|
|
export function setConversationFeedbackRating(a0, a1, a2) {
|
|
Dispatcher.dispatch({
|
|
type: "SET_CONVERSATION_FEEDBACK_RATING",
|
|
channelId: a0,
|
|
conversationId: a1,
|
|
rating: a2
|
|
});
|
|
}
|
|
export { fetchConversationMessages };
|
|
export function trackTopicalNavigationEntrypointImpression(a0, a1) {
|
|
ConversationsAnalytics.trackEntrypointImpression({
|
|
channelId: a0,
|
|
conversationCount: a1
|
|
});
|
|
if (TopicalNavigationSurveyStore.shouldTriggerOnNextExposure()) {
|
|
QualtricsActionCreators.fireSurveyAction(SurveyActionTypes.TOPICAL_NAVIGATION_MULTIPLE_IMPRESSIONS);
|
|
}
|
|
Dispatcher.dispatch({
|
|
type: "TOPICAL_NAVIGATION_ENTRYPOINT_IMPRESSION"
|
|
});
|
|
}
|