IMAPlatform+FriendShip.m 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659
  1. //
  2. // IMAPlatform+FriendShip.m
  3. // TIMChat
  4. //
  5. // Created by AlexiChen on 16/3/1.
  6. // Copyright © 2016年 AlexiChen. All rights reserved.
  7. //
  8. #import "IMAPlatform+FriendShip.h"
  9. @implementation IMAPlatform (FriendShip)
  10. //- (NSArray *)changeToUsers:(NSArray *)userProfiles
  11. //{
  12. // if (userProfiles.count)
  13. // {
  14. // NSMutableArray *array = [NSMutableArray array];
  15. // for (TIMUserProfile *pro in userProfiles)
  16. // {
  17. // IMAUser *user = [[IMAUser alloc] initWithUserInfo:pro];
  18. // [array addObject:user];
  19. // }
  20. //
  21. // return array;
  22. // }
  23. // return nil;
  24. //}
  25. - (void)asyncSearchUserBy:(NSString *)key with:(RequestPageParamItem *)page succ:(TIMFriendSucc)succ fail:(TIMFail)fail
  26. {
  27. if ([NSString isEmpty:key])
  28. {
  29. DebugLog(@"key为空");
  30. return;
  31. }
  32. NSArray *accountIDs = @[key];
  33. NSString *phoneId = [NSString stringWithFormat:@"86-%@", key];
  34. NSArray *phoneIDs = @[phoneId];
  35. [[TIMFriendshipManager sharedInstance] getUsersProfile:accountIDs succ:^(NSArray *data) {
  36. if (succ)
  37. {
  38. succ(data);
  39. }
  40. } fail:^(int code, NSString *err) {
  41. DebugLog(@"Fail: %d->%@", code, err);
  42. [[TIMFriendshipManager sharedInstance] getUsersProfile:phoneIDs succ:^(NSArray *data){
  43. if (succ)
  44. {
  45. succ(data);
  46. }
  47. } fail:^(int code, NSString *err) {
  48. DebugLog(@"Fail: %d->%@", code, err);
  49. [[TIMFriendshipManager sharedInstance] searchUser:key pageIndex:page.pageIndex pageSize:page.pageSize succ:^(uint64_t totalNum, NSArray *data) {
  50. page.pageIndex++;
  51. if (data.count < page.pageSize)
  52. {
  53. page.canLoadMore = NO;
  54. }
  55. if (succ)
  56. {
  57. succ(data);
  58. }
  59. } fail:^(int code, NSString *err) {
  60. DebugLog(@"Fail: %d->%@", code, err);
  61. page.canLoadMore = NO;
  62. if (fail)
  63. {
  64. fail(code, err);
  65. }
  66. }];
  67. }];
  68. }];
  69. }
  70. - (void)asyncSearchGroupBy:(NSString *)key with:(RequestPageParamItem *)page succ:(TIMGroupListSucc)succ fail:(TIMFail)fail
  71. {
  72. if ([NSString isEmpty:key])
  73. {
  74. DebugLog(@"key为空");
  75. return;
  76. }
  77. NSArray *groups = @[key];
  78. __weak NSArray *wg = groups;
  79. [[TIMGroupManager sharedInstance] getGroupPublicInfo:wg succ:^(NSArray *arr) {
  80. if (succ)
  81. {
  82. succ(arr);
  83. }
  84. } fail:^(int code, NSString *msg) {
  85. DebugLog(@"Fail: %d->%@", code, msg);
  86. [[TIMGroupManager sharedInstance] searchGroup:key
  87. flags:TIM_GET_GROUP_BASE_INFO_FLAG_NAME | TIM_GET_GROUP_BASE_INFO_FLAG_MEMBER_NUM
  88. | TIM_GET_GROUP_BASE_INFO_FLAG_FACE_URL | TIM_GET_GROUP_BASE_INFO_FLAG_OWNER_UIN
  89. | TIM_GET_GROUP_BASE_INFO_FLAG_CREATE_TIME
  90. custom:nil
  91. pageIndex:(uint32_t)page.pageIndex
  92. pageSize:(uint32_t)page.pageSize
  93. succ:^(uint64_t totalNum, NSArray *groups) {
  94. if (groups.count < page.pageSize)
  95. {
  96. page.canLoadMore = NO;
  97. }
  98. if (succ)
  99. {
  100. succ(groups);
  101. }
  102. } fail:^(int code, NSString *msg) {
  103. DebugLog(@"Fail: %d->%@", code, msg);
  104. page.canLoadMore = NO;
  105. if (fail)
  106. {
  107. fail(code, msg);
  108. }
  109. }];
  110. }];
  111. }
  112. - (void)asyncSendAddFriend:(IMAUser *)user withRemark:(NSString *)remark applyInfo:(NSString *)apinfo toSubGroup:(IMASubGroup *)group succ:(TIMFriendSucc)succ fail:(TIMFail)fail
  113. {
  114. // 1. 先检查是否是黑名单中,如果在,则不添加
  115. if ([remark isContainsEmoji])
  116. {
  117. [BGHUDHelper alert:ASLocalizedString(@"备注名不能包含表情")];
  118. return;
  119. }
  120. if ([remark utf8Length] > 96) {
  121. [BGHUDHelper alert:ASLocalizedString(@"备注名超长")];
  122. return;
  123. }
  124. if ([apinfo utf8Length] > 120)
  125. {
  126. [BGHUDHelper alert:ASLocalizedString(@"验证信息过长")];
  127. return;
  128. }
  129. TIMAddFriendRequest *req = [[TIMAddFriendRequest alloc] init];
  130. req.identifier = [user userId];
  131. req.remark = remark;
  132. req.addWording = apinfo;
  133. req.friendGroup = group ? group.name ? group.name : @"" : @"";
  134. __weak IMASubGroup *wsg = group;
  135. [[TIMFriendshipManager sharedInstance] addFriend:@[req] succ:^(NSArray *data) {
  136. if (succ)
  137. {
  138. NSMutableArray *sussResults = [NSMutableArray array];
  139. for (TIMFriendResult *res in data)
  140. {
  141. if (res.status == TIM_FRIEND_STATUS_SUCC)
  142. {
  143. [sussResults addObject:res];
  144. [[IMAPlatform sharedInstance] asyncGetFirendInfo:res.identifier succ:^(IMAUser *auser) {
  145. [[IMAPlatform sharedInstance].contactMgr addUser:user toSubGroup:wsg];
  146. } fail:^(int code, NSString *msg) {
  147. NSString *errinfo = [NSString stringWithFormat:ASLocalizedString(@"添加好友成功后,获取好友资料失败,%@"),IMALocalizedError(code, msg)];
  148. DebugLog(@"%@",errinfo);
  149. [[BGHUDHelper sharedInstance] tipMessage:errinfo];
  150. }];
  151. }
  152. else
  153. {
  154. [[BGHUDHelper sharedInstance] tipMessage:IMALocalizedError(res.status, msg) delay:1.0];
  155. }
  156. }
  157. succ(sussResults);
  158. }
  159. } fail:^(int code, NSString *msg) {
  160. DebugLog(@"Fail: %d->%@", code, msg);
  161. [[BGHUDHelper sharedInstance] tipMessage:IMALocalizedError(code, msg)];
  162. if (fail)
  163. {
  164. fail(code, msg);
  165. }
  166. }];
  167. }
  168. - (void)asyncFriendPendencyReport:(uint64_t)timestamp succ:(TIMSucc)succ fail:(TIMFail)fail
  169. {
  170. if (timestamp <= 0)
  171. {
  172. DebugLog(@"参数错误");
  173. return;
  174. }
  175. [[TIMFriendshipManager sharedInstance] pendencyReport:timestamp succ:^{
  176. if (succ)
  177. {
  178. succ();
  179. }
  180. } fail:^(int code, NSString *msg) {
  181. DebugLog(@"Fail: %d->%@", code, msg);
  182. [[BGHUDHelper sharedInstance] tipMessage:IMALocalizedError(code, msg)];
  183. if (fail)
  184. {
  185. fail(code, msg);
  186. }
  187. }];
  188. }
  189. - (void)asyncGetAllFriendPendency:(TIMFriendFutureMeta *)meta succ:(TIMGetFriendFutureListSucc)succ fail:(TIMFail)fail
  190. {
  191. if (meta)
  192. {
  193. [self asyncGetAllFutureFriends:TIM_FUTURE_FRIEND_PENDENCY_IN_TYPE meta:meta succ:succ fail:nil];
  194. }
  195. }
  196. - (void)asyncGetAllFutureFriends:(TIMFutureFriendType)futureFlag meta:(TIMFriendFutureMeta *)meta succ:(TIMGetFriendFutureListSucc)succ fail:(TIMFail)fail
  197. {
  198. if (meta)
  199. {
  200. NSInteger tag = TIM_PROFILE_FLAG_NICK | TIM_PROFILE_FLAG_ALLOW_TYPE | TIM_PROFILE_FLAG_FACE_URL | TIM_PROFILE_FLAG_REMARK;
  201. [[TIMFriendshipManager sharedInstance] getFutureFriends:tag futureFlag:futureFlag custom:nil meta:meta succ:succ fail:^(int code, NSString *msg) {
  202. DebugLog(@"Fail:--> code=%d,msg=%@,fun=%s", code, msg,__func__);
  203. [[BGHUDHelper sharedInstance] tipMessage:IMALocalizedError(code, msg)];
  204. if (fail)
  205. {
  206. fail(code, msg);
  207. }
  208. }];
  209. }
  210. }
  211. - (void)asyncDeleteFriendPendency:(TIMFriendPendencyItem *)item succ:(TIMFriendSucc)succ fail:(TIMFail)fail
  212. {
  213. if(item)
  214. {
  215. [[TIMFriendshipManager sharedInstance] deletePendency:item.type users:@[item.identifier] succ:succ fail:^(int code, NSString *err){
  216. DebugLog(@"Fail:-->code=%d,msg=%@,fun=%s", code, err,__func__);
  217. [[BGHUDHelper sharedInstance] tipMessage:IMALocalizedError(code, err)];
  218. if (fail)
  219. {
  220. fail(code, err);
  221. }
  222. }];
  223. }
  224. }
  225. - (void)asyncApplyAddFriend:(IMAUser *)item succ:(TIMFriendSucc)succ fail:(TIMFail)fail
  226. {
  227. [self asyncApplyAddFriend:item withRemark:nil succ:succ fail:fail];
  228. }
  229. - (void)asyncApplyAddFriend:(IMAUser *)item withRemark:(NSString *)remark succ:(TIMFriendSucc)succ fail:(TIMFail)fail
  230. {
  231. if ([remark utf8Length] > 96)
  232. {
  233. DebugLog(@"remark过长");
  234. return;
  235. }
  236. if(item)
  237. {
  238. TIMFriendResponse *response = [[TIMFriendResponse alloc] init];
  239. response.identifier = [item userId];
  240. response.remark = remark;
  241. response.responseType = TIM_FRIEND_RESPONSE_AGREE_AND_ADD;
  242. [[TIMFriendshipManager sharedInstance] doResponse:@[response] succ:^(NSArray *data) {
  243. if (succ)
  244. {
  245. succ(data);
  246. }
  247. } fail:^(int code, NSString *err) {
  248. DebugLog(@"Fail:-->code=%d,msg=%@,fun=%s", code, err,__func__);
  249. [[BGHUDHelper sharedInstance] tipMessage:IMALocalizedError(code, err)];
  250. if (fail)
  251. {
  252. fail(code, err);
  253. }
  254. }];
  255. }
  256. }
  257. - (void)asyncApplyAddFriendWithId:(NSString *)userid succ:(TIMFriendSucc)succ fail:(TIMFail)fail
  258. {
  259. if(![NSString isEmpty:userid])
  260. {
  261. TIMFriendResponse *response = [[TIMFriendResponse alloc] init];
  262. response.identifier = userid;
  263. response.responseType = TIM_FRIEND_RESPONSE_AGREE_AND_ADD;
  264. [[TIMFriendshipManager sharedInstance] doResponse:@[response] succ:^(NSArray *data) {
  265. if (succ)
  266. {
  267. succ(data);
  268. }
  269. } fail:^(int code, NSString *err) {
  270. DebugLog(@"Fail:-->code=%d,msg=%@,fun=%s", code, err,__func__);
  271. [[BGHUDHelper sharedInstance] tipMessage:IMALocalizedError(code, err)];
  272. if (fail)
  273. {
  274. fail(code, err);
  275. }
  276. }];
  277. }
  278. }
  279. - (void)asyncRefuseFriend:(TIMUserProfile *)item succ:(TIMFriendSucc)succ fail:(TIMFail)fail
  280. {
  281. if(item)
  282. {
  283. TIMFriendResponse *response = [[TIMFriendResponse alloc] init];
  284. response.identifier = item.identifier;
  285. response.responseType = TIM_FRIEND_RESPONSE_REJECT;
  286. [[TIMFriendshipManager sharedInstance] doResponse:@[response] succ:^(NSArray *data) {
  287. if (succ)
  288. {
  289. succ(data);
  290. }
  291. } fail:^(int code, NSString *err) {
  292. DebugLog(@"Fail:-->code=%d,msg=%@,fun=%s", code, err,__func__);
  293. [[BGHUDHelper sharedInstance] tipMessage:IMALocalizedError(code, err)];
  294. if (fail)
  295. {
  296. fail(code, err);
  297. }
  298. }];
  299. }
  300. }
  301. - (void)asyncGetFirendInfo:(NSString *)userid succ:(void (^)(IMAUser *auser))succ fail:(TIMFail)fail
  302. {
  303. if ([NSString isEmpty:userid])
  304. {
  305. if (succ)
  306. {
  307. succ(nil);
  308. }
  309. else
  310. {
  311. DebugLog(@"参数错误");
  312. }
  313. return;
  314. }
  315. [[TIMFriendshipManager sharedInstance] getFriendsProfile:@[userid] succ:^(NSArray *friends) {
  316. for (TIMUserProfile *pro in friends)
  317. {
  318. IMAUser *user = [[IMAUser alloc] initWithUserInfo:pro];
  319. if (succ)
  320. {
  321. succ(user);
  322. }
  323. break;
  324. }
  325. } fail:^(int code, NSString *msg) {
  326. DebugLog(@"Fail: %d->%@", code, msg);
  327. if (fail)
  328. {
  329. fail(code, msg);
  330. }
  331. }];
  332. }
  333. - (void)asyncGetStrangerInfo:(NSString *)userid succ:(void (^)(IMAUser *auser))succ fail:(TIMFail)fail
  334. {
  335. if ([NSString isEmpty:userid])
  336. {
  337. if (succ)
  338. {
  339. succ(nil);
  340. }
  341. else
  342. {
  343. DebugLog(@"参数错误");
  344. }
  345. return;
  346. }
  347. [[TIMFriendshipManager sharedInstance] getFriendsProfile:@[userid] succ:^(NSArray *friends) {
  348. for (TIMUserProfile *pro in friends)
  349. {
  350. IMAUser *user = [[IMAUser alloc] initWithUserInfo:pro];
  351. if (succ)
  352. {
  353. succ(user);
  354. }
  355. break;
  356. }
  357. } fail:^(int code, NSString *msg) {
  358. DebugLog(@"Fail: %d->%@", code, msg);
  359. if (fail)
  360. {
  361. fail(code, msg);
  362. }
  363. }];
  364. }
  365. - (void)asyncDeleteFutureFriend:(TIMFriendFutureItem *)item succ:(TIMFriendSucc)succ fail:(TIMFail)fail
  366. {
  367. if(item)
  368. {
  369. switch (item.type)
  370. {
  371. case TIM_FUTURE_FRIEND_PENDENCY_IN_TYPE:
  372. case TIM_FUTURE_FRIEND_PENDENCY_OUT_TYPE:
  373. {
  374. [[TIMFriendshipManager sharedInstance] deletePendency:(TIMPendencyGetType)item.type users:@[item.identifier] succ:succ fail:^(int code, NSString *err){
  375. DebugLog(@"Fail:-->code=%d,msg=%@,fun=%s", code, err,__func__);
  376. [[BGHUDHelper sharedInstance] tipMessage:IMALocalizedError(code, err)];
  377. if (fail)
  378. {
  379. fail(code, err);
  380. }
  381. }];
  382. }
  383. break;
  384. case TIM_FUTURE_FRIEND_RECOMMEND_TYPE:
  385. {
  386. [[TIMFriendshipManager sharedInstance] deleteRecommend:@[item.identifier] succ:succ fail:^(int code, NSString *err){
  387. DebugLog(@"Fail:-->code=%d,msg=%@,fun=%s", code, err,__func__);
  388. [[BGHUDHelper sharedInstance] tipMessage:IMALocalizedError(code, err)];
  389. if (fail)
  390. {
  391. fail(code, err);
  392. }
  393. }];
  394. }
  395. break;
  396. case TIM_FUTURE_FRIEND_DECIDE_TYPE:
  397. {
  398. [[TIMFriendshipManager sharedInstance] deleteDecide:@[item.identifier] succ:succ fail:^(int code, NSString *err){
  399. DebugLog(@"Fail:-->code=%d,msg=%@,fun=%s", code, err,__func__);
  400. [[BGHUDHelper sharedInstance] tipMessage:IMALocalizedError(code, err)];
  401. if (fail)
  402. {
  403. fail(code, err);
  404. }
  405. }];
  406. }
  407. break;
  408. default:
  409. break;
  410. }
  411. }
  412. }
  413. - (void)asyncApplyAddFutureFriend:(TIMFriendFutureItem *)item succ:(TIMFriendSucc)succ fail:(TIMFail)fail
  414. {
  415. // 必须是TIM_FUTURE_FRIEND_PENDENCY_IN_TYPE
  416. if(item && item.type == TIM_FUTURE_FRIEND_PENDENCY_IN_TYPE)
  417. {
  418. IMAUser *u = [[IMAUser alloc] initWithUserInfo:item.profile];
  419. [self asyncApplyAddFriend:u withRemark:nil succ:^(NSArray *friends) {
  420. item.type = TIM_FUTURE_FRIEND_DECIDE_TYPE;
  421. IMAUser *user = [[IMAUser alloc] initWithUserInfo:item.profile];
  422. [[IMAPlatform sharedInstance].contactMgr addUserToDefaultSubGroup:user];
  423. if (succ)
  424. {
  425. succ(friends);
  426. }
  427. } fail:fail];
  428. }
  429. else
  430. {
  431. DebugLog(@"必须是TIM_FUTURE_FRIEND_PENDENCY_IN_TYPE");
  432. }
  433. }
  434. - (void)asyncRefuseFutureFriend:(TIMFriendFutureItem *)item succ:(TIMFriendSucc)succ fail:(TIMFail)fail
  435. {
  436. if(item && item.type == TIM_FUTURE_FRIEND_PENDENCY_IN_TYPE)
  437. {
  438. [self asyncRefuseFriend:item.profile succ:^(NSArray *friends) {
  439. item.type = TIM_FUTURE_FRIEND_DECIDE_TYPE;
  440. if (succ)
  441. {
  442. succ(friends);
  443. }
  444. } fail:fail];
  445. }
  446. else
  447. {
  448. DebugLog(@"必须是TIM_FUTURE_FRIEND_PENDENCY_IN_TYPE");
  449. }
  450. }
  451. - (void)asyncClearRecommonds:(NSArray *)recommonds succ:(TIMFriendSucc)succ fail:(TIMFail)fail
  452. {
  453. if (recommonds.count > 0)
  454. {
  455. __weak IMAPlatform *ws = self;
  456. [[TIMFriendshipManager sharedInstance] deleteRecommend:recommonds succ:^(NSArray *friends) {
  457. if (succ)
  458. {
  459. NSMutableArray *results = [ws filterResult:friends];
  460. succ(results);
  461. }
  462. } fail:^(int code, NSString *msg) {
  463. DebugLog(@"删除推荐好友失败,code=%d,msg=%@",code,msg);
  464. [[BGHUDHelper sharedInstance] tipMessage:[NSString stringWithFormat:ASLocalizedString(@"删除推荐好友失败,code=%d,msg=%@"),code,msg]];
  465. if (fail)
  466. {
  467. fail(code,msg);
  468. }
  469. }];
  470. }
  471. }
  472. - (void)asyncClearPendencysIn:(NSArray *)pendencys isInPendency:(BOOL)isIn succ:(TIMFriendSucc)succ fail:(TIMFail)fail
  473. {
  474. if (pendencys.count > 0)
  475. {
  476. DebugLog(@"DeletePendencys font");
  477. __weak IMAPlatform *ws = self;
  478. [[TIMFriendshipManager sharedInstance] deletePendency:isIn ? TIM_PENDENCY_GET_COME_IN : TIM_PENDENCY_GET_SEND_OUT users:pendencys succ:^(NSArray *friends) {
  479. DebugLog(@"DeletePendencys succ");
  480. if (succ)
  481. {
  482. NSMutableArray *results = [ws filterResult:friends];
  483. succ(results);
  484. }
  485. } fail:^(int code, NSString *msg) {
  486. DebugLog(@"删除未决好友失败,code=%d,msg=%@",code,msg);
  487. [[BGHUDHelper sharedInstance] tipMessage:[NSString stringWithFormat:ASLocalizedString(@"删除未决好友失败,code=%d,msg=%@"),code,msg]];
  488. if (fail)
  489. {
  490. fail(code,msg);
  491. }
  492. }];
  493. DebugLog(@"DeletePendencys rail");
  494. }
  495. }
  496. - (void)asyncClearDecides:(NSArray *)decides succ:(TIMFriendSucc)succ fail:(TIMFail)fail
  497. {
  498. if (decides.count > 0)
  499. {
  500. DebugLog(@"DeleteDecide front");
  501. __weak IMAPlatform *ws = self;
  502. [[TIMFriendshipManager sharedInstance] deleteDecide:decides succ:^(NSArray *friends) {
  503. DebugLog(@"DeleteDecide succ");
  504. if (succ)
  505. {
  506. NSMutableArray *results = [ws filterResult:friends];
  507. succ(results);
  508. }
  509. } fail:^(int code, NSString *msg) {
  510. DebugLog(@"删除已决好友失败,code=%d,msg=%@",code,msg);
  511. [[BGHUDHelper sharedInstance] tipMessage:[NSString stringWithFormat:ASLocalizedString(@"删除已决好友失败,code=%d,msg=%@"),code,msg]];
  512. if (fail)
  513. {
  514. fail(code,msg);
  515. }
  516. }];
  517. DebugLog(@"DeleteDecide rail");
  518. }
  519. }
  520. - (NSMutableArray *)filterResult:(NSArray *)array
  521. {
  522. NSMutableArray *results = [NSMutableArray array];
  523. for (TIMFriendResult *result in array)
  524. {
  525. if (result.status == TIM_FRIEND_STATUS_SUCC)
  526. {
  527. IMAUser *user = [[IMAUser alloc] initWith:result.identifier];
  528. [results addObject:user];
  529. }
  530. }
  531. return results;
  532. }
  533. - (void)asyncGetSystemMessages:(RequestPageParamItem *)item last:(IMAMsg*)lastMsg succ:(TIMGetMsgSucc)succ fail:(TIMFail)fail
  534. {
  535. TIMConversation* conversation = [[TIMManager sharedInstance] getConversation:TIM_SYSTEM receiver:@""];
  536. __block IMAMsg *wm = lastMsg;
  537. [conversation getMessage:(int)item.pageSize
  538. last:(lastMsg ? lastMsg.msg : nil)
  539. succ:^(NSArray *msgList) {
  540. NSInteger index = 0;
  541. NSMutableArray *msgs = [NSMutableArray array];
  542. while (index < msgList.count)
  543. {
  544. TIMMessage *msg = [msgList objectAtIndex:index];
  545. if (msg.isSelf)
  546. {
  547. index++;
  548. continue;
  549. }
  550. for (int i=0; i < [msg elemCount]; i++)
  551. {
  552. TIMElem *elem = [msg getElem:i];
  553. if ([elem isKindOfClass:[TIMSNSSystemElem class]])
  554. {
  555. TIM_SNS_SYSTEM_TYPE type = ((TIMSNSSystemElem *)elem).type;
  556. if (type == TIM_SNS_SYSTEM_ADD_FRIEND_REQ || type == TIM_SNS_SYSTEM_ADD_FRIEND)
  557. {
  558. [msgs addObject:[IMAMsg msgWith:msg]];
  559. }
  560. }
  561. else if ([elem isKindOfClass:[TIMGroupSystemElem class]])
  562. {
  563. TIM_GROUP_SYSTEM_TYPE type = ((TIMGroupSystemElem *)elem).type;
  564. if (type == TIM_GROUP_SYSTEM_ADD_GROUP_REQUEST_TYPE)
  565. {
  566. [msgs addObject:[IMAMsg msgWith:msg]];
  567. }
  568. }
  569. }
  570. index++;
  571. }
  572. if (msgList.count > 0)
  573. {
  574. TIMMessage *msg = [msgList objectAtIndex:index-1];
  575. wm = [IMAMsg msgWith:msg];
  576. }
  577. if (succ)
  578. {
  579. succ(msgs);
  580. }
  581. }
  582. fail:^(int code, NSString *err) {
  583. DebugLog(@"Fail:-->code=%d,msg=%@,fun=%s", code, err,__func__);
  584. [[BGHUDHelper sharedInstance] tipMessage:IMALocalizedError(code, err)];
  585. if (fail)
  586. {
  587. fail(code, err);
  588. }
  589. }];
  590. }
  591. @end