IMAHost.m 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. //
  2. // IMAHost.m
  3. // TIMAdapter
  4. //
  5. // Created by AlexiChen on 16/1/29.
  6. // Copyright © 2016年 AlexiChen. All rights reserved.
  7. //
  8. #import "IMAHost.h"
  9. @implementation IMAHost
  10. - (void)getMyInfo:(AppCommonBlock)block
  11. {
  12. _reloadUserInfoTimes ++;
  13. NSMutableDictionary *mDict = [NSMutableDictionary dictionary];
  14. [mDict setObject:@"user" forKey:@"ctl"];
  15. [mDict setObject:@"userinfo" forKey:@"act"];
  16. FWWeakify(self)
  17. [[NetHttpsManager manager] POSTWithParameters:mDict SuccessBlock:^(NSDictionary *responseJson) {
  18. FWStrongify(self)
  19. NSDictionary *user = [responseJson objectForKey:@"user"];
  20. if (user && [user isKindOfClass:[NSDictionary class]])
  21. {
  22. UserModel *model = [UserModel mj_objectWithKeyValues:user];
  23. [GlobalVariables sharedInstance].is_noble_mysterious = model.is_noble_mysterious;
  24. [GlobalVariables sharedInstance].userModel = model;
  25. TIMUserProfile *selfProfile = [[TIMUserProfile alloc]init];
  26. selfProfile.identifier = [user toString:@"user_id"];
  27. selfProfile.nickname = [user toString:@"nick_name"];
  28. selfProfile.faceURL = [user toString:@"head_image"];
  29. self.is_robot = [[user toString:@"is_robot"] boolValue];
  30. self.profile = selfProfile;
  31. self.profile.customInfo = user;
  32. self.customInfoDict = [NSMutableDictionary dictionaryWithDictionary:user];
  33. if (block)
  34. {
  35. AppBlockModel *blockModel = [AppBlockModel manager];
  36. blockModel.retDict = responseJson;
  37. blockModel.status = 1;
  38. block(blockModel);
  39. }
  40. }
  41. else
  42. {
  43. if (_reloadUserInfoTimes < 10)
  44. {
  45. [self performSelector:@selector(getMyInfo:) withObject:nil afterDelay:1];
  46. }
  47. if (block)
  48. {
  49. block([AppBlockModel manager]);
  50. }
  51. }
  52. } FailureBlock:^(NSError *error) {
  53. if (block)
  54. {
  55. block([AppBlockModel manager]);
  56. }
  57. }];
  58. }
  59. - (void)setLoginParm:(TIMLoginParam *)loginParm
  60. {
  61. _loginParm = loginParm;
  62. [_loginParm saveToLocal];
  63. }
  64. - (NSString *)userId
  65. {
  66. return _profile ? _profile.identifier : _loginParm.identifier;
  67. }
  68. - (NSString *)icon
  69. {
  70. return [NSString isEmpty:_profile.faceURL] ? nil : _profile.faceURL;
  71. }
  72. - (NSString *)remark
  73. {
  74. return ![NSString isEmpty:_profile.nickname] ? _profile.nickname : _profile.identifier;
  75. }
  76. - (NSString *)name
  77. {
  78. return ![NSString isEmpty:_profile.nickname] ? _profile.nickname : _profile.identifier;
  79. }
  80. - (NSString *)nickName
  81. {
  82. return ![NSString isEmpty:_profile.nickname] ? _profile.nickname : _profile.identifier;
  83. }
  84. - (BOOL)isEqual:(id)object
  85. {
  86. BOOL isEqual = [super isEqual:object];
  87. if (!isEqual)
  88. {
  89. if ([object conformsToProtocol:@protocol(IMUserAble)])
  90. {
  91. id<IMUserAble> io = (id<IMUserAble>)object;
  92. isEqual = [[self imUserId] isEqualToString:[io imUserId]];
  93. }
  94. }
  95. return isEqual;
  96. }
  97. // 用户IMSDK的identigier
  98. - (NSString *)imUserId
  99. {
  100. return [self userId];
  101. }
  102. // 用户昵称
  103. - (NSString *)imUserName
  104. {
  105. return [self nickName];
  106. }
  107. // 用户头像地址
  108. - (NSString *)imUserIconUrl
  109. {
  110. return [self icon];
  111. }
  112. // 当前App对应的AppID
  113. - (NSString *)imSDKAppId
  114. {
  115. return TXYSdkAppId;
  116. }
  117. // 当前App的AccountType
  118. - (NSString *)imSDKAccountType
  119. {
  120. return TXYSdkAccountType;
  121. }
  122. - (long)getDiamonds
  123. {
  124. return [[self.customInfoDict objectForKey:@"diamonds"] intValue];
  125. }
  126. - (void)setDiamonds:(NSString *)diamonds
  127. {
  128. [self.customInfoDict setObject:diamonds forKey:@"diamonds"];
  129. }
  130. // 获取等级
  131. - (long)getUserRank
  132. {
  133. return [[self.customInfoDict objectForKey:@"user_level"] intValue];
  134. }
  135. // 设置等级
  136. - (void)setUserRank:(NSString *)rank
  137. {
  138. [self.customInfoDict setObject:rank forKey:@"user_level"];
  139. }
  140. - (long)getUserCoin
  141. {
  142. if ([GlobalVariables sharedInstance].appModel.open_diamond_game_module == 1)
  143. {
  144. return [[self.customInfoDict objectForKey:@"diamonds"] intValue];
  145. }
  146. else
  147. {
  148. return [[self.customInfoDict objectForKey:@"coin"] intValue];
  149. }
  150. }
  151. - (void)setUserCoin:(NSString *)coin
  152. {
  153. if ([GlobalVariables sharedInstance].appModel.open_diamond_game_module == 1)
  154. {
  155. [self.customInfoDict setObject:coin forKey:@"diamonds"];
  156. }
  157. else
  158. {
  159. [self.customInfoDict setObject:coin forKey:@"coin"];
  160. }
  161. }
  162. - (BOOL)isMe:(IMAUser *)user
  163. {
  164. return [self.userId isEqualToString:user.userId];
  165. }
  166. @end