WFCCFileMessageContent.m 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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.contentType = [self.class getContentType];
  24. payload.searchableContent = self.name;
  25. payload.content = [NSString stringWithFormat:@"%ld", (long)self.size];
  26. payload.mediaType = Media_Type_File;
  27. payload.remoteMediaUrl = self.remoteUrl;
  28. payload.localMediaPath = self.localPath;
  29. return payload;
  30. }
  31. - (void)decode:(WFCCMessagePayload *)payload {
  32. if ([payload isKindOfClass:[WFCCMediaMessagePayload class]]) {
  33. WFCCMediaMessagePayload *mediaPayload = (WFCCMediaMessagePayload *)payload;
  34. self.remoteUrl = mediaPayload.remoteMediaUrl;
  35. self.localPath = mediaPayload.localMediaPath;
  36. self.name = mediaPayload.searchableContent;
  37. self.size = [mediaPayload.content integerValue];
  38. }
  39. }
  40. + (int)getContentType {
  41. return MESSAGE_CONTENT_TYPE_FILE;
  42. }
  43. + (int)getContentFlags {
  44. return WFCCPersistFlag_PERSIST_AND_COUNT;
  45. }
  46. + (void)load {
  47. [[WFCCIMService sharedWFCIMService] registerMessageContent:self];
  48. }
  49. - (NSString *)digest {
  50. return [NSString stringWithFormat:@"[文件]:%@", self.name];
  51. }
  52. @end