WFCCChangeGroupNameNotificationContent.m 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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 = [[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.name) {
  21. [dataDict setObject:self.name forKey:@"n"];
  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.name = dictionary[@"n"];
  36. if (self.name == nil) {
  37. self.name = @"";
  38. }
  39. }
  40. }
  41. + (int)getContentType {
  42. return MESSAGE_CONTENT_TYPE_CHANGE_GROUP_NAME;
  43. }
  44. + (int)getContentFlags {
  45. return WFCCPersistFlag_PERSIST;
  46. }
  47. + (void)load {
  48. [[WFCCIMService sharedWFCIMService] registerMessageContent:self];
  49. }
  50. - (NSString *)digest {
  51. return [self formatNotification];
  52. }
  53. - (NSString *)formatNotification {
  54. NSString *formatMsg;
  55. if ([[WFCCNetworkService sharedInstance].userId isEqualToString:self.operateUser]) {
  56. formatMsg = [NSString stringWithFormat:@"你修改群名称为:%@", self.name];
  57. } else {
  58. WFCCUserInfo *userInfo = [[WFCCIMService sharedWFCIMService] getUserInfo:self.operateUser refresh:NO];
  59. if (userInfo.displayName.length > 0) {
  60. formatMsg = [NSString stringWithFormat:@"%@修改群名称为:", userInfo.displayName];
  61. } else {
  62. formatMsg = [NSString stringWithFormat:@"%@修改群名称为:", self.operateUser];
  63. }
  64. formatMsg = [formatMsg stringByAppendingString:self.name];
  65. }
  66. return formatMsg;
  67. }
  68. @end