WFCCCreateGroupNotificationContent.m 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. //
  2. // WFCCCreateGroupNotificationContent.m
  3. // WFChatClient
  4. //
  5. // Created by heavyrain on 2017/9/19.
  6. // Copyright © 2017年 WildFireChat. All rights reserved.
  7. //
  8. #import "WFCCCreateGroupNotificationContent.h"
  9. #import "WFCCIMService.h"
  10. #import "WFCCNetworkService.h"
  11. #import "Common.h"
  12. @implementation WFCCCreateGroupNotificationContent
  13. - (WFCCMessagePayload *)encode {
  14. WFCCMessagePayload *payload = [[WFCCMessagePayload alloc] init];
  15. payload.contentType = [self.class getContentType];
  16. NSMutableDictionary *dataDict = [NSMutableDictionary dictionary];
  17. if (self.creator) {
  18. [dataDict setObject:self.creator forKey:@"o"];
  19. }
  20. if (self.groupName) {
  21. [dataDict setObject:self.groupName 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.creator = dictionary[@"o"];
  35. self.groupName = dictionary[@"n"];
  36. }
  37. }
  38. + (int)getContentType {
  39. return MESSAGE_CONTENT_TYPE_CREATE_GROUP;
  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. if ([[WFCCNetworkService sharedInstance].userId isEqualToString:self.creator]) {
  52. return [NSString stringWithFormat:@"你创建了群\"%@\"", self.groupName];
  53. } else {
  54. WFCCUserInfo *userInfo = [[WFCCIMService sharedWFCIMService] getUserInfo:self.creator refresh:NO];
  55. if (userInfo.displayName.length > 0) {
  56. return [NSString stringWithFormat:@"%@创建了群\"%@\"", userInfo.displayName, self.groupName];
  57. } else {
  58. return [NSString stringWithFormat:@"用户<%@>创建了群\"%@\"", self.creator, self.groupName];
  59. }
  60. }
  61. }
  62. @end