71 lines
2.3 KiB
Objective-C
71 lines
2.3 KiB
Objective-C
//
|
|
// YMHomeSearchPresenter.m
|
|
// YUMI
|
|
//
|
|
// Created by YUMI on 2021/11/29.
|
|
//
|
|
|
|
#import "XPHomeSearchPresenter.h"
|
|
#import "Api+Home.h"
|
|
#import "Api+Mine.h"
|
|
#import "UserInfoModel.h"
|
|
#import <NIMSDK/NIMSDK.h>
|
|
#import "XPHomeSearchProtocol.h"
|
|
#import "AccountInfoStorage.h"
|
|
#import "HomeSearchResultModel.h"
|
|
#import "HomeRecommendRoomModel.h"
|
|
|
|
@implementation XPHomeSearchPresenter
|
|
|
|
|
|
/// 搜索房间或者用户
|
|
/// @param key 搜索的关键字
|
|
/// @param type 类型 1 房间 2 用户
|
|
- (void)searchRoomList:(NSString *)key type:(NSString *)type {
|
|
[Api searchComplection:[self createHttpCompletion:^(BaseModel * _Nonnull data) {
|
|
NSArray * array = [HomeSearchResultModel modelsWithArray:data.data];
|
|
[[self getView] searchRoomSuccess:array type:type];
|
|
} showLoading:YES] key:key type:type page:@"1" pageSize:@"50"];
|
|
}
|
|
|
|
/// 获取首页推荐列表
|
|
- (void)getHomeRecommendRoomList {
|
|
NSString * uid = [AccountInfoStorage instance].getUid;
|
|
[Api homeRecommendRoomList:[self createHttpCompletion:^(BaseModel * _Nonnull data) {
|
|
NSArray<HomeRecommendRoomModel *> * array = [HomeRecommendRoomModel modelsWithArray:data.data];
|
|
[[self getView] searchRoomGetRecommendSuccess:array];
|
|
}fail:^(NSInteger code, NSString * _Nullable msg) {
|
|
[[self getView] searchRoomGetRecommendFail];
|
|
}] uid:uid];
|
|
}
|
|
|
|
- (void)getFriends:(void(^)(NSArray <UserInfoModel *>*users))success
|
|
failure:(void(^)(NSError *error))failure {
|
|
NSArray * array = [[NIMSDK sharedSDK].userManager myFriends];
|
|
if (array.count > 0) {
|
|
NSMutableArray * uidsArray = [NSMutableArray array];
|
|
for (int i = 0; i< array.count; i++) {
|
|
NIMUser * user = [array xpSafeObjectAtIndex:i];
|
|
[uidsArray addObject:user.userId];
|
|
}
|
|
NSString *uids = [uidsArray componentsJoinedByString:@","];
|
|
[Api getUsersListInfo:[self createHttpCompletion:^(BaseModel * _Nonnull data) {
|
|
NSArray *users= [UserInfoModel modelsWithArray:data.data];
|
|
if (success) {
|
|
success(users);
|
|
}
|
|
} fail:^(NSInteger code, NSString * _Nullable msg) {
|
|
if (failure) {
|
|
failure([NSError errorWithDomain:msg code:code userInfo:nil]);
|
|
}
|
|
} showLoading:YES errorToast:YES] uids:uids];
|
|
} else {
|
|
if (success) {
|
|
success(@[]);
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@end
|