NIMGroupedUsrInfo.m 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. //
  2. // NTESGroupedUsrInfo.m
  3. // NIM
  4. //
  5. // Created by Xuhui on 15/3/24.
  6. // Copyright (c) 2015年 Netease. All rights reserved.
  7. //
  8. #import "NIMGroupedUsrInfo.h"
  9. #import "NIMKit.h"
  10. #import "NIMSpellingCenter.h"
  11. #import "NIMKitInfoFetchOption.h"
  12. @interface NIMGroupUser()
  13. @property (nonatomic,copy) NSString *userId;
  14. @property (nonatomic,strong) NIMKitInfo *info;
  15. @end
  16. @implementation NIMGroupUser
  17. - (instancetype)initWithUserId:(NSString *)userId{
  18. self = [super init];
  19. if (self) {
  20. _userId = userId;
  21. _info = [[NIMKit sharedKit] infoByUser:userId option:nil];
  22. }
  23. return self;
  24. }
  25. - (NSString *)groupTitle{
  26. NSString *title = [[NIMSpellingCenter sharedCenter] firstLetter:self.info.showName].capitalizedString;
  27. unichar character = [title characterAtIndex:0];
  28. if (character >= 'A' && character <= 'Z') {
  29. return title;
  30. }else{
  31. return @"#";
  32. }
  33. }
  34. - (NSString *)showName{
  35. return self.info.showName;
  36. }
  37. - (NSString *)memberId{
  38. return self.userId;
  39. }
  40. - (id)sortKey{
  41. return [[NIMSpellingCenter sharedCenter] spellingForString:self.info.showName].shortSpelling;
  42. }
  43. @end
  44. @interface NIMGroupTeamMember()
  45. @property (nonatomic,strong) NIMTeamMember *member;
  46. @end
  47. @implementation NIMGroupTeamMember
  48. - (instancetype)initWithUserId:(NSString *)userId teamId:(NSString *)teamId{
  49. self = [super init];
  50. if (self) {
  51. _member = [[NIMSDK sharedSDK].teamManager teamMember:userId inTeam:teamId];
  52. }
  53. return self;
  54. }
  55. - (NSString *)groupTitle{
  56. NSString *title = [[NIMSpellingCenter sharedCenter] firstLetter:self.showName].capitalizedString;
  57. unichar character = [title characterAtIndex:0];
  58. if (character >= 'A' && character <= 'Z') {
  59. return title;
  60. }else{
  61. return @"#";
  62. }
  63. }
  64. - (NSString *)memberId{
  65. return self.member.userId;
  66. }
  67. - (id)sortKey{
  68. return [[NIMSpellingCenter sharedCenter] spellingForString:self.showName].shortSpelling;
  69. }
  70. - (NSString *)showName{
  71. NIMSession *session = [NIMSession session:self.member.teamId type:NIMSessionTypeTeam];
  72. NIMKitInfoFetchOption *option = [[NIMKitInfoFetchOption alloc] init];
  73. option.session = session;
  74. NIMKitInfo *info = [[NIMKit sharedKit] infoByUser:self.memberId option:option];
  75. return info.showName;
  76. }
  77. @end
  78. @interface NIMGroupTeam()
  79. @property (nonatomic,strong) NIMTeam *team;
  80. @end
  81. @implementation NIMGroupTeam
  82. - (instancetype)initWithTeam:(NSString *)teamId{
  83. self = [super init];
  84. if (self) {
  85. _team = [[NIMSDK sharedSDK].teamManager teamById:teamId];
  86. }
  87. return self;
  88. }
  89. - (NSString *)groupTitle{
  90. NSString *title = [[NIMSpellingCenter sharedCenter] firstLetter:self.team.teamName].capitalizedString;
  91. unichar character = [title characterAtIndex:0];
  92. if (character >= 'A' && character <= 'Z') {
  93. return title;
  94. }else{
  95. return @"#";
  96. }
  97. }
  98. - (NSString *)memberId{
  99. return self.team.teamId;
  100. }
  101. - (id)sortKey{
  102. return [[NIMSpellingCenter sharedCenter] spellingForString:self.team.teamName].shortSpelling;
  103. }
  104. - (NSString *)showName{
  105. return self.team.teamName;
  106. }
  107. @end