你的浏览器禁用了JavaScript, 请开启后刷新浏览器获得更好的体验!
输入关键字进行搜索
搜索:
没有找到相关结果
lifei9241
赞同来自: 不轻易言弃
[已注销]
不轻易言弃
要回复问题请先登录或注册
4 个回复
lifei9241
赞同来自: 不轻易言弃
[已注销]
不轻易言弃
//判断消息的类型
if([dict[@"msg_type"]isEqualToString:@"txt"])
{
//插入文字消息
EMChatText *txt = [[EMChatText alloc] initWithText:dict[@"msg"]];
EMTextMessageBody *body = [[EMTextMessageBody alloc] initWithChatObject:txt];
// EMMessage *messagetext = [[EMMessage alloc] initWithReceiver:_conversation.chatter bodies:@[body]];
EMMessage *messagetext = [[EMMessage alloc] initMessageWithID:dict[@"msg_id"] sender:dict[@"from_user"] receiver:_chatter bodies:@[body]];
DLog(@"谁发的消息==%@==消息的内容==%@",_chatter,txt);
messagetext.isReadAcked = YES;
messagetext.isAcked = NO;
messagetext.isReadAcked = NO;
messagetext.isRead = YES;
messagetext.isGroup = self.isChatGroup;
messagetext.timestamp = [dict[@"timestamp"] longLongValue];
messagetext.conversationChatter = _chatter;
messagetext.messageType = eConversationTypeGroupChat;// 设置为群聊消息
messagetext.deliveryState = eMessageDeliveryState_Delivered;
[[EaseMob sharedInstance].chatManager insertMessageToDB:messagetext append2Chat:NO];
}
else if ([dict[@"msg_type"]isEqualToString:@"img"])
{
//插入图片消息体
NSDictionary *imageDic = @{EMMessageBodyAttrKeySecret:dict[@"secret"],
EMMessageBodyAttrKeySize:@{EMMessageBodyAttrKeySizeWidth:@laznrbfe,EMMessageBodyAttrKeySizeHeight:@1136},
EMMessageBodyAttrKeyFileName:dict[@"filename"],
EMMessageBodyAttrKeyType:EMMessageBodyAttrTypeImag,
EMMessageBodyAttrKeyUrl:dict[@"url"],
EMMessageBodyAttrKeyFileLength:@178212};
EMImageMessageBody *imageBody = [EMImageMessageBody imageMessageBodyFromBodyDict:imageDic forChatter:_chatter];
EMMessage *image = [[EMMessage alloc] initMessageWithID:dict[@"msg_id"] sender:dict[@"from_user"] receiver:_chatter bodies:@[imageBody]];
image.timestamp = [dict[@"timestamp"] longLongValue];
image.isReadAcked = NO;
image.isAcked = NO;
image.deliveryState = eMessageDeliveryState_Delivered;
image.isRead = YES;
image.isGroup = self.isChatGroup;
image.conversationChatter = _chatter;
// [[EaseMob sharedInstance].chatManager insertMessageToDB:messagetext];
[[EaseMob sharedInstance].chatManager insertMessageToDB:image append2Chat:YES];
}
传递模型写这样判断
- (void)setMessageModel:(MessageModel *)model
{
if (_messageModel.isSender)
{
NSArray *avate = [mUserDefaults objectForKey:hAvatar];
NSString *str = [avate firstObject];
[self.headImageView sd_setImageWithURL:[NSURL URLWithString:str]];
}
else
{
NSArray *arraySoce = [[DBManager shareManager] selectAppsById:messageModel.username];
self.uid = messageModel.username;
for (ChartModel *model in arraySoce)
{
[self.headImageView sd_setImageWithURL:[NSURL URLWithString:model.avatar] placeholderImage:[UIImage imageNamed:@"DefaultHeader"]];
self.headImageView.userInteractionEnabled = YES;
UITapGestureRecognizer *g = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapClickAction:)];
[self.headImageView addGestureRecognizer:g];
}
}
不轻易言弃