XYVoiceMatchViewModel.m 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. //
  2. // XYVoiceMatchViewModel.m
  3. // Starbuds
  4. //
  5. // Created by 翟玉磊 on 2020/12/4.
  6. // Copyright © 2020 翟玉磊. All rights reserved.
  7. //
  8. #import "XYVoiceMatchViewModel.h"
  9. @implementation XYVoiceMatchViewModel
  10. - (instancetype)init
  11. {
  12. self = [super init];
  13. if (self) {
  14. [self initValue];
  15. }
  16. return self;
  17. }
  18. - (void)initValue {
  19. // 默认状态
  20. self.matchStatus = XYVoiceMatchingStatusNormal;
  21. // 默认只看女生
  22. self.filterType = XYVoiceMatchingFilterTypeAll;
  23. self.freeTime = 0;
  24. }
  25. - (void)loadData:(SuccessHandler)success failure:(FailureHandler)failure {
  26. // 获取语音配置
  27. [[XYChatAPIManager new] getVoiceChatConfigSuccessHandler:^(ZYLResponseModel *responseModel) {
  28. self.freeTime = [responseModel.data[@"freeTime"] integerValue];
  29. self.voiceChatPriceName = [BaseMethod toString:responseModel.data[@"voiceChatPriceName"]];
  30. self.voiceChatPrice = [BaseMethod toString:responseModel.data[@"voiceChatPrice"]];
  31. !success?:success(responseModel);
  32. } failureHandler:^(ZYLNetworkError *error) {
  33. !failure?:failure(error);
  34. }];
  35. }
  36. /// 发起速配
  37. - (void)sendVoiceMatch:(SuccessHandler)success failure:(FailureHandler)failure {
  38. [[XYChatAPIManager new] sendVoiceMatchWithUserSex:self.filterType successHandler:^(ZYLResponseModel *responseModel) {
  39. self.matchStatus = XYVoiceMatchingStatusOpenMatching;
  40. self.hisId = [BaseMethod toString:responseModel.data[@"hisId"]];
  41. !success?:success(responseModel);
  42. } failureHandler:^(ZYLNetworkError *error) {
  43. !failure?:failure(error);
  44. }];
  45. }
  46. /// 取消速配
  47. - (void)cancelVoiceMatch:(SuccessHandler)success failure:(FailureHandler)failure {
  48. if (StringIsEmpty(self.hisId)) {
  49. self.matchStatus = XYVoiceMatchingStatusNormal;
  50. !success?:success(nil);
  51. return;
  52. }
  53. [[XYChatAPIManager new] cancelVoiceChatWithHisId:self.hisId successHandler:^(ZYLResponseModel *responseModel) {
  54. self.hisId = @"";
  55. self.matchStatus = XYVoiceMatchingStatusNormal;
  56. !success?:success(responseModel);
  57. } failureHandler:^(ZYLNetworkError *error) {
  58. !failure?:failure(error);
  59. }];
  60. }
  61. //获取符合条件用户(头像信息)
  62. - (void)getMatchUserList:(SuccessHandler)success failure:(FailureHandler)failure{
  63. NSMutableDictionary *parm = [[NSMutableDictionary alloc] init];
  64. [parm setValue:@(self.filterType) forKey:@"userSex"];
  65. [[XYChatAPIManager new] getMatchUserList:parm successHandler:^(ZYLResponseModel *responseModel) {
  66. [self.matchUserArray removeAllObjects];
  67. for (NSDictionary *dict in responseModel.data[@"list"]) {
  68. XYUserModel *model = [[XYUserModel alloc] init];
  69. [model yy_modelSetWithDictionary:dict];
  70. model.niceNo = [BaseMethod toString:dict[@"roomId"]];
  71. [self.matchUserArray addObject:model];
  72. }
  73. !success?:success(responseModel);
  74. } failureHandler:^(ZYLNetworkError *error) {
  75. !failure?:failure(error);
  76. }];
  77. }
  78. //获取匹配成功记录
  79. - (void)getMatchSuccessList:(SuccessHandler)success failure:(FailureHandler)failure{
  80. [[XYChatAPIManager new] getMatchSuccessList:nil successHandler:^(ZYLResponseModel *responseModel) {
  81. !success?:success(responseModel);
  82. } failureHandler:^(ZYLNetworkError *error) {
  83. !failure?:failure(error);
  84. }];
  85. }
  86. - (NSMutableArray *)matchUserArray {
  87. if (!_matchUserArray) {
  88. _matchUserArray = [NSMutableArray array];
  89. }
  90. return _matchUserArray;
  91. }
  92. @end