123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 |
- //
- // TMPrivateChatGiftMessage.m
- // Timi
- //
- // Created by 翟玉磊 on 2021/5/19.
- //
- #import "TMPrivateChatGiftMessage.h"
- #import "Macro.h"
- #import "NSString+YYAdd.h"
- #import "NSData+YYAdd.h"
- static NSString * const RTC_CONVENE_GIFT_NOTICE = @"private:chat:gift:settle";
- @implementation TMPrivateChatGiftMessage
- ///消息是否存储,是否计入未读数
- + (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 != nil) {
-
- //自定义TIMCustomElem首页默认显示
- NSString *type = [@"23" toString:param[@"type"]];
- if ([type isEqualToString:RTC_CONVENE_GIFT_NOTICE]) {
- NSString *senderUserName = [@"23" toString:param[@"senderUserName"]];
- NSString *targetUserName = [@"23" toString:param[@"targetUserName"]];
- NSString *giftName = [@"23" toString:param[@"giftName"]];
- NSInteger quantity= [param[@"quantity"] integerValue];
-
- str = [NSString stringWithFormat:@"%@ 送给 %@ %@ x%ld", senderUserName, targetUserName, giftName, quantity];
-
- }else{
- NSString *msg = [@"23" toString:param[@"msg"]];
- NSString *msgContent = [@"23" toString:param[@"msgContent"]];
- if (StringIsEmpty(msg)) {
- str = msgContent;
- }else {
- str = msg;
- }
- }
-
- }
- if (StringIsNotEmpty(str)) {
- return str;
- }
- return @"";
- }
- ///消息的类型名
- + (NSString *)getObjectName {
- return TMPrivateChatGiftIdentifier;
- }
- @end
|