WFCCTransferGroupOwnerNotificationContent.m 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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 = [[WFCCMessagePayload alloc] init];
  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. payload.binaryContent = [NSJSONSerialization dataWithJSONObject:dataDict
  24. options:kNilOptions
  25. error:nil];
  26. return payload;
  27. }
  28. - (void)decode:(WFCCMessagePayload *)payload {
  29. NSError *__error = nil;
  30. NSDictionary *dictionary = [NSJSONSerialization JSONObjectWithData:payload.binaryContent
  31. options:kNilOptions
  32. error:&__error];
  33. if (!__error) {
  34. self.operateUser = dictionary[@"o"];
  35. self.owner = dictionary[@"m"];
  36. }
  37. }
  38. + (int)getContentType {
  39. return MESSAGE_CONTENT_TYPE_TRANSFER_GROUP_OWNER;
  40. }
  41. + (int)getContentFlags {
  42. return WFCCPersistFlag_PERSIST;
  43. }
  44. + (void)load {
  45. [[WFCCIMService sharedWFCIMService] registerMessageContent:self];
  46. }
  47. - (NSString *)digest {
  48. return [self formatNotification];
  49. }
  50. - (NSString *)formatNotification {
  51. NSString *formatMsg;
  52. if ([[WFCCNetworkService sharedInstance].userId isEqualToString:self.operateUser]) {
  53. WFCCUserInfo *userInfo = [[WFCCIMService sharedWFCIMService] getUserInfo:self.owner refresh:NO];
  54. if (userInfo.displayName.length > 0) {
  55. formatMsg = [NSString stringWithFormat:@"你把群主转让给了%@", userInfo.displayName];
  56. } else {
  57. formatMsg = [NSString stringWithFormat:@"你把群主转让给了%@", self.owner];
  58. }
  59. } else {
  60. WFCCUserInfo *userInfo = [[WFCCIMService sharedWFCIMService] getUserInfo:self.operateUser refresh:NO];
  61. if (userInfo.displayName.length > 0) {
  62. formatMsg = [NSString stringWithFormat:@"%@把群主转让给了", userInfo.displayName];
  63. } else {
  64. formatMsg = [NSString stringWithFormat:@"%@把群主转让给了", self.operateUser];
  65. }
  66. if ([[WFCCNetworkService sharedInstance].userId isEqualToString:self.owner]) {
  67. formatMsg = [formatMsg stringByAppendingString:@"你"];
  68. } else {
  69. userInfo = [[WFCCIMService sharedWFCIMService] getUserInfo:self.owner refresh:NO];
  70. if (userInfo.displayName.length > 0) {
  71. formatMsg = [formatMsg stringByAppendingString:userInfo.displayName];
  72. } else {
  73. formatMsg = [formatMsg stringByAppendingString:self.owner];
  74. }
  75. }
  76. }
  77. return formatMsg;
  78. }
  79. @end