WFCCQuitGroupNotificationContent.m 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. //
  2. // WFCCQuitGroupNotificationContent.m
  3. // WFChatClient
  4. //
  5. // Created by heavyrain on 2017/9/20.
  6. // Copyright © 2017年 WildFireChat. All rights reserved.
  7. //
  8. #import "WFCCQuitGroupNotificationContent.h"
  9. #import "WFCCIMService.h"
  10. #import "WFCCNetworkService.h"
  11. #import "Common.h"
  12. @implementation WFCCQuitGroupNotificationContent
  13. - (WFCCMessagePayload *)encode {
  14. WFCCMessagePayload *payload = [[WFCCMessagePayload alloc] init];
  15. payload.contentType = [self.class getContentType];
  16. NSMutableDictionary *dataDict = [NSMutableDictionary dictionary];
  17. if (self.quitMember) {
  18. [dataDict setObject:self.quitMember forKey:@"o"];
  19. }
  20. payload.binaryContent = [NSJSONSerialization dataWithJSONObject:dataDict
  21. options:kNilOptions
  22. error:nil];
  23. return payload;
  24. }
  25. - (void)decode:(WFCCMessagePayload *)payload {
  26. NSError *__error = nil;
  27. NSDictionary *dictionary = [NSJSONSerialization JSONObjectWithData:payload.binaryContent
  28. options:kNilOptions
  29. error:&__error];
  30. if (!__error) {
  31. self.quitMember = dictionary[@"o"];
  32. }
  33. }
  34. + (int)getContentType {
  35. return MESSAGE_CONTENT_TYPE_QUIT_GROUP;
  36. }
  37. + (int)getContentFlags {
  38. return WFCCPersistFlag_PERSIST;
  39. }
  40. + (void)load {
  41. [[WFCCIMService sharedWFCIMService] registerMessageContent:self];
  42. }
  43. - (NSString *)digest {
  44. return [self formatNotification];
  45. }
  46. - (NSString *)formatNotification {
  47. NSString *formatMsg;
  48. if ([[WFCCNetworkService sharedInstance].userId isEqualToString:self.quitMember]) {
  49. formatMsg = @"你退出了群聊";
  50. } else {
  51. WFCCUserInfo *userInfo = [[WFCCIMService sharedWFCIMService] getUserInfo:self.quitMember refresh:NO];
  52. if (userInfo.displayName.length > 0) {
  53. formatMsg = [NSString stringWithFormat:@"%@退出了群聊", userInfo.displayName];
  54. } else {
  55. formatMsg = [NSString stringWithFormat:@"用户<%@>退出了群聊", self.quitMember];
  56. }
  57. }
  58. return formatMsg;
  59. }
  60. @end