WFCCChangeGroupPortraitNotificationContent.m 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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 "WFCCChangeGroupPortraitNotificationContent.h"
  9. #import "WFCCIMService.h"
  10. #import "WFCCNetworkService.h"
  11. #import "Common.h"
  12. @implementation WFCCChangeGroupPortraitNotificationContent
  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.groupId) {
  21. [dataDict setObject:self.groupId forKey:@"g"];
  22. }
  23. payload.binaryContent = [NSJSONSerialization dataWithJSONObject:dataDict
  24. options:kNilOptions
  25. error:nil];
  26. return payload;
  27. }
  28. - (void)decode:(WFCCMessagePayload *)payload {
  29. [super decode:payload];
  30. NSError *__error = nil;
  31. NSDictionary *dictionary = [NSJSONSerialization JSONObjectWithData:payload.binaryContent
  32. options:kNilOptions
  33. error:&__error];
  34. if (!__error) {
  35. self.operateUser = dictionary[@"o"];
  36. self.groupId = dictionary[@"g"];
  37. }
  38. }
  39. + (int)getContentType {
  40. return MESSAGE_CONTENT_TYPE_CHANGE_GROUP_PORTRAIT;
  41. }
  42. + (int)getContentFlags {
  43. return WFCCPersistFlag_PERSIST;
  44. }
  45. + (void)load {
  46. [[WFCCIMService sharedWFCIMService] registerMessageContent:self];
  47. }
  48. - (NSString *)digest:(WFCCMessage *)message {
  49. return [self formatNotification:message];
  50. }
  51. - (NSString *)formatNotification:(WFCCMessage *)message {
  52. NSString *formatMsg;
  53. if ([[WFCCNetworkService sharedInstance].userId isEqualToString:self.operateUser]) {
  54. formatMsg = @"你更新了群头像";
  55. } else {
  56. WFCCUserInfo *userInfo = [[WFCCIMService sharedWFCIMService] getUserInfo:self.operateUser inGroup:self.groupId refresh:NO];
  57. if (userInfo.friendAlias.length > 0) {
  58. formatMsg = [NSString stringWithFormat:@"%@更新了群头像", userInfo.friendAlias];
  59. } else if(userInfo.groupAlias.length > 0) {
  60. formatMsg = [NSString stringWithFormat:@"%@更新了群头像", userInfo.groupAlias];
  61. } else if (userInfo.displayName.length > 0) {
  62. formatMsg = [NSString stringWithFormat:@"%@更新了群头像", userInfo.displayName];
  63. } else {
  64. formatMsg = [NSString stringWithFormat:@"用户<%@>更新了群头像", self.operateUser];
  65. }
  66. }
  67. return formatMsg;
  68. }
  69. @end