WFCCGroupMemberAllowNotificationContent.m 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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 "WFCCGroupMemberAllowNotificationContent.h"
  9. #import "WFCCIMService.h"
  10. #import "WFCCNetworkService.h"
  11. #import "Common.h"
  12. @implementation WFCCGroupMemberAllowNotificationContent
  13. - (WFCCMessagePayload *)encode {
  14. WFCCMessagePayload *payload = [super encode];
  15. payload.contentType = [self.class getContentType];
  16. NSMutableDictionary *dataDict = [NSMutableDictionary dictionary];
  17. if (self.creator) {
  18. [dataDict setObject:self.creator 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.targetIds) {
  27. [dataDict setObject:self.targetIds 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.creator = dictionary[@"o"];
  42. self.type = dictionary[@"n"];
  43. self.groupId = dictionary[@"g"];
  44. self.targetIds = dictionary[@"ms"];
  45. }
  46. }
  47. + (int)getContentType {
  48. return MESSAGE_CONTENT_TYPE_ALLOW_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 *formatMsg;
  61. if ([[WFCCNetworkService sharedInstance].userId isEqualToString:self.creator]) {
  62. formatMsg = @"你";
  63. } else {
  64. WFCCUserInfo *userInfo = [[WFCCIMService sharedWFCIMService] getUserInfo:self.creator refresh:NO];
  65. if (userInfo.displayName.length > 0) {
  66. formatMsg = [NSString stringWithFormat:@"%@", userInfo.displayName];
  67. } else {
  68. formatMsg = [NSString stringWithFormat:@"%@", self.creator];
  69. }
  70. }
  71. if ([self.type isEqualToString:@"1"]) {
  72. formatMsg = [NSString stringWithFormat:@"%@ 允许了", formatMsg];
  73. } else {
  74. formatMsg = [NSString stringWithFormat:@"%@ 取消了", formatMsg];
  75. }
  76. for (NSString *member in self.targetIds) {
  77. if ([member isEqualToString:[WFCCNetworkService sharedInstance].userId]) {
  78. formatMsg = [formatMsg stringByAppendingString:@" 你"];
  79. } else {
  80. WFCCUserInfo *userInfo = [[WFCCIMService sharedWFCIMService] getUserInfo:member refresh:NO];
  81. if (userInfo.displayName.length > 0) {
  82. formatMsg = [formatMsg stringByAppendingFormat:@" %@", userInfo.displayName];
  83. } else {
  84. formatMsg = [formatMsg stringByAppendingFormat:@" %@", member];
  85. }
  86. }
  87. }
  88. formatMsg = [formatMsg stringByAppendingString:@" 群组禁言时的发言权限"];
  89. return formatMsg;
  90. }
  91. @end