Skip to content

Commit

Permalink
【iOS】Modify the issue of inaccurate participants in conference details.
Browse files Browse the repository at this point in the history
  • Loading branch information
Tangjianing authored and AbySwifter committed Nov 18, 2024
1 parent 421866a commit 717d4e7
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
import Combine

protocol ScheduleConferenceStore {
func fetchAttendees(cursor: String)
func update(conference info: ConferenceInfo)
func fetchRoomInfo(roomId: String)
func fetchAttendees(cursor: String)
func fetchRoomPassword(roomId: String)
func select<Value:Equatable>(_ selector: Selector<ConferenceInfo, Value>) -> AnyPublisher<Value, Never>
var conferenceInfo: ConferenceInfo { get }
}
Expand All @@ -19,7 +19,8 @@ class ScheduleConferenceStoreProvider {
static let updateConferenceInfo = ActionTemplate(id: "updateConferenceInfo", payloadType: ConferenceInfo.self)
static let fetchAttendeeList = ActionTemplate(id: "fetchAttendeeList", payloadType: (String, String, Int).self)
static let updateAttendeeList = ActionTemplate(id: "updateAttendeeList", payloadType: ([UserInfo], String, UInt).self)
static let fetchRoomInfo = ActionTemplate(id: ".fetchRoomInfo", payloadType: String.self)
static let fetchRoomPassword = ActionTemplate(id: ".fetchRoomPassword", payloadType: String.self)
static let updateRoomPassword = ActionTemplate(id: "updateRoomPassword", payloadType: String.self)
static let attendeesPerFetch = 20

// MARK: - private property.
Expand All @@ -37,6 +38,10 @@ class ScheduleConferenceStoreProvider {
state.attendeeListResult.attendeeList.append(contentsOf: action.payload.0)
state.attendeeListResult.fetchCursor = action.payload.1
state.attendeeListResult.totalCount = action.payload.2
}),
ReduceOn(updateRoomPassword, reduce: { state, action in
state.basicInfo.password = action.payload
state.basicInfo.isPasswordEnabled = !action.payload.isEmpty
})
)

Expand All @@ -47,17 +52,17 @@ class ScheduleConferenceStoreProvider {
}

extension ScheduleConferenceStoreProvider: ScheduleConferenceStore {
func update(conference info: ConferenceInfo) {
store.dispatch(action: ScheduleConferenceStoreProvider.updateConferenceInfo(payload: info))
}

func fetchAttendees(cursor: String) {
let conferenceId = conferenceInfo.basicInfo.roomId
store.dispatch(action: ScheduleConferenceStoreProvider.fetchAttendeeList(payload: (conferenceId, cursor, ScheduleConferenceStoreProvider.attendeesPerFetch)))
}

func update(conference info: ConferenceInfo) {
store.dispatch(action: ScheduleConferenceStoreProvider.updateConferenceInfo(payload: info))
}

func fetchRoomInfo(roomId: String) {
store.dispatch(action: ScheduleConferenceStoreProvider.fetchRoomInfo(payload: roomId))
func fetchRoomPassword(roomId: String) {
store.dispatch(action: ScheduleConferenceStoreProvider.fetchRoomPassword(payload: roomId))
}

func select<Value>(_ selector: Selector<ConferenceInfo, Value>) -> AnyPublisher<Value, Never> where Value : Equatable {
Expand Down Expand Up @@ -88,12 +93,12 @@ class scheduleConferenceEffects: Effects {
.eraseToAnyPublisher()
}

let fetchRoomInfo = Effect<Environment>.dispatchingOne { actions, environment in
actions.wasCreated(from: ScheduleConferenceStoreProvider.fetchRoomInfo)
let fetchRoomPassword = Effect<Environment>.dispatchingOne { actions, environment in
actions.wasCreated(from: ScheduleConferenceStoreProvider.fetchRoomPassword)
.flatMap { action in
environment.conferenceListService.fetchConferenceInfo(roomId: action.payload)
.map { conferenceInfo in
ScheduleConferenceStoreProvider.updateConferenceInfo(payload: conferenceInfo)
ScheduleConferenceStoreProvider.updateRoomPassword(payload: conferenceInfo.basicInfo.password)
}
.catch { error -> Just<Action> in
Just(ErrorActions.throwError(payload: error))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ class ScheduleDetailsDataHelper: ScheduleConferenceDataHelper {
item?.bindStateClosure = { cell, cancellableSet in
let selector = Selector(keyPath: \ConferenceInfo.attendeeListResult.attendeeList)
store.select(selector)
.removeDuplicates()
.receive(on: RunLoop.main)
.sink { [weak cell] list in
if let cell = cell as? ScheduleTabCell {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ class ScheduleDetailsViewController: UIViewController {
self.rootView.tableView.reloadData()
}
.store(in: &cancellableSet)
store.fetchRoomInfo(roomId: conferenceInfo.basicInfo.roomId)
store.fetchRoomPassword(roomId: conferenceInfo.basicInfo.roomId)
}

private func initState() {
Expand Down

0 comments on commit 717d4e7

Please sign in to comment.