| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231 |
- //
- // IMAContactManager+User.m
- // TIMChat
- //
- // Created by AlexiChen on 16/3/22.
- // Copyright © 2016年 AlexiChen. All rights reserved.
- //
- #import "IMAContactManager+User.h"
- @implementation IMAContactManager (User)
- - (void)asyncModify:(IMAUser *)user remark:(NSString *)remark succ:(TIMSucc)succ fail:(TIMFail)fail
- {
- if (!user)
- {
- DebugLog(@"参数有误");
- return;
- }
-
- if ([remark utf8Length] > 96)
- {
- [[BGHUDHelper sharedInstance] tipMessage:ASLocalizedString(@"备注名过长")];
- return;
- }
-
-
- __weak IMAContactManager *ws = self;
- [[TIMFriendshipManager sharedInstance] setFriendRemark:user.userId remark:remark succ:^{
- // 更新用户的名称
- user.remark = remark;
- [ws onFriendInfoChanged:user remark:remark];
- if (succ)
- {
- succ();
- }
- } fail:^(int code, NSString *err) {
- DebugLog(@"Fail:-->code=%d,msg=%@,fun=%s", code, err,__func__);
- [[BGHUDHelper sharedInstance] tipMessage:IMALocalizedError(code, err)];
-
- if (fail)
- {
- fail(code, err);
- }
- }];
-
- }
- - (void)asyncModify:(IMAUser *)user subgroup:(IMASubGroup *)sg succ:(TIMFriendSucc)succ fail:(TIMFail)fail
- {
- if (!user || !sg)
- {
- DebugLog(@"参数有误");
- return;
- }
-
-
-
- // TODO:等Tom新增默认分组接口
- IMASubGroup *sub = [self subGroupOf:user];
-
- if (!sub)
- {
- // 好友不存在分组中中
- DebugLog(@"参数有误");
- return;
- }
-
- if ([sub isEqual:sg])
- {
-
- [[BGHUDHelper sharedInstance] tipMessage:ASLocalizedString(@"用户已在该分组")];
- return;
- }
-
- if (sub.isDefaultSubGroup && !sg.isDefaultSubGroup)
- {
- // 从我的好友移动到分组
- [[TIMFriendshipManager sharedInstance] addFriendsToFriendGroup:sg.name users:@[user.userId] succ:^(NSArray *friends) {
- [[IMAPlatform sharedInstance].contactMgr onMove:user from:sub to:sg];
- if (succ)
- {
- succ(friends);
- }
- } fail:^(int code, NSString *err) {
- DebugLog(@"Fail:-->code=%d,msg=%@,fun=%s", code, err,__func__);
- [[BGHUDHelper sharedInstance] tipMessage:IMALocalizedError(code, err)];
-
- if (fail)
- {
- fail(code, err);
- }
- }];
- }
- else if (!sub.isDefaultSubGroup && !sg.isDefaultSubGroup)
- {
- //非默认分组之间的移动有两个步骤
- //1、将用户从当前分组移动到默认分组 2、将用户从默认分组移动到指定分组
- __weak IMASubGroup *wFromSubGroup = sub;
- __weak IMASubGroup *wToSubGroup = sg;
- __weak IMAUser *wu = user;
-
- [[TIMFriendshipManager sharedInstance] delFriendsFromFriendGroup:wFromSubGroup.name users:@[wu.userId] succ:^(NSArray *friends) {
-
- //从当前分组移动到默认分组
- [[TIMFriendshipManager sharedInstance] addFriendsToFriendGroup:wToSubGroup.name users:@[wu.userId] succ:^(NSArray *friends) {
-
- //从默认分组移动到指定分组
- [[IMAPlatform sharedInstance].contactMgr onMove:wu from:wFromSubGroup to:wToSubGroup];
- if (succ)
- {
- succ(friends);
- }
- } fail:^(int code, NSString *msg) {
- DebugLog(@"Fail: %d->%@", code, msg);
- //
- IMASubGroup *defaultGroup = [[IMAPlatform sharedInstance].contactMgr defaultAddToSubGroup];
- [[IMAPlatform sharedInstance].contactMgr onMove:wu from:wFromSubGroup to:defaultGroup];
-
- NSString *failInfo =ASLocalizedString( @"移动失败,已将好友移动到默认分组");
- NSString *errInfo = [NSString stringWithFormat:@"%@(%@)", IMALocalizedError(code, msg) ,failInfo];
- [[BGHUDHelper sharedInstance] tipMessage:errInfo];
-
- if (fail)
- {
- fail(code, msg);
- }
- }];
-
- } fail:^(int code, NSString *msg) {
- DebugLog(@"Fail: %d->%@", code, msg);
- [[BGHUDHelper sharedInstance] tipMessage:IMALocalizedError(code, msg)];
-
- if (fail)
- {
- fail(code, msg);
- }
- }];
- }
- else if (!sub.isDefaultSubGroup && sg.isDefaultSubGroup)
- {
- [[TIMFriendshipManager sharedInstance] delFriendsFromFriendGroup:sub.name users:@[user.userId] succ:^(NSArray *friends) {
- [[IMAPlatform sharedInstance].contactMgr onMove:user from:sub to:sg];
- if (succ)
- {
- succ(friends);
- }
- } fail:^(int code, NSString *err) {
- DebugLog(@"Fail:-->code=%d,msg=%@,fun=%s", code, err,__func__);
- [[BGHUDHelper sharedInstance] tipMessage:IMALocalizedError(code, err)];
-
- if (fail)
- {
- fail(code, err);
- }
- }];
- }
- else
- {
- // 都是我的好友分组中
- // 不作处理
- }
- }
- - (void)asyncMoveToBlackList:(IMAUser *)user succ:(TIMFriendSucc)succ fail:(TIMFail)fail
- {
- if (!user)
- {
- DebugLog(@"参数有误");
- if (fail)
- {
- fail(-1,ASLocalizedString( @"参数有误"));
- }
- return;
- }
- __weak IMAContactManager *ws = self;
- [[TIMFriendshipManager sharedInstance] addBlackList:@[user.userId] succ:^(NSArray *friends) {
- // 从好友分组中移除
- if (friends.count > 0)
- {
- TIMFriendResult *res = friends[0];
- IMAUser *user = [[IMAUser alloc] initWith:res.identifier];
- [ws removeUserToBlackList:user];
- if (succ)
- {
- succ(friends);
- }
- }
-
- } fail:^(int code, NSString *err) {
- DebugLog(@"Fail: %d->%@", code, err);
- if (fail)
- {
- fail(code, err);
- }
- }];
- }
- - (void)asyncMoveOutBlackList:(IMAUser *)user succ:(TIMFriendSucc)succ fail:(TIMFail)fail
- {
- if (!user)
- {
- DebugLog(@"参数有误");
- return;
- }
- __weak IMAContactManager *ws = self;
- [[TIMFriendshipManager sharedInstance] delBlackList:@[user.userId] succ:^(NSArray *friends) {
- // 从好友分组中移除
- [ws removeUserOutBlackList:user];
- if (succ)
- {
- succ(friends);
- }
-
- } fail:^(int code, NSString *err) {
- DebugLog(@"Fail:-->code=%d,msg=%@,fun=%s", code, err,__func__);
- [[BGHUDHelper sharedInstance] tipMessage:IMALocalizedError(code, err)];
-
- if (fail)
- {
- fail(code, err);
- }
- }];
-
- }
- @end
|