TMSysNoticeMessage.m 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. //
  2. // TMSysNoticeMessage.m
  3. // Timi
  4. //
  5. // Created by 翟玉磊 on 2021/5/8.
  6. //
  7. #import "TMSysNoticeMessage.h"
  8. @implementation TMSysNoticeMessage
  9. ///消息是否存储,是否计入未读数
  10. + (RCMessagePersistent)persistentFlag {
  11. return MessagePersistent_NONE;
  12. }
  13. /// NSCoding
  14. - (instancetype)initWithCoder:(NSCoder *)aDecoder {
  15. self = [super init];
  16. if (self) {
  17. self.notice = [aDecoder decodeObjectForKey:@"notice"];
  18. }
  19. return self;
  20. }
  21. /// NSCoding
  22. - (void)encodeWithCoder:(NSCoder *)aCoder {
  23. [aCoder encodeObject:self.notice forKey:@"notice"];
  24. }
  25. ///将消息内容编码成json
  26. - (NSData *)encode {
  27. NSMutableDictionary *dataDict = [NSMutableDictionary dictionary];
  28. [dataDict setObject:self.notice forKey:@"notice"];
  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.notice = dictionary[@"notice"];
  42. NSDictionary *userinfoDic = dictionary[@"user"];
  43. [self decodeUserInfo:userinfoDic];
  44. }
  45. }
  46. }
  47. /// 会话列表中显示的摘要
  48. - (NSString *)conversationDigest {
  49. NSString *str = @"";
  50. NSDictionary *param = [self.notice jsonValueDecoded];
  51. if (param != nil) {
  52. NSString *msg = [BaseMethod toString:param[@"msg"]];
  53. NSString *msgContent = [BaseMethod toString:param[@"msgContent"]];
  54. if (StringIsEmpty(msg)) {
  55. str = msgContent;
  56. }else {
  57. str = msg;
  58. }
  59. }
  60. if (StringIsNotEmpty(str)) {
  61. return str;
  62. }
  63. return @"";
  64. }
  65. ///消息的类型名
  66. + (NSString *)getObjectName {
  67. return TMSysNoticeMessageIdentifier;
  68. }
  69. @end