WFCCTransferGroupOwnerNotificationContent.m 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. //
  2. // WFCCTransferGroupOwnerNotificationContent.m
  3. // WFChatClient
  4. //
  5. // Created by heavyrain on 2017/9/20.
  6. // Copyright © 2017年 WildFireChat. All rights reserved.
  7. //
  8. #import "WFCCTransferGroupOwnerNotificationContent.h"
  9. #import "WFCCIMService.h"
  10. #import "WFCCNetworkService.h"
  11. #import "Common.h"
  12. @implementation WFCCTransferGroupOwnerNotificationContent
  13. - (WFCCMessagePayload *)encode {
  14. WFCCMessagePayload *payload = [super encode];
  15. payload.contentType = [self.class getContentType];
  16. NSMutableDictionary *dataDict = [NSMutableDictionary dictionary];
  17. if (self.operateUser) {
  18. [dataDict setObject:self.operateUser forKey:@"o"];
  19. }
  20. if (self.owner) {
  21. [dataDict setObject:self.owner forKey:@"m"];
  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.operateUser = dictionary[@"o"];
  39. self.owner = dictionary[@"m"];
  40. self.groupId = dictionary[@"g"];
  41. }
  42. }
  43. + (int)getContentType {
  44. return MESSAGE_CONTENT_TYPE_TRANSFER_GROUP_OWNER;
  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 ([[WFCCNetworkService sharedInstance].userId isEqualToString:self.operateUser]) {
  58. WFCCUserInfo *userInfo = [[WFCCIMService sharedWFCIMService] getUserInfo:self.owner inGroup:self.groupId refresh:NO];
  59. if (userInfo.friendAlias.length > 0) {
  60. formatMsg = [NSString stringWithFormat:@"你把群主转让给了%@", userInfo.friendAlias];
  61. } else if(userInfo.groupAlias.length > 0) {
  62. formatMsg = [NSString stringWithFormat:@"你把群主转让给了%@", userInfo.groupAlias];
  63. } else if (userInfo.displayName.length > 0) {
  64. formatMsg = [NSString stringWithFormat:@"你把群主转让给了%@", userInfo.displayName];
  65. } else {
  66. formatMsg = [NSString stringWithFormat:@"你把群主转让给了%@", self.owner];
  67. }
  68. } else {
  69. WFCCUserInfo *userInfo = [[WFCCIMService sharedWFCIMService] getUserInfo:self.operateUser inGroup:self.groupId refresh:NO];
  70. if (userInfo.friendAlias.length > 0) {
  71. formatMsg = [NSString stringWithFormat:@"%@把群主转让给了", userInfo.friendAlias];
  72. } else if(userInfo.groupAlias.length > 0) {
  73. formatMsg = [NSString stringWithFormat:@"%@把群主转让给了", userInfo.groupAlias];
  74. } else if (userInfo.displayName.length > 0) {
  75. formatMsg = [NSString stringWithFormat:@"%@把群主转让给了", userInfo.displayName];
  76. } else {
  77. formatMsg = [NSString stringWithFormat:@"%@把群主转让给了", self.operateUser];
  78. }
  79. if ([[WFCCNetworkService sharedInstance].userId isEqualToString:self.owner]) {
  80. formatMsg = [formatMsg stringByAppendingString:@"你"];
  81. } else {
  82. userInfo = [[WFCCIMService sharedWFCIMService] getUserInfo:self.owner inGroup:self.groupId refresh:NO];
  83. if (userInfo.friendAlias.length > 0) {
  84. formatMsg = [formatMsg stringByAppendingString:userInfo.friendAlias];
  85. } else if(userInfo.groupAlias.length > 0) {
  86. formatMsg = [formatMsg stringByAppendingString:userInfo.groupAlias];
  87. } else if (userInfo.displayName.length > 0) {
  88. formatMsg = [formatMsg stringByAppendingString:userInfo.displayName];
  89. } else {
  90. formatMsg = [formatMsg stringByAppendingString:self.owner];
  91. }
  92. }
  93. }
  94. return formatMsg;
  95. }
  96. @end