ios - 无法使用 QMServicesManager 从对话框列表中删除对话框?

标签 ios iphone quickblox q-municate

我正在尝试删除 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。所以我得到了成功的回应。如果我得到成功响应,那么只有我从我的 TableView 对话框列表中删除该对话框。如上所写。

这里的问题是,当我从 ServicesManager 中删除对话框时,它会在 dialogsMemoryStorage 中删除,因此计数正在减少(示例初始计数为 10,删除后显示计数为 9,并且其重新加载 TableView 完全成功)。

但是当我退出应用程序然后重新启动应用程序时,它不会删除内存中已删除的对话框(即,它显示实际计数为 10 但不是 9)。所以预期的行为是,它应该给出新的计数(9)而不是旧的计数(10)。

我的理解是,它是临时删除 session ,但我猜不会在数据库中删除。否则我做错了什么吗?如何做到这一点?

更新问题:经过一些试验和错误后,我得到了解决方案,我没有在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 个不同的私有(private)聊天),然后我也开始聊天。然后我删除了与 User2 的对话框现在我的对话框列表中只有 User3 的对话框。

但是,如果我想用 User2 创建 NewDialog,那么它会在我与 user2 新创建的对话框中显示我旧的最新消息。但我想要的是,它应该创建一个带有空最新消息的新对话框? (与用户 2 的新对话)
我希望我很清楚..怎么做?

问题更新为新要求:

现在如果我想删除群聊我应该如何处理?如果我在其中使用相同的方法,我们会将 forAllUsers 传递为硬编码的“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 个用户。用户 1 、用户 2 和用户 3。现在 User1 已经用 User2 和 User3 创建了组。

那么这种方法对所有不同的 3 个用户都有用。我的意思是如果 User1 使用会发生什么
[ServicesManager.instance.chatService deleteDialogWithID:dialog.ID completion:nil];

如果 User2 和 User3 使用相同的方法会发生什么。

天气它作为退出对话框或删除对话框。在群组和公共(public)聊天的情况下,我对这种方法如何适用于不同用户感到有点困惑。

问题3:有没有其他退出群聊的方法?我希望它是清楚的!

最佳答案

你为什么不使用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);
                                                        }
                                                    }];

关于ios - 无法使用 QMServicesManager 从对话框列表中删除对话框?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37163394/

相关文章:

android - MonoTouch 还是 Sencha Touch?

苹果手机 : how to stop shutter animation?

iphone - 在 mkmap View 中的道路上绘制折线 - iPhone

java - QuickBlox 聊天消息监听器

javascript - Quickblox Webrtc 音频通话 - 听不到声音

ios - 在 swift 4 IOS 应用程序中手动添加和引用控件

ios - 将 HEX NSString 转换为 ASCII NSString

iPhone 加速度计确定运动

iPhone SDK自动滚动UIWebView到特定位置

ios - QBChatDelegate-chatDidReceiveMessage : getting called but dialogID is NULL