import {
delay as e,
getContext as i,
put as a,
select as t,
take as o,
call as l,
} from "redux-saga/effects"
import { taskErrorSaga as d } from "../error"
import { CHAT_MESSAGE_TYPE as r, getChatMessageById as s } from "../chat"
import {
createRoomInvitation as n,
getRoomItemById as y,
setRoomInvitation as c,
clearRoomInvitation as m,
} from "../room"
import { APP_CONTEXT_KEY as g } from "../constants"
import { uiProcessCopyChatMessage as p } from "./ui.action"
import { userInfoNotification as f } from "../notification"
import { getFileEntryById as h, updateFileEntryCleared as I } from "../media/file"
export function* copyMessageLinkSaga({ payload: { messageId: e, roomId: l } }) {
try {
const { localeManager: d } = yield i(g),
r = d.getStrings()
yield a(n({ roomId: l, messageId: e }))
const { invitationLink: s } = yield o(c),
{ title: h } = yield t(y(l)),
{ messageLinkCopied: I, messageLinkCopiedTitle: C, messageLinkCopiedValidity: L } = r.chat,
S = `${C.replace("$0", h)}${s}${L}`
;(yield a(p(S || "")), yield a(f({ message: I })), yield a(m()))
} catch (e) {
yield d("copyMessageLinkSaga", e)
}
}
export function* copyChatMessageSaga({ payload: { messageId: o } }) {
try {
const { localeManager: l, helpers: d } = yield i(g),
n = l.getStrings(),
y = yield t(s, o),
c =
y.event?.type === r.LOCATION_SHARED
? `${y.event.latitude}, ${y.event.longitude}`
: d.messageToParserData(y.chat)?.text || ""
;(yield a(p(c)), yield e(300), yield a(f({ message: n.downloads.textCopied })))
} catch (e) {
yield d("copyChatMessageSaga", e)
}
}
export function* clearFileCacheSaga({ payload: e }) {
try {
const { fileManager: o } = yield i(g),
d = yield t(s, e),
{ fileId: r } = d || {}
if (r) {
yield a(I({ fileId: r, cleared: !0 }))
const e = yield t(h, r),
{ isImage: i } = yield l(o.getMediaType, e.httpLink, e.mimetype)
i && (yield l(o.clearImage, e.httpLink))
}
} catch (e) {
yield d("clearFileCacheSaga", e)
}
}