2
0

WFCCFileMessageContent.m 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. //
  2. // WFCCSoundMessageContent.m
  3. // WFChatClient
  4. //
  5. // Created by heavyrain on 2017/9/9.
  6. // Copyright © 2017年 WildFireChat. All rights reserved.
  7. //
  8. #import "WFCCFileMessageContent.h"
  9. #import "WFCCUtilities.h"
  10. #import "WFCCIMService.h"
  11. #import "Common.h"
  12. @implementation WFCCFileMessageContent
  13. + (instancetype)fileMessageContentFromPath:(NSString *)filePath {
  14. WFCCFileMessageContent *fileMsg = [[WFCCFileMessageContent alloc] init];
  15. fileMsg.localPath = filePath;
  16. fileMsg.name = [filePath lastPathComponent];
  17. NSDictionary *fileAttributes = [[NSFileManager defaultManager] attributesOfItemAtPath:filePath error:nil];
  18. fileMsg.size = [fileAttributes fileSize];
  19. return fileMsg;
  20. }
  21. - (WFCCMessagePayload *)encode {
  22. WFCCMediaMessagePayload *payload = [[WFCCMediaMessagePayload alloc] init];
  23. payload.extra = self.extra;
  24. payload.contentType = [self.class getContentType];
  25. payload.searchableContent = self.name;
  26. payload.content = [NSString stringWithFormat:@"%ld", (long)self.size];
  27. payload.mediaType = Media_Type_FILE;
  28. payload.remoteMediaUrl = self.remoteUrl;
  29. payload.localMediaPath = self.localPath;
  30. return payload;
  31. }
  32. - (void)decode:(WFCCMessagePayload *)payload {
  33. [super decode:payload];
  34. if ([payload isKindOfClass:[WFCCMediaMessagePayload class]]) {
  35. WFCCMediaMessagePayload *mediaPayload = (WFCCMediaMessagePayload *)payload;
  36. self.remoteUrl = mediaPayload.remoteMediaUrl;
  37. self.localPath = mediaPayload.localMediaPath;
  38. self.name = mediaPayload.searchableContent;
  39. self.size = [mediaPayload.content integerValue];
  40. }
  41. }
  42. + (int)getContentType {
  43. return MESSAGE_CONTENT_TYPE_FILE;
  44. }
  45. + (int)getContentFlags {
  46. return WFCCPersistFlag_PERSIST_AND_COUNT;
  47. }
  48. + (void)load {
  49. [[WFCCIMService sharedWFCIMService] registerMessageContent:self];
  50. }
  51. - (NSString *)digest:(WFCCMessage *)message {
  52. return [NSString stringWithFormat:@"[文件]:%@", self.name];
  53. }
  54. @end