WFCCDismissGroupNotificationContent.m 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. //
  2. // WFCCDismissGroupNotificationContent.m
  3. // WFChatClient
  4. //
  5. // Created by heavyrain on 2017/9/20.
  6. // Copyright © 2017年 WildFireChat. All rights reserved.
  7. //
  8. #import "WFCCDismissGroupNotificationContent.h"
  9. #import "WFCCIMService.h"
  10. #import "WFCCNetworkService.h"
  11. #import "Common.h"
  12. @implementation WFCCDismissGroupNotificationContent
  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. 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.operateUser = dictionary[@"o"];
  32. }
  33. }
  34. + (int)getContentType {
  35. return MESSAGE_CONTENT_TYPE_DISMISS_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.operateUser]) {
  49. formatMsg = @"你解散了群聊";
  50. } else {
  51. WFCCUserInfo *userInfo = [[WFCCIMService sharedWFCIMService] getUserInfo:self.operateUser refresh:NO];
  52. if (userInfo.displayName.length > 0) {
  53. formatMsg = [NSString stringWithFormat:@"%@解散了群聊", userInfo.displayName];
  54. } else {
  55. formatMsg = [NSString stringWithFormat:@"用户<%@>解散了群聊", self.operateUser];
  56. }
  57. }
  58. return formatMsg;
  59. }
  60. @end