WFCCChangeGroupNameNotificationContent.m 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. //
  2. // WFCCChangeGroupNameNotificationContent.m
  3. // WFChatClient
  4. //
  5. // Created by heavyrain on 2017/9/20.
  6. // Copyright © 2017年 WildFireChat. All rights reserved.
  7. //
  8. #import "WFCCChangeGroupNameNotificationContent.h"
  9. #import "WFCCIMService.h"
  10. #import "WFCCNetworkService.h"
  11. #import "Common.h"
  12. @implementation WFCCChangeGroupNameNotificationContent
  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.name) {
  21. [dataDict setObject:self.name 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.operateUser = dictionary[@"o"];
  39. self.name = dictionary[@"n"];
  40. if (self.name == nil) {
  41. self.name = @"";
  42. }
  43. self.groupId = dictionary[@"g"];
  44. }
  45. }
  46. + (int)getContentType {
  47. return MESSAGE_CONTENT_TYPE_CHANGE_GROUP_NAME;
  48. }
  49. + (int)getContentFlags {
  50. return WFCCPersistFlag_PERSIST;
  51. }
  52. + (void)load {
  53. [[WFCCIMService sharedWFCIMService] registerMessageContent:self];
  54. }
  55. - (NSString *)digest:(WFCCMessage *)message {
  56. return [self formatNotification:message];
  57. }
  58. - (NSString *)formatNotification:(WFCCMessage *)message {
  59. NSString *formatMsg;
  60. if ([[WFCCNetworkService sharedInstance].userId isEqualToString:self.operateUser]) {
  61. formatMsg = [NSString stringWithFormat:@"你修改群名称为:%@", self.name];
  62. } else {
  63. WFCCUserInfo *userInfo = [[WFCCIMService sharedWFCIMService] getUserInfo:self.operateUser inGroup:self.groupId refresh:NO];
  64. if (userInfo.friendAlias.length > 0) {
  65. formatMsg = [NSString stringWithFormat:@"%@修改群名称为:", userInfo.friendAlias];
  66. } else if(userInfo.groupAlias.length > 0) {
  67. formatMsg = [NSString stringWithFormat:@"%@修改群名称为:", userInfo.groupAlias];
  68. } else if (userInfo.displayName.length > 0) {
  69. formatMsg = [NSString stringWithFormat:@"%@修改群名称为:", userInfo.displayName];
  70. } else {
  71. formatMsg = [NSString stringWithFormat:@"%@修改群名称为:", self.operateUser];
  72. }
  73. formatMsg = [formatMsg stringByAppendingString:self.name];
  74. }
  75. return formatMsg;
  76. }
  77. @end