WFCCModifyGroupAliasNotificationContent.m 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. //
  2. // WFCCModifyGroupAliasNotificationContent.m
  3. // WFChatClient
  4. //
  5. // Created by heavyrain on 2017/9/20.
  6. // Copyright © 2017年 WildFireChat. All rights reserved.
  7. //
  8. #import "WFCCModifyGroupAliasNotificationContent.h"
  9. #import "WFCCIMService.h"
  10. #import "WFCCNetworkService.h"
  11. #import "Common.h"
  12. @implementation WFCCModifyGroupAliasNotificationContent
  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.alias) {
  21. [dataDict setObject:self.alias 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.alias = dictionary[@"n"];
  36. }
  37. }
  38. + (int)getContentType {
  39. return MESSAGE_CONTENT_TYPE_MODIFY_GROUP_ALIAS;
  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. formatMsg = [NSString stringWithFormat:@"你修改群名片为:%@", self.alias];
  54. } else {
  55. WFCCUserInfo *userInfo = [[WFCCIMService sharedWFCIMService] getUserInfo:self.operateUser refresh:NO];
  56. if (userInfo.displayName.length > 0) {
  57. formatMsg = [NSString stringWithFormat:@"%@修改群名片为:%@", userInfo.displayName, self.alias];
  58. } else {
  59. formatMsg = [NSString stringWithFormat:@"%@修改群名片为:%@", self.operateUser, self.alias];
  60. }
  61. }
  62. return formatMsg;
  63. }
  64. @end