无法从对话框列表中删除对话框使用QMServicesManager? [英] Unable to remove dialog from dialog list Using QMServicesManager?

查看:45
本文介绍了无法从对话框列表中删除对话框使用QMServicesManager?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在QMServicesManager中删除对话框对象,因此,当我想删除对话框时,请执行以下操作

I'm trying to remove dialog object in QMServicesManager, So when I want to delete the dialog I'm doing the below

- (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.这样我就能获得成功的回应.如果得到成功响应,则只有从表视图对话框列表中删除该对话框.如上所述.

So that whenever i say delete I'm calling deleteDialogsWitIDs api. So that I'm getting success response. If I get success response, then only I'm removing the dialog from my table view dialog list. As written above.

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

Here the problem is when ever I remove dialog from ServicesManager it is removing in the dialogsMemoryStorage so the count is decreasing(Example initial count is 10 after deleting it is showing count as 9 and its reloading table view success fully).

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

But when i quit the app and then re launch the application it is not removing the deleted dialog inside the memory(i.e, it is showing actual count as 10 but not as 9). So expected behaviour is, It should give new count(9) but not the old count(10).

我了解的是,它是为会话临时删除的,但我想并不是在数据库中删除.否则我做错什么了吗?如何实现呢?

What I understood is, it is deleting temporarily for the session but not deleting in the DB i guess. Or else Am I doing anything wrong ? How to achieve this ?

更新后的问题:经过一些尝试和错误,我得到了解决方案,我没有在comitEditingStyle:中做所有这些工作,我只是在调用deleteDialogWithID:它正在处理所有内容.代码被修改了

Updated Question : After some trial and errors I got the solution I'm not doing all those stuff inside comitEditingStyle:, I'm simply calling deleteDialogWithID: it is handling everything. The code is modified this

    - (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的对话框".

I logged in as User1 and I created chat with User2 and User3 separately (2 different private chats) and then I chatted also. Then I deleted dialog with User2 Now I have Only User3's Dialog in my dialog list.

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

But If I want to create NewDialog With User2 then It is showing my old latest message in my newly created dialog with user2. But What I want is, It should create a new dialog with empty latest message ? (New Dialog with User 2) I hope I'm clear.. How to do this ?

问题更新为新要求:

现在,如果我要删除群聊,应该如何处理?如果我在其中使用相同的方法,则会将forAllUsers传递为硬编码的"NO".写在QMChatServices.m内

Now If I want to delete group chat how I should handle this ? If I use the same method inside it we are passing forAllUsers as "NO" which is hard coded. written inside 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);
        }
    }];
}

所以现在我的疑问是..

So Now my doubt is..

问题1:如果我们想为所有用户删除对话框该怎么办.问题2:可以说有3个用户.用户1,用户2和用户3.现在,User1已使用User2和User3创建了组.

Question 1 : What if we want to delete dialog for all the users. Question 2 : Lets say there are 3 users. User1 , User2 and User3. Now User1 has created group with User2 and User3.

因此,此方法对所有3个不同的用户有用.我的意思是,如果User1使用

So how this method is useful for all the different 3 users. I mean What happens if User1 uses

[ServicesManager.instance.chatService deleteDialogWithID:dialog.ID completion:nil];

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

and what happens if User2 and User3 uses the same method.

在退出对话框或删除对话框时可以正常运行.在群聊和公共聊天的情况下,我对这种方法如何适用于不同的用户几乎不感到困惑.

Weather it works as exit from the dialog or deleting dialog. I'm little confused how this method works for different users in case of group and public chat.

问题3:还有其他方法可以退出群聊吗?我希望这很清楚!

Question 3 : Is there any other way to exit from the group chat ? I hope it is clear !!

推荐答案

为什么不使用 QMServices ?)

您可以使用以下方法简单地删除对话框:

You can simply delete the dialog with the following method:

 // 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);
                                                        }
                                                    }];

这篇关于无法从对话框列表中删除对话框使用QMServicesManager?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆