WFCCGroupPrivateChatNotificationContent.m 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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 "WFCCGroupPrivateChatNotificationContent.h"
  9. #import "WFCCIMService.h"
  10. #import "WFCCNetworkService.h"
  11. #import "Common.h"
  12. @implementation WFCCGroupPrivateChatNotificationContent
  13. - (WFCCMessagePayload *)encode {
  14. WFCCMessagePayload *payload = [[WFCCMessagePayload alloc] init];
  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. NSError *__error = nil;
  33. NSDictionary *dictionary = [NSJSONSerialization JSONObjectWithData:payload.binaryContent
  34. options:kNilOptions
  35. error:&__error];
  36. if (!__error) {
  37. self.creator = dictionary[@"o"];
  38. self.type = dictionary[@"n"];
  39. self.groupId = dictionary[@"g"];
  40. }
  41. }
  42. + (int)getContentType {
  43. return MESSAGE_CONTENT_TYPE_CHANGE_PRIVATECHAT;
  44. }
  45. + (int)getContentFlags {
  46. return WFCCPersistFlag_PERSIST;
  47. }
  48. + (void)load {
  49. [[WFCCIMService sharedWFCIMService] registerMessageContent:self];
  50. }
  51. - (NSString *)digest:(WFCCMessage *)message {
  52. return [self formatNotification:message];
  53. }
  54. - (NSString *)formatNotification:(WFCCMessage *)message {
  55. if ([[WFCCNetworkService sharedInstance].userId isEqualToString:self.creator]) {
  56. return [self.type isEqualToString:@"1"] ? @"你开启了成员私聊" : @"你关闭了成员私聊";
  57. } else {
  58. WFCCUserInfo *userInfo = [[WFCCIMService sharedWFCIMService] getUserInfo:self.creator inGroup:self.groupId refresh:NO];
  59. if (userInfo.friendAlias.length > 0) {
  60. return [NSString stringWithFormat:[self.type isEqualToString:@"1"] ? @"%@开启了成员私聊" : @"%@关闭了成员私聊", userInfo.friendAlias];
  61. } else if(userInfo.groupAlias.length > 0) {
  62. return [NSString stringWithFormat:[self.type isEqualToString:@"1"] ? @"%@开启了成员私聊" : @"%@关闭了成员私聊", userInfo.groupAlias];
  63. } else if (userInfo.displayName.length > 0) {
  64. return [NSString stringWithFormat:[self.type isEqualToString:@"1"] ? @"%@开启了成员私聊" : @"%@关闭了成员私聊", userInfo.displayName];
  65. } else {
  66. return [NSString stringWithFormat:[self.type isEqualToString:@"1"] ? @"用户<%@>开启了成员私聊" : @"用户<%@>关闭了成员私聊", self.creator];
  67. }
  68. }
  69. }
  70. @end