问题描述
读取数据库历史记录时;如何让我发的消息显示在右边
解决方案
给message.from 和message.to 赋值
解决方案二:
你拉取的你们自己的服务器上的消息,那么你接收和发送是怎么写的啊
解决方案三:
拉取的你们自己的服务器上的消息,插到数据库,插入是用这样的方法,然后就用你们demo的方法读取数据库 //判断消息的类型 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]; } }
解决方案四:
请问是在插入数据库代码里写还是在设置模型那里写