// // YOUPAILCGiftAttachment.m // LiveChat // // Created by 张灿 on 2018/9/22. // Copyright © 2018年 caicai. All rights reserved. // #import "YOUPAILCGiftAttachment.h" @implementation YOUPAILCGiftAttachment - (NSString *)encodeAttachment { NSDictionary *dict = @{ CMType : @(CustomGift), CMData : @{ CMGiftId: self.gift_id ?[NSNumber numberWithInteger:self.gift_id]:@0, CMGiftName: self.gift_name?self.gift_name:@"", CMGiftUrl: self.gift_url ?self.gift_url:@"", CMGiftCount: self.gift_count ?[NSNumber numberWithInteger:self.gift_count]:@0, CMFrom: self.from_uid?[NSNumber numberWithInteger:self.from_uid]:@0, CMTo: self.to_uid?[NSNumber numberWithInteger:self.to_uid]:@0, CMLink_type: self.link_type?[NSNumber numberWithInteger:self.link_type]:@0, CMLink_url: self.link_url?self.link_url:@"", CMMd5String:self.md5_string ?self.md5_string:@"", CMGiftSvga:self.gift_svga ?self.gift_svga:@"", CMGiftType:self.gift_type?[NSNumber numberWithInteger:self.gift_type]:@0, CMFromNickname:self.from_nickname ?self.from_nickname:@"", CMSendGiftHide:self.send_gift_hide ?@(self.send_gift_hide):@0, CMFromAvatar:self.from_avatar ?self.from_avatar:@"", } }; NSData *data = [NSJSONSerialization dataWithJSONObject:dict options:0 error:nil]; NSString *content = nil; if (data) { content = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]; } return content; } - (NSString *)cellContent:(NIMMessage *)message{ return @"YOUPAILCGiftContentView";//让礼物和贴图一样的形势发送 } - (CGSize)contentSize:(NIMMessageModel *)model cellWidth:(CGFloat)width{ CGFloat height = 77.0f; CGFloat space = 8.0f; NSString *giftStr = [NSString stringWithFormat:@"%@x%@",self.gift_name,@(self.gift_count)]; NSString *titleStr = [NSString stringWithFormat:@"%@礼物",self.from_uid == [[LCSaveModel getUserModel].youpaipuserinfo.youpaipuser_id integerValue] ? @"送出" : @"收到"]; CGFloat titleWidth = [titleStr widthWithFont:LCBoldFont(14) constrainedToHeight:height]; CGFloat giftWidth = [giftStr widthWithFont:LCFont(11) constrainedToHeight:height]; CGFloat textWidth = giftWidth >= titleWidth ? giftWidth : titleWidth; CGFloat giftBgWidth = 88.0f; return CGSizeMake(textWidth + space + giftBgWidth, height); } - (UIEdgeInsets)contentViewInsets:(NIMMessage *)message { return UIEdgeInsetsZero; // CGFloat bubblePaddingForImage = 3.f; // CGFloat bubbleArrowWidthForImage = 5.f; // if (message.isOutgoingMsg) { // return UIEdgeInsetsMake(bubblePaddingForImage,bubblePaddingForImage,bubblePaddingForImage,bubblePaddingForImage + bubbleArrowWidthForImage); // }else{ // return UIEdgeInsetsMake(bubblePaddingForImage,bubblePaddingForImage + bubbleArrowWidthForImage, bubblePaddingForImage,bubblePaddingForImage); // } } @end