WFCCDismissGroupNotificationContent.m 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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 = [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_DISMISS_GROUP;
  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