123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103 |
- //
- // XYVoiceMatchViewModel.m
- // Starbuds
- //
- // Created by 翟玉磊 on 2020/12/4.
- // Copyright © 2020 翟玉磊. All rights reserved.
- //
- #import "XYVoiceMatchViewModel.h"
- @implementation XYVoiceMatchViewModel
- - (instancetype)init
- {
- self = [super init];
- if (self) {
- [self initValue];
- }
- return self;
- }
- - (void)initValue {
-
- // 默认状态
- self.matchStatus = XYVoiceMatchingStatusNormal;
- // 默认只看女生
- self.filterType = XYVoiceMatchingFilterTypeAll;
- self.freeTime = 0;
- }
- - (void)loadData:(SuccessHandler)success failure:(FailureHandler)failure {
- // 获取语音配置
- [[XYChatAPIManager new] getVoiceChatConfigSuccessHandler:^(ZYLResponseModel *responseModel) {
-
- self.freeTime = [responseModel.data[@"freeTime"] integerValue];
- self.voiceChatPriceName = [BaseMethod toString:responseModel.data[@"voiceChatPriceName"]];
- self.voiceChatPrice = [BaseMethod toString:responseModel.data[@"voiceChatPrice"]];
- !success?:success(responseModel);
- } failureHandler:^(ZYLNetworkError *error) {
- !failure?:failure(error);
- }];
- }
- /// 发起速配
- - (void)sendVoiceMatch:(SuccessHandler)success failure:(FailureHandler)failure {
- [[XYChatAPIManager new] sendVoiceMatchWithUserSex:self.filterType successHandler:^(ZYLResponseModel *responseModel) {
- self.matchStatus = XYVoiceMatchingStatusOpenMatching;
- self.hisId = [BaseMethod toString:responseModel.data[@"hisId"]];
- !success?:success(responseModel);
- } failureHandler:^(ZYLNetworkError *error) {
- !failure?:failure(error);
- }];
- }
- /// 取消速配
- - (void)cancelVoiceMatch:(SuccessHandler)success failure:(FailureHandler)failure {
- if (StringIsEmpty(self.hisId)) {
- self.matchStatus = XYVoiceMatchingStatusNormal;
- !success?:success(nil);
- return;
- }
- [[XYChatAPIManager new] cancelVoiceChatWithHisId:self.hisId successHandler:^(ZYLResponseModel *responseModel) {
- self.hisId = @"";
- self.matchStatus = XYVoiceMatchingStatusNormal;
- !success?:success(responseModel);
- } failureHandler:^(ZYLNetworkError *error) {
- !failure?:failure(error);
- }];
- }
- //获取符合条件用户(头像信息)
- - (void)getMatchUserList:(SuccessHandler)success failure:(FailureHandler)failure{
- NSMutableDictionary *parm = [[NSMutableDictionary alloc] init];
- [parm setValue:@(self.filterType) forKey:@"userSex"];
- [[XYChatAPIManager new] getMatchUserList:parm successHandler:^(ZYLResponseModel *responseModel) {
- [self.matchUserArray removeAllObjects];
- for (NSDictionary *dict in responseModel.data[@"list"]) {
- XYUserModel *model = [[XYUserModel alloc] init];
- [model yy_modelSetWithDictionary:dict];
- model.niceNo = [BaseMethod toString:dict[@"roomId"]];
- [self.matchUserArray addObject:model];
- }
- !success?:success(responseModel);
- } failureHandler:^(ZYLNetworkError *error) {
- !failure?:failure(error);
- }];
- }
- //获取匹配成功记录
- - (void)getMatchSuccessList:(SuccessHandler)success failure:(FailureHandler)failure{
- [[XYChatAPIManager new] getMatchSuccessList:nil successHandler:^(ZYLResponseModel *responseModel) {
- !success?:success(responseModel);
- } failureHandler:^(ZYLNetworkError *error) {
- !failure?:failure(error);
- }];
- }
- - (NSMutableArray *)matchUserArray {
- if (!_matchUserArray) {
- _matchUserArray = [NSMutableArray array];
- }
- return _matchUserArray;
- }
- @end
|