95 lines
3.2 KiB
TypeScript
95 lines
3.2 KiB
TypeScript
// Metro module 9885 (f9886).
|
|
import JoinedThreadsStore from "../threads/JoinedThreadsStore";
|
|
import ChannelStore from "../../stores/ChannelStore";
|
|
import MessageStore from "../../stores/MessageStore";
|
|
import { shouldBadgeMessage } from "../../stores/ReadStateStore";
|
|
import UserStore from "../../stores/UserStore";
|
|
import { Endpoints } from "../../Constants";
|
|
import Logger from "../debug/Logger";
|
|
import SnowflakeUtils from "../../utils/SnowflakeUtils";
|
|
import ThreadActionCreators from "../threads/ThreadActionCreators";
|
|
import { HTTP } from "../../_bundle/sendRequest";
|
|
let env6556 = {};
|
|
const c6556_10 = new Logger("markUnread");
|
|
export default async function markUnread(c26558_0, c26558_1) {
|
|
let c26558_2, c26558_3;
|
|
L27: {
|
|
L22: {
|
|
let env30154;
|
|
const r33 = env6556;
|
|
c26558_3 = r33;
|
|
const r13 = env30154 = {
|
|
$parent: r33
|
|
};
|
|
c26558_2 = r13;
|
|
env30154[0] = c26558_0;
|
|
env30154[1] = c26558_1;
|
|
env30154[2] = void 0;
|
|
env30154[3] = void 0;
|
|
env30154[4] = void 0;
|
|
env30154[5] = void 0;
|
|
const currentUser = UserStore.getCurrentUser();
|
|
env30154[2] = currentUser;
|
|
if (currentUser == null) {
|
|
break L27;
|
|
}
|
|
const messages = MessageStore.getMessages(c26558_0);
|
|
const r47 = messages.toArray().filter((item) => SnowflakeUtils.compare(item.id, env30154[1]) < 0).sort((a, b) => SnowflakeUtils.compare(a.id, b.id)).reverse()[0];
|
|
env30154[3] = r47 == null ? SnowflakeUtils.atPreviousMillisecond(c26558_1) : r47.id;
|
|
env30154[4] = 0;
|
|
messages.forAll((a0) => {
|
|
if (SnowflakeUtils.compare(a0.id, env30154[3]) > 0 && (0, shouldBadgeMessage)(a0, env30154[2])) {
|
|
env30154[4] = env30154[4] + 1;
|
|
}
|
|
});
|
|
const channel = ChannelStore.getChannel(c26558_0);
|
|
env30154[5] = channel;
|
|
const r60 = channel != null && channel.isThread();
|
|
L14: {
|
|
if (r60) {
|
|
if (channel.isArchivedThread()) {
|
|
await ThreadActionCreators.unarchiveThread(channel, false);
|
|
if (!JoinedThreadsStore.hasJoined(env30154[0])) {
|
|
await ThreadActionCreators.joinThread(env30154[5], "Mark Unread");
|
|
}
|
|
} else {
|
|
if (JoinedThreadsStore.hasJoined(env30154[0])) {
|
|
break L14;
|
|
}
|
|
await ThreadActionCreators.joinThread(env30154[5], "Mark Unread");
|
|
}
|
|
c6556_10.log("Marking unread", {
|
|
channelId: env30154[0],
|
|
messageId: env30154[1]
|
|
});
|
|
HTTP.post({
|
|
url: Endpoints.MESSAGE_ACK(env30154[0], env30154[3]),
|
|
body: {
|
|
manual: true,
|
|
mention_count: env30154[4]
|
|
},
|
|
oldFormErrors: true,
|
|
rejectWithError: true
|
|
});
|
|
break L22;
|
|
}
|
|
}
|
|
c6556_10.log("Marking unread", {
|
|
channelId: env30154[0],
|
|
messageId: env30154[1]
|
|
});
|
|
HTTP.post({
|
|
url: Endpoints.MESSAGE_ACK(env30154[0], env30154[3]),
|
|
body: {
|
|
manual: true,
|
|
mention_count: env30154[4]
|
|
},
|
|
oldFormErrors: true,
|
|
rejectWithError: true
|
|
});
|
|
break L27;
|
|
}
|
|
return void 0;
|
|
}
|
|
};
|