Skip to content

Commit

Permalink
fix: message addMessageStoreBeforeIntercept invalid
Browse files Browse the repository at this point in the history
  • Loading branch information
tangtaoit committed Oct 28, 2024
1 parent 2de4097 commit bb22a76
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 15 deletions.
2 changes: 1 addition & 1 deletion WuKongIMSDK/Classes/manager/WKChannelManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ typedef void (^WKChannelInfoBlock)(WKChannelInfo*);
-(void) fetchChannelInfo:(WKChannel*) channel;

/**
添加频道请求(此方法时候大量cell获取频道数据
添加频道请求(此方法适合大量cell获取频道数据
*/
-(void) addChannelRequest:(WKChannel*)channel complete:(void(^_Nullable)(NSError *error,bool notifyBefore))complete;

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 @@ -99,7 +99,7 @@ typedef BOOL(^MessageStoreBeforeIntercept)(WKMessage*message);


/// 保存消息
-(void) saveMessages:(NSArray<WKMessage*>*)messages;
- (NSArray<WKMessage*>*) saveMessages:(NSArray<WKMessage*>*)messages;


// 添加或更新消息(如果存在则更新,不存在添加)
Expand Down
22 changes: 9 additions & 13 deletions WuKongIMSDK/Classes/manager/WKChatManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -199,17 +199,19 @@ -(BOOL) needStoreOfIntercept:(WKMessage*)message {
return store;
}

-(void) saveMessages:(NSArray<WKMessage*>*)messages {
-(NSArray<WKMessage*>*) saveMessages:(NSArray<WKMessage*>*)messages {
if(!messages || messages.count<=0) {
return;
return nil;
}
for (WKMessage *message in messages) {
message.isDeleted = ![self needStoreOfIntercept:message];
}
// 保存消息
[[WKMessageDB shared] saveMessages:messages];
NSArray<WKMessage*> *newMessages = [[WKMessageDB shared] saveMessages:messages];
// 更新最近会话
[self addOrUpdateConversationWithMessages:messages];
[self addOrUpdateConversationWithMessages:newMessages];

return newMessages;
}

-(void) addOrUpdateMessages:(NSArray<WKMessage*>*)messages {
Expand Down Expand Up @@ -547,15 +549,13 @@ -(void) handleRecv:(NSArray<WKRecvPacket*>*) packets {
-(void) handleMessages:(NSArray<WKMessage*>*) messages {

// 存储消息
NSArray<WKMessage*> *storeMessages = [[WKMessageDB shared] saveMessages:[self filterNeedStoreMessages:messages]];
[self saveMessages:[self filterNeedStoreMessages:messages]];

// 流消息
NSArray<WKMessage*> *streamMessages = [self filterStreamMessagesWithStreamFlagIng:messages];

NSArray<WKStream*> *streams;
if(streamMessages && streamMessages.count>0) {

streams = [self getStreams:streamMessages];

// 保存流式消息
NSMutableArray<WKStream*> *needStoreStreams = [NSMutableArray array]; // 需要存储的流
for (WKMessage *m in streamMessages) {
Expand All @@ -566,6 +566,7 @@ -(void) handleMessages:(NSArray<WKMessage*>*) messages {
[WKMessageDB.shared saveOrUpdateStreams:needStoreStreams];
}

// cmd消息
NSArray<WKCMDModel*> *cmds = [self getCMDModels:messages]; // 获取命令消息
if(cmds && cmds.count>0) {
NSArray<WKCMDMessage*> *cmdMessages = [self getCMDMessages:messages];
Expand All @@ -576,11 +577,6 @@ -(void) handleMessages:(NSArray<WKMessage*>*) messages {

NSArray<WKMessage*> *commonMessages = [self filterNoCMDAndNoStreamMessages:messages]; // 非cmd消息和流消息

if(storeMessages && storeMessages.count>0) {
// 更新最近会话(只有需要存储的消息才更新最近会话)
[self addOrUpdateConversationWithMessages:storeMessages];
}

// 调用委托通知上层 不管存不存的消息都需要通知到delegate
[self callRecvMessagesDelegate:commonMessages];

Expand Down
1 change: 1 addition & 0 deletions WuKongIMSDK/Classes/manager/WKConnectionManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -631,6 +631,7 @@ -(void) handlePacketData:(NSArray<NSData*>*)dataList {
}
self.lastMsgTimeInterval = [[NSDate date] timeIntervalSince1970];
NSMutableArray<WKPacket*> *packets = [NSMutableArray array];
NSLog(@"包数量--->%lu",dataList.count);
for (NSData *data in dataList) {
WKPacket *packet = [[WKSDK shared].coder decode:data];
if(!packet) {
Expand Down

0 comments on commit bb22a76

Please sign in to comment.