Commit b1724dd9 by zhangyunjie

数据库聊天列表接口获取

parent 60e090ba
// //
...@@ -26,10 +26,14 @@ typedef void (^callBackIsSuccess)(BOOL isSuccess); ...@@ -26,10 +26,14 @@ typedef void (^callBackIsSuccess)(BOOL isSuccess);
- (void)getUserDB; - (void)getUserDB;
//发送,收到消息写入 //发送,收到消息写入
- (void)insertChatInfoToFMDBWithModel:(OffcnIMBodyModel *)chatModel; - (void)insertChatInfoToFMDBWithModel:(OffcnIMBodyModel *)chatModel;
//拉取更新消息列表
- (void)updateChatInfoCacheInfo:(OffcnIMBodyModel *)chatModel callback:(callBackIsSuccess)isSucess;
//消息发送成功更新状态 //消息发送成功更新状态
- (void)updateChatInfoIsSendStatusToFMDBWithModel:(OffcnIMBodyModel *)messageModel isSuccess:(callBackIsSuccess)isSuccess; - (void)updateChatInfoIsSendStatusToFMDBWithModel:(OffcnIMBodyModel *)messageModel isSuccess:(callBackIsSuccess)isSuccess;
//自己发送消息更新聊天列表 //自己发送消息更新聊天列表
- (void)chatlistCacheInfo:(OffcnIMBodyModel *)chatlistModel callback:(callBackIsSuccess)isSucess; - (void)chatlistCacheInfo:(OffcnIMBodyModel *)chatlistModel callback:(callBackIsSuccess)isSucess;
//拉取更新聊天列表
- (void)updateChatlistCacheInfo:(OffcnIMBodyModel *)chatlistModel callback:(callBackIsSuccess)isSucess;
//某一条消息更新已读状态 //某一条消息更新已读状态
- (void)updateChatInfoIsRead:(OffcnIMBodyModel *)model callBack:(callBackIsSuccess)isSuccess; - (void)updateChatInfoIsRead:(OffcnIMBodyModel *)model callBack:(callBackIsSuccess)isSuccess;
//删除个人聊天记录 //删除个人聊天记录
......
// //
...@@ -80,6 +80,46 @@ static OffcnIMZYJFMDBHandler *FMDBHandler; ...@@ -80,6 +80,46 @@ static OffcnIMZYJFMDBHandler *FMDBHandler;
}]; }];
} }
//拉取更新消息列表
- (void)updateChatInfoCacheInfo:(OffcnIMBodyModel *)chatModel callback:(callBackIsSuccess)isSucess{
if (!_database) {
getFMDBInstance();
}
[_database inDatabase:^(ZYJZYJFMDatabase *db) {
//查询是否存在
NSString * sql = @"SELECT * FROM chatinfo where msg_fromId = ? and msg_id = ?";
NSMutableArray *tmpDataArray = [NSMutableArray array];
ZYJZYJFMResultSet *rs = [db executeQuery:sql,chatModel.msg_from,chatModel.msg_id];
while ([rs next]) {
OffcnIMBodyModel *tmpModel = [[OffcnIMBodyModel alloc] init];
[tmpDataArray addObject:tmpModel];
break;
}
//存在
BOOL result = NO;
if (tmpDataArray.count) {
NSString *sqlStr = @"update chatinfo set isSentSuccess = ?,bymyself = ?,isRead = ? where msg_fromId = ? and msg_id = ?";
result = [db executeUpdate:sqlStr,[NSNumber numberWithInteger:chatModel.isSentSuccess],[NSNumber numberWithInteger:chatModel.bymyself],[NSNumber numberWithInteger:chatModel.isRead],chatModel.msg_from,chatModel.msg_id];
//不存在,插库
}else{
NSString *sqlStr = @"insert into chatinfo(msg_fromId,msg_toId,tid,session_id,msg_id,version,send_time,msg_seq,msg_scope,msg_type,msg,dur,name,md5,url,thumb_url,cover_url,ext,w,h,size,isSentSuccess,bymyself,isRead) values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
result = [db executeUpdate:sqlStr,chatModel.msg_from,chatModel.msg_to,chatModel.tid,chatModel.session_id,chatModel.msg_id,chatModel.version,chatModel.send_time,[NSNumber numberWithInteger:chatModel.msg_seq],[NSNumber numberWithInteger:chatModel.msg_scope],[NSNumber numberWithInteger:chatModel.msg_type],chatModel.msg.msg,[NSNumber numberWithInteger:chatModel.msg.dur],chatModel.msg.name,chatModel.msg.md5,chatModel.msg.url,chatModel.msg.thumb_url,chatModel.msg.cover_url,chatModel.msg.ext,[NSNumber numberWithInteger:chatModel.msg.w],[NSNumber numberWithInteger:chatModel.msg.h],[NSNumber numberWithInteger:chatModel.msg.size],[NSNumber numberWithInteger:chatModel.isSentSuccess],[NSNumber numberWithInteger:chatModel.bymyself],[NSNumber numberWithInteger:chatModel.isRead]];
}
[rs close];
if (isSucess) {
isSucess(result);
}
}];
}
//消息发送成功更新状态 //消息发送成功更新状态
- (void)updateChatInfoIsSendStatusToFMDBWithModel:(OffcnIMBodyModel *)messageModel isSuccess:(callBackIsSuccess)isSuccess{ - (void)updateChatInfoIsSendStatusToFMDBWithModel:(OffcnIMBodyModel *)messageModel isSuccess:(callBackIsSuccess)isSuccess{
if (!_database) { if (!_database) {
...@@ -143,6 +183,47 @@ static OffcnIMZYJFMDBHandler *FMDBHandler; ...@@ -143,6 +183,47 @@ static OffcnIMZYJFMDBHandler *FMDBHandler;
}]; }];
} }
//拉取更新聊天列表
- (void)updateChatlistCacheInfo:(OffcnIMBodyModel *)chatlistModel callback:(callBackIsSuccess)isSucess{
if (!_database) {
getFMDBInstance();
}
[_database inDatabase:^(ZYJZYJFMDatabase *db) {
//查询是否存在
NSString * sql = @"SELECT * FROM chatlist where session_id = ?";
NSMutableArray *tmpDataArray = [NSMutableArray array];
ZYJZYJFMResultSet *rs = [db executeQuery:sql,chatlistModel.session_id];
while ([rs next]) {
OffcnIMBodyModel *tmpModel = [[OffcnIMBodyModel alloc] init];
[tmpDataArray addObject:tmpModel];
break;
}
//存在
BOOL result = NO;
if (tmpDataArray.count) {
NSString *sqlStr = @"update chatlist set lastmessage = ?,lastSendtime = ?,msg_seq = ?,session_id = ?,tid = ?,msg_id = ?,msg_type = ? where session_id = ?";
NSString *lastmessage = [self lastMessage:chatlistModel];
result = [db executeUpdate:sqlStr,lastmessage,chatlistModel.send_time,[NSNumber numberWithInteger:chatlistModel.msg_seq],chatlistModel.session_id,chatlistModel.tid,chatlistModel.msg_id,[NSNumber numberWithInteger:chatlistModel.msg_type],chatlistModel.session_id];
//不存在,插库
}else{
NSString *sqlStr = @"insert into chatlist(msg_toId,tid,session_id,msg_id,msg_type,lastmessage,lastSendtime,msg_seq)values(?,?,?,?,?,?,?,?)";
NSString *lastmessage = [self lastMessage:chatlistModel];
result = [db executeUpdate:sqlStr,chatlistModel.msg_to,chatlistModel.tid,chatlistModel.session_id,chatlistModel.msg_id,[NSNumber numberWithInteger:chatlistModel.msg_type],lastmessage,chatlistModel.send_time,[NSNumber numberWithInteger:chatlistModel.msg_seq]];
}
[rs close];
if (isSucess) {
isSucess(result);
}
}];
}
//某一条消息更新已读状态 //某一条消息更新已读状态
- (void)updateChatInfoIsRead:(OffcnIMBodyModel *)model callBack:(callBackIsSuccess)isSuccess{ - (void)updateChatInfoIsRead:(OffcnIMBodyModel *)model callBack:(callBackIsSuccess)isSuccess{
if (!_database) { if (!_database) {
...@@ -151,8 +232,8 @@ static OffcnIMZYJFMDBHandler *FMDBHandler; ...@@ -151,8 +232,8 @@ static OffcnIMZYJFMDBHandler *FMDBHandler;
[_database inDatabase:^(ZYJZYJFMDatabase *db) { [_database inDatabase:^(ZYJZYJFMDatabase *db) {
//插入记录到表中 //插入记录到表中
NSString *sqlStr = @"update chatinfo set isRead = ? where msg_id = ?"; NSString *sqlStr = @"update chatinfo set isRead = ? where msg_fromId = ? and msg_toId = ? and msg_seq = ?";
BOOL result = [db executeUpdate:sqlStr,[NSNumber numberWithInteger:model.isRead],model.msg_id]; BOOL result = [db executeUpdate:sqlStr,[NSNumber numberWithInteger:model.isRead],model.msg_from,model.msg_to,[NSNumber numberWithInteger:model.msg_seq]];
if (!result) { if (!result) {
NSLog(@"error when insert into database table"); NSLog(@"error when insert into database table");
NSLog(@"%d",db.lastErrorCode); NSLog(@"%d",db.lastErrorCode);
......
// //
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#import "SDConfigrationNetwork.h" #import "SDConfigrationNetwork.h"
#import "ZYJMJExtension.h" #import "ZYJMJExtension.h"
#import "OffcnIMZYJFMDBHandler.h" #import "OffcnIMZYJFMDBHandler.h"
#import "OffcnIMSocketManager.h"
@implementation OffcnNetworkExecutor @implementation OffcnNetworkExecutor
+ (void)cancelAllOperations{ + (void)cancelAllOperations{
...@@ -100,6 +101,15 @@ ...@@ -100,6 +101,15 @@
[OffcnBaseNetworking postToURL:markMsgReadURL bodyParams:dic finished:^(BaseResponse *baseResponse) { [OffcnBaseNetworking postToURL:markMsgReadURL bodyParams:dic finished:^(BaseResponse *baseResponse) {
if (baseResponse.isSuccess) { if (baseResponse.isSuccess) {
OffcnIMBodyModel *BodyModel = [[OffcnIMBodyModel alloc] init];
BodyModel.msg_from = msg_fromID;
BodyModel.msg_to = msg_toID;
BodyModel.msg_seq = msg_seq;
BodyModel.isRead = 1;
[[OffcnIMZYJFMDBHandler sharedInstance] updateChatInfoIsRead:BodyModel callBack:^(BOOL isSuccess) {
}];
finished(YES,baseResponse.responseObject,nil); finished(YES,baseResponse.responseObject,nil);
}else{ }else{
...@@ -133,6 +143,22 @@ ...@@ -133,6 +143,22 @@
if (baseResponse.isSuccess) { if (baseResponse.isSuccess) {
OffcnIMUnreadMsgModel *unreadMsgModel = [OffcnIMUnreadMsgModel mj_ZYJobjectWithKeyValues:baseResponse.responseObject]; OffcnIMUnreadMsgModel *unreadMsgModel = [OffcnIMUnreadMsgModel mj_ZYJobjectWithKeyValues:baseResponse.responseObject];
for (int i=0; i<unreadMsgModel.msg_list.count; i++) {
OffcnIMBodyModel *model = unreadMsgModel.msg_list[i];
if ([model.msg_from isEqualToString:[OffcnIMSocketManager defaultService].msg_fromId]) {
model.bymyself = 1;
}else{
model.bymyself = 0;
}
model.isSentSuccess = 1;
model.isRead = 0;
[[OffcnIMZYJFMDBHandler sharedInstance] updateChatInfoCacheInfo:model callback:^(BOOL isSuccess) {
}];
}
finished(YES,unreadMsgModel,nil); finished(YES,unreadMsgModel,nil);
}else{ }else{
finished(NO,nil,baseResponse); finished(NO,nil,baseResponse);
...@@ -153,6 +179,7 @@ ...@@ -153,6 +179,7 @@
// }; // };
// "session_id" = "a05517f0-ddec-11ea-88a4-4a5555fb6ab4"; // "session_id" = "a05517f0-ddec-11ea-88a4-4a5555fb6ab4";
// to = jfdfjei0343; // to = jfdfjei0343;
// type = 1; // type = 1;
// "unread_number" = 11; // "unread_number" = 11;
// }, // },
...@@ -166,6 +193,47 @@ ...@@ -166,6 +193,47 @@
if (baseResponse.isSuccess) { if (baseResponse.isSuccess) {
OffcnIMRecentMsgModel *recentMsgModel = [OffcnIMRecentMsgModel mj_ZYJobjectWithKeyValues:baseResponse.responseObject]; OffcnIMRecentMsgModel *recentMsgModel = [OffcnIMRecentMsgModel mj_ZYJobjectWithKeyValues:baseResponse.responseObject];
for (int i=0; i<recentMsgModel.sessions.count; i++) {
OffcnIMSessionModel *SessionModel = recentMsgModel.sessions[i];
OffcnIMMsgModel *MsgModel = [[OffcnIMMsgModel alloc] init];
OffcnIMBodyModel *BodyModel = [[OffcnIMBodyModel alloc] init];
BodyModel.msg_from = accid;
BodyModel.msg_to = SessionModel.to;
BodyModel.session_id = SessionModel.session_id;
BodyModel.msg_type = SessionModel.last_msg.msg_type;
BodyModel.send_time = SessionModel.last_msg.send_time;
BodyModel.tid = @"";
BodyModel.msg_id = @"";
BodyModel.msg_seq = 0;
BodyModel.isSentSuccess = 1;
if ([BodyModel.msg_to isEqualToString:[OffcnIMSocketManager defaultService].msg_fromId]) {
BodyModel.bymyself = 0;
}else{
BodyModel.bymyself = 1;
}
BodyModel.isRead = 1;
if (BodyModel.msg_type == 1) {
MsgModel.msg = SessionModel.last_msg.msg_content.msg;
}else{
MsgModel.dur = SessionModel.last_msg.msg_content.dur;
MsgModel.name = SessionModel.last_msg.msg_content.name;
MsgModel.md5 = SessionModel.last_msg.msg_content.md5;
MsgModel.url = SessionModel.last_msg.msg_content.url;
MsgModel.thumb_url = SessionModel.last_msg.msg_content.thumb_url;
MsgModel.cover_url = SessionModel.last_msg.msg_content.cover_url;
MsgModel.ext = SessionModel.last_msg.msg_content.ext;
MsgModel.w = SessionModel.last_msg.msg_content.w;
MsgModel.h = SessionModel.last_msg.msg_content.h;
MsgModel.size = SessionModel.last_msg.msg_content.size;
}
BodyModel.msg = MsgModel;
[[OffcnIMZYJFMDBHandler sharedInstance] updateChatlistCacheInfo:BodyModel callback:^(BOOL isSuccess) {
}];
}
finished(YES,recentMsgModel,nil); finished(YES,recentMsgModel,nil);
}else{ }else{
finished(NO,nil,baseResponse); finished(NO,nil,baseResponse);
...@@ -198,6 +266,22 @@ ...@@ -198,6 +266,22 @@
if (baseResponse.isSuccess) { if (baseResponse.isSuccess) {
OffcnIMHistoryMsgModel *historyMsgModel = [OffcnIMHistoryMsgModel mj_ZYJobjectWithKeyValues:baseResponse.responseObject]; OffcnIMHistoryMsgModel *historyMsgModel = [OffcnIMHistoryMsgModel mj_ZYJobjectWithKeyValues:baseResponse.responseObject];
for (int i=0; i<historyMsgModel.msg_list.count; i++) {
OffcnIMBodyModel *model = historyMsgModel.msg_list[i];
if ([model.msg_from isEqualToString:[OffcnIMSocketManager defaultService].msg_fromId]) {
model.bymyself = 1;
}else{
model.bymyself = 0;
}
model.isSentSuccess = 1;
model.isRead = 1;
[[OffcnIMZYJFMDBHandler sharedInstance] updateChatInfoCacheInfo:model callback:^(BOOL isSuccess) {
}];
}
finished(YES,historyMsgModel,nil); finished(YES,historyMsgModel,nil);
}else{ }else{
finished(NO,nil,baseResponse); finished(NO,nil,baseResponse);
......
...@@ -188,7 +188,7 @@ ...@@ -188,7 +188,7 @@
- (IBAction)readedAction:(UIButton *)sender { - (IBAction)readedAction:(UIButton *)sender {
//用户信息标记已读 //用户信息标记已读
__weak typeof(self) weakSelf = self; __weak typeof(self) weakSelf = self;
[[OffcnIMSDKiOS defaultService] markMsgReadWithMsg_fromID:self.fromId msg_toID:self.toId msg_seq:1597744585 Finished:^(BOOL success, id response, NSString *errorMessage) { [[OffcnIMSDKiOS defaultService] markMsgReadWithMsg_fromID:self.fromId msg_toID:self.toId msg_seq:1599222612718 Finished:^(BOOL success, id response, NSString *errorMessage) {
if (success) { if (success) {
[weakSelf tipMessageWithTitle:@"标记已读成功" message:@""]; [weakSelf tipMessageWithTitle:@"标记已读成功" message:@""];
}else{ }else{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment