12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- //
- // TMPrivateChatGameShareMessage.m
- // Timi
- //
- // Created by 翟玉磊 on 2021/6/24.
- //
- #import "TMPrivateChatGameShareMessage.h"
- @implementation TMPrivateChatGameShareMessage
- ///消息是否存储,是否计入未读数
- + (RCMessagePersistent)persistentFlag {
- return MessagePersistent_ISCOUNTED;
- }
- /// NSCoding
- - (instancetype)initWithCoder:(NSCoder *)aDecoder {
- self = [super init];
- if (self) {
- self.data = [aDecoder decodeObjectForKey:@"data"];
- }
- return self;
- }
- /// NSCoding
- - (void)encodeWithCoder:(NSCoder *)aCoder {
- [aCoder encodeObject:self.data forKey:@"data"];
- }
- ///将消息内容编码成json
- - (NSData *)encode {
- NSMutableDictionary *dataDict = [NSMutableDictionary dictionary];
- [dataDict setObject:self.data forKey:@"data"];
- if (self.senderUserInfo) {
- [dataDict setObject:[self encodeUserInfo:self.senderUserInfo] forKey:@"user"];
- }
- NSData *data = [NSJSONSerialization dataWithJSONObject:dataDict options:kNilOptions error:nil];
- return data;
- }
- ///将json解码生成消息内容
- - (void)decodeWithData:(NSData *)data {
- if (data) {
- __autoreleasing NSError *error = nil;
- NSDictionary *dictionary = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&error];
- if (dictionary) {
- self.data = dictionary[@"data"];
-
- NSDictionary *userinfoDic = dictionary[@"user"];
- [self decodeUserInfo:userinfoDic];
- }
- }
- }
- /// 会话列表中显示的摘要
- - (NSString *)conversationDigest {
- NSString *str = @"";
- NSDictionary *param = [self.data jsonValueDecoded];
- if (param) {
- str = param[@"title"];
- }
- if (StringIsNotEmpty(str)) {
- return str;
- }
- return @"";
- }
- ///消息的类型名
- + (NSString *)getObjectName {
- return TMPrivateChatGameShareIdentifier;
- }
- @end
|