import {
fork as o,
takeLatest as e,
takeLeading as r,
getContext as m,
put as i,
call as d,
select as t,
} from "redux-saga/effects"
import { FEATURES as a, isFeatureSupported as n } from "@holepunchto/keet-core/features"
import { channel as p, buffers as s } from "redux-saga"
import { getCoreBackend as l } from "../../../backend"
import { apiCall as f } from "../../../api/core"
import { chatSaga as y, chatFilePendingSaga as c, chatMembersBlockedHandler as I } from "../../chat"
import {
memberSaga as g,
memberAllSubscriptionSaga as u,
MEMBER_ROLE as R,
getMemberItemById as M,
} from "../../member"
import { memberListSaga as b } from "../../member-list"
import { taskErrorSaga as E } from "../../error"
import { createInvitationSaga as S, createRoomInvitation as T } from "../joint"
import { subscribeToRoomInfo as O } from "../room-info.saga"
import { setMainRoomTipSize as x, getFirstTimeRoomModal as _ } from "./room-main.reducer"
import { updateRoomCapabilitiesInfo as h } from "../room-capabilities.saga"
import { roomVersionGate as D, subscribeRoomVersion as A } from "../room-version.saga"
import { roomInfoSaga as N } from "./room-info.saga"
import { ROOM_TYPE as B } from "../room.constant"
import { PLATFORM_CONTEXT_KEY as V } from "../../constants"
import { isBlockedMembersDataEvt as C } from "../../identity/member"
import { throttleFileStatsChanged as L } from "../../media/file/saga/file.saga"
import { memberChangeRoleSubmit as P, myMemberRemoved as k } from "../../member/member.reducer"
import {
setFirstTimeRoomModal as w,
closeFirstTimeRoomModal as X,
closeRoomSubmit as j,
} from "../room.action"
import {
PREFERENCES as v,
preferenceUpdateTask as z,
getPreferencesRoomIntroModalNeeded as F,
getPreferencesIntroModalSeenRooms as G,
} from "../../preferences"
import { forwardMessageToRoomSaga as H } from "../forward-message/forward-message.saga"
import { reportedMessagesSaga as U } from "../../reported-messages"
import { membersReportedSaga as q } from "../../member/reported"
export function* unindexededRoomTipSaga(o) {
try {
const e = l(),
r = yield f(e.getTipSize, o)
yield i(x(r))
} catch (o) {
yield E("unindexededRoomTipSaga", o)
}
}
function* J(o, e) {
const { role: r, memberId: m } = e.payload
if (r === R.MODERATOR || r === R.ADMIN) {
const e = yield t(M(o, m))
if (!e?.isMuted) return
const r = l()
yield f(r.unmuteMember, o, m)
}
}
function* K(o, e) {
const { roomId: r } = e.payload
r === o && (yield i(j({ openNextRoom: !0 })))
}
function* Q({ roomId: o }) {
try {
const e = yield t(_)
;(e.isOpen || e.roomId) && (yield i(X()))
const r = yield t(G)
yield i(w({ roomId: o, isOpen: !0 }))
const m = { ...r, [o]: !0 }
yield d(z, v.INTRO_MODAL_SEEN_ROOMS, m)
} catch (o) {
yield E("firstTimeRoomModalSaga", o)
}
}
export function* commonRoomSaga(i) {
const { roomId: l, myMemberId: f, roomType: R, roomVersion: M, messageId: x, appVersion: _ } = i
try {
const {
config: { appProtocol: i },
} = yield m(V),
E = yield d(p, s.expanding(20))
;(yield o(L, E),
yield o(D(a.REPORTED_MSG_INDEX, U, [l, f]), l),
yield o(D(a.REPORTED_MEMBER_INDEX, q, [l, f]), l))
const w = [],
X = R === B.BROADCAST,
j = n(M, a.CHAT_LABELS)
;(yield o(y, {
roomId: l,
ignoreBlocked: X,
filterNames: w,
messageId: x,
fileStatsChannel: E,
useLabelsFeature: j,
}),
yield o(c, { roomId: l }))
const v = n(M, a.MUTE_MEMBER)
;(yield o(h, { roomId: l, myMemberId: f }),
yield o(g, { roomId: l, myMemberId: f, muteMemberSupported: v }),
v && (yield e(P, J, l)),
yield r(T, S, { appProtocol: i }),
yield r(k, K, l),
yield o(N, { roomId: l, fileStatsChannel: E }),
yield o(O, { roomId: l, appVersion: _ }),
yield o(A, { roomId: l, appVersion: _ }),
yield e(C, I),
yield o(unindexededRoomTipSaga, l),
yield o(b, { roomId: l }),
yield o(u, { roomId: l }),
(yield t(F, l)) && (yield o(Q, { roomId: l })),
yield o(H, { appVersion: _ }))
} catch (o) {
yield E("commonRoomSaga", o)
}
}