UserEffects.swift 1002 B

1234567891011121314151617181920212223242526272829303132
  1. //
  2. // UserEffects.swift
  3. // TUIRoomKit
  4. //
  5. // Created by CY zhao on 2024/6/5.
  6. //
  7. import Foundation
  8. import Combine
  9. import ImSDK_Plus
  10. import RTCRoomEngine
  11. class UserEffects: Effects {
  12. typealias Environment = ServiceCenter
  13. let getSelfInfo = Effect<Environment>.dispatchingOne { actions, environment in
  14. actions
  15. .wasCreated(from: UserActions.getSelfInfo)
  16. .flatMap { action -> AnyPublisher<Action, Never> in
  17. let selfId = environment.store?.selectCurrent(UserSelectors.getSelfId) ?? ""
  18. return environment.userService.fetchUserInfo(selfId)
  19. .map { userInfo in
  20. return UserActions.updateSelfInfo(payload: userInfo)
  21. }
  22. .catch { error -> Just<Action> in
  23. return Just(ErrorActions.throwError(payload: error))
  24. }
  25. .eraseToAnyPublisher()
  26. }
  27. .eraseToAnyPublisher()
  28. }
  29. }