【问题标题】:Unable to remove dialog from dialog list Using QMServicesManager?无法使用 QMServicesManager 从对话框列表中删除对话框?
【发布时间】:2016-05-11 12:56:55
【问题描述】:

我正在尝试删除 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 的新对话) 我希望我很清楚.. 如何做到这一点?

问题更新为新要求:

现在如果我想删除群聊,我应该如何处理?如果我在其中使用相同的方法,我们会将 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 使用相同的方法会发生什么。

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

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

【问题讨论】:

    标签: ios iphone quickblox q-municate


    【解决方案1】:

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

    【讨论】:

    • 是的,我现在只做这个。我更新了我的问题。请检查一下。我还有一个问题。
    • 现在有了你的回答,我确认我的做法是正确的。但是我还有一个问题。如果我想与同一个用户创建一个新对话框。删除对话框后。它向我显示了新创建的对话框中的最后一条消息。如何处理?
    • @Wills-In 至于你的第二个问题,这是一个服务器端问题。我们从服务器收到最后一条消息。我们将在最新更新中解决此问题。请关注this link 获取更新。
    • @Wills-In,如果您仍有问题,请创建问题 in our repo
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-12-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-07-07
    • 1970-01-01
    相关资源
    最近更新 更多