WFCCGroupMemberMutedNotificationContent.m 4.0 KB

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