WFCCGroupMuteNotificationContent.m 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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 "WFCCGroupMuteNotificationContent.h"
  9. #import "WFCCIMService.h"
  10. #import "WFCCNetworkService.h"
  11. #import "Common.h"
  12. @implementation WFCCGroupMuteNotificationContent
  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. 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.creator = dictionary[@"o"];
  39. self.type = dictionary[@"n"];
  40. self.groupId = dictionary[@"g"];
  41. }
  42. }
  43. + (int)getContentType {
  44. return MESSAGE_CONTENT_TYPE_CHANGE_MUTE;
  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. if ([[WFCCNetworkService sharedInstance].userId isEqualToString:self.creator]) {
  57. return [self.type isEqualToString:@"1"] ? @"你开启了全员禁言" : @"你关闭了全员禁言";
  58. } else {
  59. WFCCUserInfo *userInfo = [[WFCCIMService sharedWFCIMService] getUserInfo:self.creator inGroup:self.groupId refresh:NO];
  60. if (userInfo.friendAlias.length > 0) {
  61. return [NSString stringWithFormat:[self.type isEqualToString:@"1"] ? @"%@开启了全员禁言" : @"%@关闭了全员禁言", userInfo.friendAlias];
  62. } else if(userInfo.groupAlias.length > 0) {
  63. return [NSString stringWithFormat:[self.type isEqualToString:@"1"] ? @"%@开启了全员禁言" : @"%@关闭了全员禁言", userInfo.groupAlias];
  64. } else if (userInfo.displayName.length > 0) {
  65. return [NSString stringWithFormat:[self.type isEqualToString:@"1"] ? @"%@开启了全员禁言" : @"%@关闭了全员禁言", userInfo.displayName];
  66. } else {
  67. return [NSString stringWithFormat:[self.type isEqualToString:@"1"] ? @"用户<%@>开启了全员禁言" : @"用户<%@>关闭了全员禁言", self.creator];
  68. }
  69. }
  70. }
  71. @end