TMPrivateChatGameShareMessage.m 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. //
  2. // TMPrivateChatGameShareMessage.m
  3. // Timi
  4. //
  5. // Created by 翟玉磊 on 2021/6/24.
  6. //
  7. #import "TMPrivateChatGameShareMessage.h"
  8. @implementation TMPrivateChatGameShareMessage
  9. ///消息是否存储,是否计入未读数
  10. + (RCMessagePersistent)persistentFlag {
  11. return MessagePersistent_ISCOUNTED;
  12. }
  13. /// NSCoding
  14. - (instancetype)initWithCoder:(NSCoder *)aDecoder {
  15. self = [super init];
  16. if (self) {
  17. self.data = [aDecoder decodeObjectForKey:@"data"];
  18. }
  19. return self;
  20. }
  21. /// NSCoding
  22. - (void)encodeWithCoder:(NSCoder *)aCoder {
  23. [aCoder encodeObject:self.data forKey:@"data"];
  24. }
  25. ///将消息内容编码成json
  26. - (NSData *)encode {
  27. NSMutableDictionary *dataDict = [NSMutableDictionary dictionary];
  28. [dataDict setObject:self.data forKey:@"data"];
  29. if (self.senderUserInfo) {
  30. [dataDict setObject:[self encodeUserInfo:self.senderUserInfo] forKey:@"user"];
  31. }
  32. NSData *data = [NSJSONSerialization dataWithJSONObject:dataDict options:kNilOptions error:nil];
  33. return data;
  34. }
  35. ///将json解码生成消息内容
  36. - (void)decodeWithData:(NSData *)data {
  37. if (data) {
  38. __autoreleasing NSError *error = nil;
  39. NSDictionary *dictionary = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&error];
  40. if (dictionary) {
  41. self.data = dictionary[@"data"];
  42. NSDictionary *userinfoDic = dictionary[@"user"];
  43. [self decodeUserInfo:userinfoDic];
  44. }
  45. }
  46. }
  47. /// 会话列表中显示的摘要
  48. - (NSString *)conversationDigest {
  49. NSString *str = @"";
  50. NSDictionary *param = [self.data jsonValueDecoded];
  51. if (param) {
  52. str = param[@"title"];
  53. }
  54. if (StringIsNotEmpty(str)) {
  55. return str;
  56. }
  57. return @"";
  58. }
  59. ///消息的类型名
  60. + (NSString *)getObjectName {
  61. return TMPrivateChatGameShareIdentifier;
  62. }
  63. @end