cdts/xdts-ios 3/TreeHole/Code/Features/Chat/ChatService.m
2023-07-27 09:20:00 +08:00

110 lines
3.7 KiB
Objective-C

//
// ChatService.m
// Youth
//
// Created by mambaxie on 2022/1/22.
//
#import "ChatService.h"
@implementation ChatService
/// 解散群
+ (void)destoryGroupWithGroupID:(NSString *)groupID completion:(PYHTTPManagerCallback)completion {
[PYHTTPManager postWithPath:@"groupdestroy" params:@{
@"im_group_id": groupID ?: @""
} callback:completion];
}
+ (void)exitGroupWithGroupID:(NSString *)groupID completion:(PYHTTPManagerCallback)completion {
[PYHTTPManager postWithPath:@"groupexit" params:@{
@"im_group_id": groupID ?: @""
} callback:completion];
}
/// 获取群信息
+ (void)getGroupInfoWithConversationData:(TUIChatConversationModel *)conversationData completion:(void(^)(GroupInfo *info))completion {
int shouldHandleCount = 4;
__block int handledCount = 0;
GroupInfo *info = [[GroupInfo alloc] init];
NSString *groupID = conversationData.groupID;
info.group_id = groupID;
[self getGroupMembersWithGroupID:groupID pageIndex:0 completion:^(NSArray<User *> * _Nonnull users, int totalSize) {
handledCount++;
info.users = users;
if (handledCount >= shouldHandleCount && completion) {
completion(info);
}
}];
[PYHTTPManager postWithPath:@"groupactivitylist" params:@{
@"im_group_id": groupID ?: @"",
@"paze_size": @(3),
@"tail_act_id": @(0)
} callback:^(id _Nullable rsp, NSError * _Nullable error) {
if (!error) {
info.group_name = rsp[@"group_name"];
}
handledCount++;
if (handledCount >= shouldHandleCount && completion) {
completion(info);
}
}];
[[V2TIMManager sharedInstance] getConversation:conversationData.conversationID succ:^(V2TIMConversation *conv) {
handledCount++;
info.conversation = conv;
if (handledCount >= shouldHandleCount && completion) {
completion(info);
}
} fail:^(int code, NSString *desc) {
[SVProgressHUD showErrorWithStatus:desc?:@"未知错误"];
handledCount++;
if (handledCount >= shouldHandleCount && completion) {
completion(info);
}
}];
[[V2TIMManager sharedInstance] getGroupsInfo:@[conversationData.groupID?:@""] succ:^(NSArray<V2TIMGroupInfoResult *> *groupResultList) {
handledCount++;
info.imGroupInfo = groupResultList.firstObject.info;
if (handledCount >= shouldHandleCount && completion) {
completion(info);
}
} fail:^(int code, NSString *desc) {
[SVProgressHUD showErrorWithStatus:desc?:@"未知错误"];
handledCount++;
if (handledCount >= shouldHandleCount && completion) {
completion(info);
}
}];
}
/// 获取群成员
+ (void)getGroupMembersWithGroupID:(NSString *)groupID pageIndex:(int)pageIndex completion:(void(^)(NSArray<User *> *users, int totalSize))completion {
[PYHTTPManager postWithPath:@"groupmemberlist" params:@{
@"im_group_id": groupID ?: @"",
@"page_size": @(20),
@"page": @(pageIndex)
} callback:^(id _Nullable rsp, NSError * _Nullable error) {
if (!completion) {
return;
}
if (!error) {
completion([User mj_objectArrayWithKeyValuesArray:rsp[@"data"]], [rsp[@"total_count"] intValue]);
} else {
completion(nil, 0);
}
}];
}
/// 修改群名称
+ (void)setGropuNameGroupID:(NSString *)groupID name:(NSString *)name completion:(PYHTTPManagerCallback)completion {
[PYHTTPManager postWithPath:@"groupupdate" params:@{
@"im_group_id": groupID ?: @"",
@"name": name ?: @""
} callback:completion];
}
@end