提交
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
//
|
||||
// ConferenceInvitationActions.swift
|
||||
// TUIRoomKit
|
||||
//
|
||||
// Created by jeremiawang on 2024/8/12.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import RTCRoomEngine
|
||||
|
||||
enum ConferenceInvitationActions {
|
||||
static let key = "action.conferenceInvitation"
|
||||
|
||||
static let inviteUsers = ActionTemplate(id: key.appending(".inviteUsers"),
|
||||
payloadType: (String, [String]).self)
|
||||
static let accept = ActionTemplate(id: key.appending(".accept"), payloadType: String.self)
|
||||
static let reject = ActionTemplate(id: key.appending(".reject"), payloadType: (String, TUIInvitationRejectedReason).self)
|
||||
static let getInvitationList = ActionTemplate(id: key.appending(".getInvitationList"), payloadType: (String, String, [TUIInvitation]).self)
|
||||
static let fetchAttendees = ActionTemplate(id: key.appending(".fetchAttendees"), payloadType: (String, String, [UserInfo]).self)
|
||||
static let clearInvitationList = ActionTemplate(id: key.appending(".fetchAttendees"))
|
||||
|
||||
// MARK: callback
|
||||
static let updateInvitationList = ActionTemplate(id: key.appending(".setInvitationList"), payloadType: [TUIInvitation].self)
|
||||
static let addInvitation = ActionTemplate(id: key.appending(".addInvitation"), payloadType: TUIInvitation.self)
|
||||
static let removeInvitation = ActionTemplate(id: key.appending(".addInvitation"), payloadType: String.self)
|
||||
static let changeInvitationStatus = ActionTemplate(id: key.appending(".addInvitation"), payloadType: TUIInvitation.self)
|
||||
static let onInviteSuccess = ActionTemplate(id: key.appending("onInviteSuccess"))
|
||||
static let onAcceptSuccess = ActionTemplate(id: key.appending("onAcceptSuccess"), payloadType: String.self)
|
||||
static let onRejectSuccess = ActionTemplate(id: key.appending("onRejectSuccess"))
|
||||
static let onReceiveInvitation = ActionTemplate(id: key.appending("onAcceptSuccess"), payloadType: (TUIRoomInfo, TUIInvitation).self)
|
||||
static let onGetInvitationSuccess = ActionTemplate(id: key.appending("onGetInvitationSuccess"), payloadType: (String, [TUIInvitation]).self)
|
||||
static let onFetchAttendeesSuccess = ActionTemplate(id: key.appending("onFetchAttendeesSuccess"), payloadType: [UserInfo].self)
|
||||
}
|
||||
@@ -0,0 +1,164 @@
|
||||
//
|
||||
// ConferenceInvitationEffects.swift
|
||||
// TUIRoomKit
|
||||
//
|
||||
// Created by jeremiawang on 2024/8/12.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import RTCRoomEngine
|
||||
import Combine
|
||||
import Factory
|
||||
|
||||
class ConferenceInvitationEffects: Effects {
|
||||
typealias Environment = ServiceCenter
|
||||
|
||||
let inviteUsers = Effect<Environment>.dispatchingOne { actions, environment in
|
||||
actions.wasCreated(from: ConferenceInvitationActions.inviteUsers)
|
||||
.flatMap { action in
|
||||
environment.conferenceInvitationService.inviteUsers(roomId: action.payload.0, userIdList: action.payload.1)
|
||||
.map { _ in
|
||||
ConferenceInvitationActions.onInviteSuccess()
|
||||
}
|
||||
.catch { error -> Just<Action> in
|
||||
Just(ErrorActions.throwError(payload: error))
|
||||
}
|
||||
}
|
||||
.eraseToAnyPublisher()
|
||||
}
|
||||
|
||||
let accept = Effect<Environment>.dispatchingOne { actions, environment in
|
||||
actions.wasCreated(from: ConferenceInvitationActions.accept)
|
||||
.flatMap { action in
|
||||
environment.conferenceInvitationService.accept(roomId: action.payload)
|
||||
.map { roomId in
|
||||
ConferenceInvitationActions.onAcceptSuccess(payload: roomId)
|
||||
}
|
||||
.catch { error -> Just<Action> in
|
||||
environment.store?.dispatch(action: InvitationViewActions.dismissInvitationView())
|
||||
return Just(ErrorActions.throwError(payload: error))
|
||||
}
|
||||
}
|
||||
.eraseToAnyPublisher()
|
||||
}
|
||||
|
||||
let reject = Effect<Environment>.dispatchingOne { actions, environment in
|
||||
actions.wasCreated(from: ConferenceInvitationActions.reject)
|
||||
.flatMap { action in
|
||||
environment.conferenceInvitationService.reject(roomId: action.payload.0, reason: action.payload.1)
|
||||
.map { _ in
|
||||
ConferenceInvitationActions.onRejectSuccess()
|
||||
}
|
||||
.catch { error -> Just<Action> in
|
||||
Just(ErrorActions.throwError(payload: error))
|
||||
}
|
||||
}
|
||||
.eraseToAnyPublisher()
|
||||
}
|
||||
|
||||
let getInvitationList = Effect<Environment>.dispatchingOne { actions, environment in
|
||||
actions.wasCreated(from: ConferenceInvitationActions.getInvitationList)
|
||||
.flatMap { action in
|
||||
environment.conferenceInvitationService.getInvitationList(roomId: action.payload.0, cursor: action.payload.1)
|
||||
.map { invitations, cursor in
|
||||
var invitationList = action.payload.2
|
||||
let newList = invitationList + invitations
|
||||
if cursor.isEmpty {
|
||||
return ConferenceInvitationActions.onGetInvitationSuccess(payload: (action.payload.0, newList))
|
||||
} else {
|
||||
return ConferenceInvitationActions.getInvitationList(payload: (action.payload.0, cursor, newList))
|
||||
}
|
||||
}
|
||||
.catch { error -> Just<Action> in
|
||||
Just(ErrorActions.throwError(payload: error))
|
||||
}
|
||||
}
|
||||
.eraseToAnyPublisher()
|
||||
}
|
||||
|
||||
let fetchAttendees = Effect<Environment>.dispatchingOne { actions, environment in
|
||||
actions.wasCreated(from: ConferenceInvitationActions.fetchAttendees)
|
||||
.flatMap { action in
|
||||
environment.conferenceListService.fetchAttendeeList(conferenceId: action.payload.0, cursor: action.payload.1)
|
||||
.map { userInfoList, cursor, totalCount in
|
||||
var attendeesList = action.payload.2
|
||||
attendeesList.append(contentsOf: userInfoList)
|
||||
if cursor.isEmpty {
|
||||
return ConferenceInvitationActions.onFetchAttendeesSuccess(payload: attendeesList)
|
||||
} else {
|
||||
return ConferenceInvitationActions.fetchAttendees(payload:(action.payload.0, cursor, attendeesList))
|
||||
}
|
||||
}
|
||||
.catch { error -> Just<Action> in
|
||||
Just(ErrorActions.throwError(payload: error))
|
||||
}
|
||||
}
|
||||
.eraseToAnyPublisher()
|
||||
}
|
||||
|
||||
let onAcceptSuccess = Effect<Environment>.nonDispatching { actions, environment in
|
||||
actions
|
||||
.wasCreated(from: ConferenceInvitationActions.onAcceptSuccess)
|
||||
.sink { action in
|
||||
let roomId = action.payload
|
||||
InvitationObserverService.shared.dismissInvitationWindow()
|
||||
let joinParams = JoinConferenceParams(roomId: roomId)
|
||||
joinParams.isOpenMicrophone = true
|
||||
joinParams.isOpenCamera = false
|
||||
joinParams.isOpenSpeaker = true
|
||||
let vc = ConferenceMainViewController()
|
||||
vc.setJoinConferenceParams(params: joinParams)
|
||||
DispatchQueue.main.async {
|
||||
RoomRouter.shared.push(viewController: vc)
|
||||
}
|
||||
environment.store?.dispatch(action: InvitationViewActions.dismissInvitationView())
|
||||
}
|
||||
}
|
||||
|
||||
let onReceiveInvitation = Effect<Environment>.nonDispatching { actions, environment in
|
||||
actions
|
||||
.wasCreated(from: ConferenceInvitationActions.onReceiveInvitation)
|
||||
.sink { action in
|
||||
let roomInfo = action.payload.0
|
||||
let invitation = action.payload.1
|
||||
let isEnteredRoom = environment.store?.selectCurrent(RoomSelectors.getIsEnteredRoom)
|
||||
let isNotBeingInviting = environment.store?.selectCurrent(ViewSelectors.getDismissInvitationFlag)
|
||||
if isEnteredRoom == true {
|
||||
environment.store?.dispatch(action: ConferenceInvitationActions.reject(payload: (roomInfo.roomId, .inOtherConference)))
|
||||
} else if isNotBeingInviting == false {
|
||||
environment.store?.dispatch(action: ConferenceInvitationActions.reject(payload: (roomInfo.roomId, .rejectToEnter)))
|
||||
} else {
|
||||
InvitationObserverService.shared.showInvitationWindow(roomInfo: roomInfo, invitation: invitation)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let onGetInvitationSuccess = Effect<Environment>.nonDispatching { actions, environment in
|
||||
actions
|
||||
.wasCreated(from: ConferenceInvitationActions.onGetInvitationSuccess)
|
||||
.sink { action in
|
||||
let roomId = action.payload.0
|
||||
let invitations = action.payload.1
|
||||
environment.store?.dispatch(action: ConferenceInvitationActions.updateInvitationList(payload: invitations))
|
||||
environment.store?.dispatch(action: ConferenceInvitationActions.fetchAttendees(payload: (roomId, "", [])))
|
||||
}
|
||||
}
|
||||
|
||||
let onFetchAttendeesSuccess = Effect<Environment>.nonDispatching { actions, environment in
|
||||
actions
|
||||
.wasCreated(from: ConferenceInvitationActions.onFetchAttendeesSuccess)
|
||||
.sink { action in
|
||||
let attendeeList = action.payload
|
||||
var filteredList: [UserInfo] = []
|
||||
if let allUsers = environment.store?.selectCurrent(UserSelectors.getAllUsers) {
|
||||
filteredList = attendeeList.filter { user in
|
||||
!allUsers.contains { existedUser in
|
||||
user.userId == existedUser.userId
|
||||
}
|
||||
}
|
||||
}
|
||||
let resultList = filteredList.map{ TUIInvitation(userInfo: $0) }
|
||||
environment.store?.dispatch(action: ConferenceInvitationActions.updateInvitationList(payload: resultList))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
//
|
||||
// ConferenceInvitationReducer.swift
|
||||
// TUIRoomKit
|
||||
//
|
||||
// Created by jeremiawang on 2024/8/19.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import RTCRoomEngine
|
||||
|
||||
let ConferenceInvitationReducer = Reducer<ConferenceInvitationState>(
|
||||
ReduceOn(ConferenceInvitationActions.updateInvitationList, reduce: { state, action in
|
||||
let newInvitations: [TUIInvitation] = action.payload
|
||||
let previousInvitations = state.invitationList
|
||||
var existingIds = Set(previousInvitations.map { $0.invitee.userId })
|
||||
var combinedInvitations = previousInvitations
|
||||
for invitation in newInvitations {
|
||||
if !existingIds.contains(invitation.invitee.userId) {
|
||||
combinedInvitations.append(invitation)
|
||||
existingIds.insert(invitation.invitee.userId)
|
||||
}
|
||||
}
|
||||
state.invitationList = combinedInvitations
|
||||
}),
|
||||
ReduceOn(ConferenceInvitationActions.addInvitation, reduce: { state, action in
|
||||
let userIdToAdd = action.payload.invitee.userId
|
||||
if let index = state.invitationList.firstIndex(where: { $0.invitee.userId == userIdToAdd }) {
|
||||
state.invitationList[index] = action.payload
|
||||
} else {
|
||||
state.invitationList.insert(action.payload, at: 0)
|
||||
}
|
||||
}),
|
||||
ReduceOn(ConferenceInvitationActions.removeInvitation, reduce: { state, action in
|
||||
let userIdToRemove = action.payload
|
||||
if let index = state.invitationList.firstIndex(where: { $0.invitee.userId == userIdToRemove }) {
|
||||
state.invitationList.remove(at: index)
|
||||
}
|
||||
}),
|
||||
ReduceOn(ConferenceInvitationActions.changeInvitationStatus, reduce: { state, action in
|
||||
let userIdToChange = action.payload.invitee.userId
|
||||
if let index = state.invitationList.firstIndex(where: { $0.invitee.userId == userIdToChange }) {
|
||||
state.invitationList[index] = action.payload
|
||||
}
|
||||
}),
|
||||
ReduceOn(ConferenceInvitationActions.clearInvitationList, reduce: { state, action in
|
||||
state.invitationList.removeAll()
|
||||
})
|
||||
)
|
||||
@@ -0,0 +1,14 @@
|
||||
//
|
||||
// ConferenceInvitationSelector.swift
|
||||
// TUIRoomKit
|
||||
//
|
||||
// Created by jeremiawang on 2024/8/19.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
enum ConferenceInvitationSelectors {
|
||||
static let getConferenceInvitationState = Selector(keyPath: \OperationState.conferenceInvitationState)
|
||||
|
||||
static let getInvitationList = Selector.with(getConferenceInvitationState, keyPath:\ConferenceInvitationState.invitationList)
|
||||
}
|
||||
Reference in New Issue
Block a user