WFCCAddGroupeMemberNotificationContent.m 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. //
  2. // WFCCAddGroupeMemberNotificationContent.m
  3. // WFChatClient
  4. //
  5. // Created by heavyrain on 2017/9/20.
  6. // Copyright © 2017年 WildFireChat. All rights reserved.
  7. //
  8. #import "WFCCAddGroupeMemberNotificationContent.h"
  9. #import "WFCCIMService.h"
  10. #import "WFCCNetworkService.h"
  11. #import "Common.h"
  12. @implementation WFCCAddGroupeMemberNotificationContent
  13. - (WFCCMessagePayload *)encode {
  14. WFCCMessagePayload *payload = [super encode];
  15. payload.contentType = [self.class getContentType];
  16. NSMutableDictionary *dataDict = [NSMutableDictionary dictionary];
  17. if (self.invitor) {
  18. [dataDict setObject:self.invitor forKey:@"o"];
  19. }
  20. if (self.invitees) {
  21. [dataDict setObject:self.invitees forKey:@"ms"];
  22. }
  23. if (self.groupId) {
  24. [dataDict setObject:self.groupId forKey:@"g"];
  25. }
  26. payload.binaryContent = [NSJSONSerialization dataWithJSONObject:dataDict
  27. options:kNilOptions
  28. error:nil];
  29. return payload;
  30. }
  31. - (void)decode:(WFCCMessagePayload *)payload {
  32. [super decode:payload];
  33. NSError *__error = nil;
  34. NSDictionary *dictionary = [NSJSONSerialization JSONObjectWithData:payload.binaryContent
  35. options:kNilOptions
  36. error:&__error];
  37. if (!__error) {
  38. self.invitor = dictionary[@"o"];
  39. self.invitees = dictionary[@"ms"];
  40. self.groupId = dictionary[@"g"];
  41. }
  42. }
  43. + (int)getContentType {
  44. return MESSAGE_CONTENT_TYPE_ADD_GROUP_MEMBER;
  45. }
  46. + (int)getContentFlags {
  47. return WFCCPersistFlag_PERSIST;
  48. }
  49. + (void)load {
  50. [[WFCCIMService sharedWFCIMService] registerMessageContent:self];
  51. }
  52. - (NSString *)digest:(WFCCMessage *)message {
  53. return [self formatNotification:message];
  54. }
  55. - (NSString *)formatNotification:(WFCCMessage *)message {
  56. NSString *formatMsg;
  57. if ([self.invitees count] == 1 && [[self.invitees objectAtIndex:0] isEqualToString:self.invitor]) {
  58. if ([[WFCCNetworkService sharedInstance].userId isEqualToString:self.invitor]) {
  59. formatMsg = @"你加入了群聊";
  60. } else {
  61. WFCCUserInfo *userInfo = [[WFCCIMService sharedWFCIMService] getUserInfo:self.invitor inGroup:self.groupId refresh:NO];
  62. if (userInfo.friendAlias.length > 0) {
  63. formatMsg = [NSString stringWithFormat:@"%@加入了群聊", userInfo.friendAlias];
  64. } else if(userInfo.groupAlias.length > 0) {
  65. formatMsg = [NSString stringWithFormat:@"%@加入了群聊", userInfo.groupAlias];
  66. } else if (userInfo.displayName.length > 0) {
  67. formatMsg = [NSString stringWithFormat:@"%@加入了群聊", userInfo.displayName];
  68. } else {
  69. formatMsg = [NSString stringWithFormat:@"%@加入了群聊", self.invitor];
  70. }
  71. }
  72. return formatMsg;
  73. }
  74. if ([[WFCCNetworkService sharedInstance].userId isEqualToString:self.invitor]) {
  75. formatMsg = @"你邀请";
  76. } else {
  77. WFCCUserInfo *userInfo = [[WFCCIMService sharedWFCIMService] getUserInfo:self.invitor refresh:NO];
  78. if (userInfo.displayName.length > 0) {
  79. formatMsg = [NSString stringWithFormat:@"%@邀请", userInfo.displayName];
  80. } else {
  81. formatMsg = [NSString stringWithFormat:@"%@邀请", self.invitor];
  82. }
  83. }
  84. for (NSString *member in self.invitees) {
  85. if ([member isEqualToString:[WFCCNetworkService sharedInstance].userId]) {
  86. formatMsg = [formatMsg stringByAppendingString:@" 你"];
  87. } else {
  88. WFCCUserInfo *userInfo = [[WFCCIMService sharedWFCIMService] getUserInfo:member refresh:NO];
  89. if (userInfo.displayName.length > 0) {
  90. formatMsg = [formatMsg stringByAppendingFormat:@" %@", userInfo.displayName];
  91. } else {
  92. formatMsg = [formatMsg stringByAppendingFormat:@" %@", member];
  93. }
  94. }
  95. }
  96. formatMsg = [formatMsg stringByAppendingString:@"加入了群聊"];
  97. return formatMsg;
  98. }
  99. @end