WFCCRecallMessageContent.m 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. //
  2. // WFCCTextMessageContent.m
  3. // WFChatClient
  4. //
  5. // Created by heavyrain on 2017/8/16.
  6. // Copyright © 2017年 WildFireChat. All rights reserved.
  7. //
  8. #import "WFCCRecallMessageContent.h"
  9. #import "WFCCIMService.h"
  10. #import "WFCCNetworkService.h"
  11. #import "Common.h"
  12. @implementation WFCCRecallMessageContent
  13. - (WFCCMessagePayload *)encode {
  14. //注意:在proto层收到撤回命令或主动撤回成功会直接更新被撤回的消息,如果修改encode&decode,需要同步修改
  15. WFCCMessagePayload *payload = [super encode];
  16. payload.contentType = [self.class getContentType];
  17. payload.content = self.operatorId;
  18. payload.binaryContent = [[[NSNumber numberWithLongLong:self.messageUid] stringValue] dataUsingEncoding:NSUTF8StringEncoding];
  19. return payload;
  20. }
  21. - (void)decode:(WFCCMessagePayload *)payload {
  22. [super decode:payload];
  23. //注意:在proto层收到撤回命令或主动撤回成功会直接更新被撤回的消息,如果修改encode&decode,需要同步修改
  24. self.operatorId = payload.content;
  25. self.messageUid = [[[NSString alloc] initWithData:payload.binaryContent encoding:NSUTF8StringEncoding] longLongValue];
  26. if (self.extra.length) {
  27. NSError *__error = nil;
  28. NSDictionary *dictionary = [NSJSONSerialization JSONObjectWithData:[payload.extra dataUsingEncoding:NSUTF8StringEncoding]
  29. options:kNilOptions
  30. error:&__error];
  31. if (!__error) {
  32. self.originalSender = dictionary[@"s"];
  33. self.originalContentType = [dictionary[@"t"] intValue];
  34. self.originalSearchableContent = dictionary[@"sc"];
  35. self.originalContent = dictionary[@"c"];
  36. self.originalExtra = dictionary[@"e"];
  37. self.originalMessageTimestamp = [dictionary[@"ts"] longLongValue];
  38. }
  39. }
  40. }
  41. + (int)getContentType {
  42. return MESSAGE_CONTENT_TYPE_RECALL;
  43. }
  44. + (int)getContentFlags {
  45. return WFCCPersistFlag_PERSIST;
  46. }
  47. + (void)load {
  48. [[WFCCIMService sharedWFCIMService] registerMessageContent:self];
  49. }
  50. - (NSString *)formatNotification:(WFCCMessage *)message {
  51. return [self digest:message];
  52. }
  53. - (NSString *)digest:(WFCCMessage *)message {
  54. if ([self.operatorId isEqualToString:[WFCCNetworkService sharedInstance].userId]) {
  55. return @"你撤回了一条消息";
  56. } else {
  57. WFCCUserInfo *userInfo = [[WFCCIMService sharedWFCIMService] getUserInfo:self.operatorId refresh:NO];
  58. if (userInfo.friendAlias.length) {
  59. return [NSString stringWithFormat:@"%@撤回了一条消息", userInfo.friendAlias];
  60. }
  61. if (userInfo.displayName != nil) {
  62. return [NSString stringWithFormat:@"%@撤回了一条消息", userInfo.displayName];
  63. }
  64. return [NSString stringWithFormat:@"用户<%@>撤回了一条消息", self.operatorId];
  65. }
  66. }
  67. @end