Skip to content

Commit

Permalink
fix: 修复拉取消息的BUG
Browse files Browse the repository at this point in the history
  • Loading branch information
tangtaoit committed Jul 24, 2023
1 parent 0024585 commit 3df7eeb
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 15 deletions.
2 changes: 1 addition & 1 deletion Example/WuKongIMSDK.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
717E773C2A1CD95B0079EB5C /* WKMessageTableView.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = WKMessageTableView.m; sourceTree = "<group>"; };
717E77412A1CF5D10079EB5C /* WKSettingView.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WKSettingView.h; sourceTree = "<group>"; };
717E77422A1CF5D10079EB5C /* WKSettingView.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = WKSettingView.m; sourceTree = "<group>"; };
742BF67DB2BA13F22924700C /* WuKongIMSDK.podspec */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text; name = WuKongIMSDK.podspec; path = ../WuKongIMSDK.podspec; sourceTree = "<group>"; };
742BF67DB2BA13F22924700C /* WuKongIMSDK.podspec */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text; name = WuKongIMSDK.podspec; path = ../WuKongIMSDK.podspec; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.ruby; };
76D1BEF62B6E06589FBE6A18 /* Pods_WuKongIMSDK_Tests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_WuKongIMSDK_Tests.framework; sourceTree = BUILT_PRODUCTS_DIR; };
7ABD133C15E8CCD576E86E10 /* LICENSE */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text; name = LICENSE; path = ../LICENSE; sourceTree = "<group>"; };
873B8AEA1B1F5CCA007FD442 /* Main.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; name = Main.storyboard; path = Base.lproj/Main.storyboard; sourceTree = "<group>"; };
Expand Down
2 changes: 1 addition & 1 deletion WuKongIMSDK/Classes/manager/WKChatManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ typedef BOOL(^MessageStoreBeforeIntercept)(WKMessage*message);
查询指定orderSeq周围的消息 上5条下5条 ,比如 orderSeq 为 20 则查询 16 17 18 19 20 21 22 23 24 25 主要使用在定位消息
@param channel 频道
@param orderSeq 以此OrderSeq查询周围的消息
@param maxMessageSeq 目前服务器最大的messageSeq(目前第一屏数据不请求接口
@param maxMessageSeq 目前服务器最大的messageSeq(目的第一屏数据不请求接口
*/
-(void) pullAround:(WKChannel*)channel orderSeq:(uint32_t)orderSeq maxMessageSeq:(uint32_t)maxMessageSeq limit:(int)limit complete:(void(^)(NSArray<WKMessage*> *messages,NSError *error))complete;

Expand Down
36 changes: 23 additions & 13 deletions WuKongIMSDK/Classes/manager/WKChatManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -1133,33 +1133,42 @@ - (void)pullUp:(WKChannel *)channel startOrderSeq:(uint32_t)startOrderSeq endOrd

-(void) pullAround:(WKChannel*)channel orderSeq:(uint32_t)aroundOrderSeq maxMessageSeq:(uint32_t)maxMessageSeq limit:(int)limit complete:(void(^)(NSArray<WKMessage*> *messages,NSError *error))complete {
uint32_t baseOrderSeq = aroundOrderSeq; // 基准orderSeq(起始ordeqrSeq)
uint32_t offset = 5;
if (aroundOrderSeq!=0) {
uint32_t maxMessageSeqFromDB = [[WKMessageDB shared] getMaxMessageSeq:channel]; // 获取当前频道最大的messageSeq
uint32_t aroundMessageSeq = [[WKSDK shared].chatManager getOrNearbyMessageSeq:aroundOrderSeq]; // 获取aroundOrderSeq最接近的messageSeq
uint32_t baseMessageSeq = aroundMessageSeq;
if(maxMessageSeqFromDB > aroundMessageSeq && maxMessageSeqFromDB - aroundMessageSeq<limit) { // 如果消息数量不满足limit,则直接查询第一屏,baseMessageSeq为0
baseMessageSeq = 0;
}else if(aroundMessageSeq>maxMessageSeq) {
baseMessageSeq = aroundMessageSeq;
if(baseMessageSeq>offset) {
baseMessageSeq = baseMessageSeq - offset;
}
}else { // 如果满足limit数量,则以aroundOrderSeq为基准查询5条的第一条消息messageSeq,比如 aroundOrderSeq=10,getChannelAroundFirstMessageSeq查询到的就是 “9 8 7 6 5 ” 5条中的 5,然后以此messageSeq为baseMessageSeq进行查询
if(baseMessageSeq>0) {
baseMessageSeq = [[WKMessageDB shared] getChannelAroundFirstMessageSeq:channel messageSeq:aroundMessageSeq];
if(aroundMessageSeq - baseMessageSeq > offset) {
baseMessageSeq = aroundMessageSeq - offset;
}
if(baseMessageSeq == 0) { // 如果baseMessageSeq=0 说明本地没有对应的消息
if(aroundMessageSeq - 5 >0) {
baseMessageSeq = aroundMessageSeq - 5;
if(aroundMessageSeq - offset >0) {
baseMessageSeq = aroundMessageSeq - offset;
}else {
baseMessageSeq = aroundOrderSeq;
baseMessageSeq = aroundMessageSeq;
}
}
}
}
if(baseMessageSeq != 0 ) {
// 如果最后一条messageSeq与开始messageSeq的差值小于查询数量,则向上偏移指定数量满足limit
if(maxMessageSeqFromDB - baseMessageSeq<limit) {
if(baseMessageSeq>(limit - (maxMessageSeqFromDB - baseMessageSeq))) {
baseMessageSeq = baseMessageSeq - (limit - (maxMessageSeqFromDB - baseMessageSeq));
}

}
}
// if(baseMessageSeq != 0 ) {
// // 如果最后一条messageSeq与开始messageSeq的差值小于查询数量,则向上偏移指定数量满足limit
// if(maxMessageSeqFromDB - baseMessageSeq > 0 && maxMessageSeqFromDB - baseMessageSeq<limit) {
// if(baseMessageSeq>(limit - (maxMessageSeqFromDB - baseMessageSeq))) {
// baseMessageSeq = baseMessageSeq - (limit - (maxMessageSeqFromDB - baseMessageSeq));
// }
//
// }
// }
baseOrderSeq = [[WKSDK shared].chatManager getOrderSeq:baseMessageSeq];
}

Expand All @@ -1168,7 +1177,8 @@ -(void) pullAround:(WKChannel*)channel orderSeq:(uint32_t)aroundOrderSeq maxMess

-(void) pullAround:(WKChannel*)channel orderSeq:(uint32_t)aroundOrderSeq limit:(int)limit complete:(void(^)(NSArray<WKMessage*> *messages,NSError *error))complete {


[self pullAround:channel orderSeq:aroundOrderSeq maxMessageSeq:0 limit:limit complete:complete];

}


Expand Down

0 comments on commit 3df7eeb

Please sign in to comment.