Unable to remove dialog from dialog list Using QMServicesManager?

大兔子大兔子 提交于 2019-12-13 02:19:14

问题


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

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.

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).

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 ?

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];   

    }
}

But I got new problem :

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.

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 ?

Question Updated With New Requirement :

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..

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.

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];

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.

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


回答1:


Why aren't you using the power of 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);
                                                        }
                                                    }];


来源:https://stackoverflow.com/questions/37163394/unable-to-remove-dialog-from-dialog-list-using-qmservicesmanager

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!