IMAHost+HostAPIs.m 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. //
  2. // IMAHost+HostAPIs.m
  3. // TIMChat
  4. //
  5. // Created by AlexiChen on 16/3/22.
  6. // Copyright © 2016年 AlexiChen. All rights reserved.
  7. //
  8. #import "IMAHost+HostAPIs.h"
  9. #ifndef kNicknameMaxLength
  10. #define kNicknameMaxLength 64
  11. #endif
  12. @implementation IMAHost (HostAPIs)
  13. - (void)asyncSetAllowType:(TIMFriendAllowType)type succ:(TIMSucc)succ fail:(TIMFail)fail
  14. {
  15. __weak IMAHost *ws = self;
  16. TIMFriendProfileOption *option = [[TIMFriendProfileOption alloc] init];
  17. option.friendFlags = TIM_PROFILE_FLAG_ALLOW_TYPE;
  18. option.friendCustom = nil;
  19. option.userCustom = nil;
  20. TIMUserProfile *profile = [[TIMUserProfile alloc] init];
  21. profile.allowType = type;
  22. [[TIMFriendshipManager sharedInstance] modifySelfProfile:option profile:profile succ:^{
  23. ws.profile.allowType = type;
  24. if (succ)
  25. {
  26. succ();
  27. }
  28. } fail:^(int code, NSString *msg) {
  29. DebugLog(@"code = %d, err = %@", code, msg);
  30. [[BGHUDHelper sharedInstance] tipMessage:IMALocalizedError(code, msg)];
  31. if (fail)
  32. {
  33. fail(code, msg);
  34. }
  35. }];
  36. }
  37. - (void)asyncSetNickname:(NSString *)nick succ:(TIMSucc)succ fail:(TIMFail)fail
  38. {
  39. if ([NSString isEmpty:nick])
  40. {
  41. [[BGHUDHelper sharedInstance] tipMessage:ASLocalizedString(@"昵称不能为空")];
  42. return;
  43. }
  44. if ([nick utf8Length] > kNicknameMaxLength)
  45. {
  46. [[BGHUDHelper sharedInstance] tipMessage:ASLocalizedString(@"昵称超过长度限制")];
  47. return;
  48. }
  49. __weak IMAHost *ws = self;
  50. TIMFriendProfileOption *option = [[TIMFriendProfileOption alloc] init];
  51. option.friendFlags = TIM_PROFILE_FLAG_NICK;
  52. option.friendCustom = nil;
  53. option.userCustom = nil;
  54. TIMUserProfile *profile = [[TIMUserProfile alloc] init];
  55. profile.nickname = nick;
  56. [[TIMFriendshipManager sharedInstance] modifySelfProfile:option profile:profile succ:^{
  57. //ws.nickName = nick;
  58. ws.profile.nickname = nick;
  59. if (succ)
  60. {
  61. succ();
  62. }
  63. } fail:^(int code, NSString *msg) {
  64. DebugLog(@"code = %d, err = %@", code, msg);
  65. [[BGHUDHelper sharedInstance] tipMessage:IMALocalizedError(code, msg)];
  66. if (fail)
  67. {
  68. fail(code, msg);
  69. }
  70. }];
  71. }
  72. @end