我试图删除QMServicesManager中的对话框对象,所以当我要删除对话框时,我正在执行以下操作
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [ServicesManager.instance.chatService.dialogsMemoryStorage dialogsSortByUpdatedAtWithAscending:NO].count;
}
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
return YES;
}
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
QBChatDialog *dialog = [self.modelArray objectAtIndex:indexPath.row];
if (dialog.type == QBChatDialogTypePrivate) {
[QBRequest deleteDialogsWithIDs:[NSSet setWithObject:dialog.ID] forAllUsers:NO
successBlock:^(QBResponse *response, NSArray *deletedObjectsIDs, NSArray *notFoundObjectsIDs, NSArray *wrongPermissionsObjectsIDs) {
NSLog(@"FJFFJFJ");
// [ServicesManager.instance.chatService.messagesMemoryStorage deleteMessagesWithDialogID:dialog.ID];
[ServicesManager.instance.chatService.dialogsMemoryStorage deleteChatDialogWithID:dialog.ID];
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationLeft];
} errorBlock:^(QBResponse *response) {
NSLog(@"GFGFGFGFG");
}];
}
}
因此,每当我说删除时,我都会调用deleteDialogsWitIDs api。这样我就能获得成功的回应。如果我得到成功响应,那么只有我从表格视图对话框列表中删除对话框。如上所述。
这里的问题是当我从ServicesManager中移除对话框时它会在dialogsMemoryStorage中删除,因此计数正在减少(删除后的初始计数为10,显示计数为9,并且其重新加载表视图完全成功)。
但是当我退出应用程序然后重新启动应用程序时,它不会删除内存中已删除的对话框(即,它显示实际计数为10而不是9)。所以预期的行为是,它应该给出新的计数(9)而不是旧的计数(10)。
我理解的是,它会暂时删除会话但不会在数据库中删除我猜。或者我做错了什么?怎么做到这一点?
更新问题:经过一些试验和错误后我得到了解决方案我没有在comitEditingStyle中执行所有这些操作:我只是调用deleteDialogWithID:它正在处理所有事情。代码被修改了
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
QBChatDialog *dialog = [self.modelArray objectAtIndex:indexPath.row];
if (dialog.type == QBChatDialogTypePrivate) {
[ServicesManager.instance.chatService deleteDialogWithID:dialog.ID completion:nil];
}
}
但我遇到了新问题:
我以User1身份登录,我分别与User2和User3创建了聊天(2个不同的私人聊天),然后我也聊了聊。然后我删除了User2的对话框现在我在对话框列表中只有User3的对话框。
但是如果我想用User2创建NewDialog那么它在我新创建的user2对话框中显示我的旧最新消息。但我想要的是,它应该创建一个空的最新消息的新对话框? (用户2的新对话框) 我希望我能说清楚......怎么做?
问题已根据新要求更新:
现在如果我要删除群聊,我应该如何处理?如果我在其中使用相同的方法,我们将传递给所有用户,因为" NO"这是硬编码的。写在QMChatServices.m中
- (void)deleteDialogWithID:(NSString *)dialogId completion:(void (^)(QBResponse *))completion {
NSParameterAssert(dialogId);
__weak __typeof(self)weakSelf = self;
[QBRequest deleteDialogsWithIDs:[NSSet setWithObject:dialogId] forAllUsers:NO successBlock:^(QBResponse *response, NSArray *deletedObjectsIDs, NSArray *notFoundObjectsIDs, NSArray *wrongPermissionsObjectsIDs) {
//
[weakSelf.dialogsMemoryStorage deleteChatDialogWithID:dialogId];
[weakSelf.messagesMemoryStorage deleteMessagesWithDialogID:dialogId];
if ([weakSelf.multicastDelegate respondsToSelector:@selector(chatService:didDeleteChatDialogWithIDFromMemoryStorage:)]) {
[weakSelf.multicastDelegate chatService:weakSelf didDeleteChatDialogWithIDFromMemoryStorage:dialogId];
}
[weakSelf.loadedAllMessages removeObjectsForKeys:deletedObjectsIDs];
if (completion) {
completion(response);
}
} errorBlock:^(QBResponse *response) {
//
if (response.status == QBResponseStatusCodeNotFound || response.status == 403) {
[weakSelf.dialogsMemoryStorage deleteChatDialogWithID:dialogId];
if ([weakSelf.multicastDelegate respondsToSelector:@selector(chatService:didDeleteChatDialogWithIDFromMemoryStorage:)]) {
[weakSelf.multicastDelegate chatService:weakSelf didDeleteChatDialogWithIDFromMemoryStorage:dialogId];
}
}
else {
[weakSelf.serviceManager handleErrorResponse:response];
}
if (completion) {
completion(response);
}
}];
}
所以现在我怀疑是......
问题1:如果我们要删除所有用户的对话框,该怎么办? 问题2:让我们说有3个用户。 User1,User2和User3。现在User1已经创建了具有User2和User3的组。
所以这个方法对所有不同的3个用户有用。我的意思是如果User1使用
会发生什么[ServicesManager.instance.chatService deleteDialogWithID:dialog.ID completion:nil];
如果User2和User3使用相同的方法会发生什么。
天气它可以作为退出对话框或删除对话框的工作。在群聊和公共聊天的情况下,我对这种方法对不同用户的效果感到困惑。
问题3:还有其他方法退出群聊吗?我希望很清楚!!
答案 0 :(得分:4)
为什么你没有使用QMServices的力量?)
您只需使用以下方法删除对话框:
// Deleting dialog from Quickblox and cache.
[ServicesManager.instance.chatService deleteDialogWithID:dialogID
completion:^(QBResponse *response) {
if (response.success) {
__typeof(self) strongSelf = weakSelf;
[strongSelf.tableView reloadData];
} else {
NSLog(@"can not delete dialog: %@", response.error);
}
}];