LNOrderRoomViewModel.swift 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. //
  2. // LNOrderRoomViewModel.swift
  3. // Gami
  4. //
  5. // Created by OneeChan on 2026/4/3.
  6. //
  7. import Foundation
  8. protocol LNOrderRoomViewModelNotify: LNRoomViewModelNotify {
  9. func onOrderRoomUserSeatApplyChanged(session: LNOrderRoomViewModel, apply: LNOrderRoomApplyingSeatType)
  10. }
  11. extension LNOrderRoomViewModelNotify {
  12. func onOrderRoomUserSeatApplyChanged(session: LNOrderRoomViewModel, apply: LNOrderRoomApplyingSeatType) { }
  13. }
  14. class LNOrderRoomViewModel: LNRoomSession {
  15. private(set) var waitingForSeat: LNOrderRoomApplyingSeatType = .none {
  16. didSet {
  17. if oldValue != waitingForSeat {
  18. LNEventDeliver.notifyEvent { ($0 as? LNOrderRoomViewModelNotify)?.onOrderRoomUserSeatApplyChanged(session: self, apply: self.waitingForSeat) }
  19. }
  20. }
  21. }
  22. override func handleSystemMessage(message: LNRoomPushMessage) {
  23. super.handleSystemMessage(message: message)
  24. if message.cmd == .MicClear,
  25. let cmd: LNRoomMicClearMessage = message.decodeCmdMessage(),
  26. cmd.type == self.waitingForSeat {
  27. self.waitingForSeat = .none
  28. }
  29. }
  30. }
  31. extension LNOrderRoomViewModel {
  32. // 申请列表
  33. func getApplyList(type: LNRoomApplySeatType, next: String?, filter: String?,
  34. handler: @escaping (LNRoomMicApplyListResponse?) -> Void) {
  35. LNHttpManager.shared.getApplySeatList(roomId: roomId, searchType: type, filter: filter,
  36. size: 30, next: next ?? "")
  37. { res, err in
  38. runOnMain {
  39. handler(res)
  40. }
  41. if let err {
  42. showToast(err.errorDesc)
  43. }
  44. }
  45. }
  46. // 申请列表的技能类别
  47. func getApplyListCategory(handler: @escaping (LNRoomGameCategoryResponse?) -> Void) {
  48. LNHttpManager.shared.getApplySeatCategory(roomId: roomId) { res, err in
  49. runOnMain {
  50. handler(res)
  51. }
  52. if let err {
  53. showToast(err.errorDesc)
  54. }
  55. }
  56. }
  57. // 用户列表
  58. func getRoomUserList(next: String?, playmete: Bool, filter: String?,
  59. handler: @escaping (LNRoomUserListResponse?) -> Void) {
  60. LNHttpManager.shared.getRoomUserList(
  61. roomId: roomId, size: 30, next: next ?? "",
  62. playmete: playmete, filter: filter)
  63. { res, err in
  64. runOnMain {
  65. handler(res)
  66. }
  67. if let err {
  68. showToast(err.errorDesc)
  69. }
  70. }
  71. }
  72. // 申请列表的技能类别
  73. func getPlaymateCategory(handler: @escaping (LNRoomGameCategoryResponse?) -> Void) {
  74. LNHttpManager.shared.getRoomPlaymateCategory(roomId: roomId) { res, err in
  75. runOnMain {
  76. handler(res)
  77. }
  78. if let err {
  79. showToast(err.errorDesc)
  80. }
  81. }
  82. }
  83. }
  84. extension LNOrderRoomViewModel: LNRoomViewModelNotify {
  85. func onRoomUserDidJoinOnSeat(session: LNRoomSession, newSeat: LNRoomSeatItem) {
  86. waitingForSeat = .none
  87. }
  88. func onRoomUserDidApplySeat(session: LNRoomSession, index: Int) {
  89. waitingForSeat = index == LNOrderRoomSeatNum.guest.rawValue ?
  90. .guest : index != LNOrderRoomSeatNum.host.rawValue ?
  91. .playmate : .none
  92. }
  93. func onRoomUserDidCancelApplySeat(session: LNRoomSession) {
  94. waitingForSeat = .none
  95. }
  96. }