Search code examples
iosobjective-cquickblox

QuickBlox - QBChatDialogTypePublicGroup : Dialog have to be in memory cache


Hello Friends i have create an application with QuickBlox. i am to create an 10 QBChatDialogTypePublicGroup from admin panel. it is static.

i want to create static public group from quickblox admin panel and chat any user in this group.

i am get this all group in viewController and display it. then user can choose any group to chat publicly.

i am using quickblox framework to chat with user. i am done QBChatDialogTypePrivate one to one user cheating.

Login :

- (void)loginWithQuickBlox{

    NSString *emaiAddress = [[NSUserDefaults standardUserDefaults] objectForKey:@"UserLogin"];
    NSString *password = [[NSUserDefaults standardUserDefaults] objectForKey:@"UserPassword"];

    [QBRequest logInWithUserLogin:emaiAddress password:password successBlock:^(QBResponse *response, QBUUser *user)
     {
         [[NSUserDefaults standardUserDefaults]setObject:[NSString stringWithFormat:@"%ld",(unsigned long)user.ID] forKey:@"USerLoginID"];
         [self loginWithQuickBloxChat:user];

     } errorBlock:^(QBResponse *response)
     {
         // error handling
         NSLog(@"errorsssss : %@", response.error);
     }];
}

Login with QuickBloxChat

- (void)loginWithQuickBloxChat:(QBUUser *)selectedUser {

    QBUUser *selectedUserx = [QBUUser user];
    selectedUserx.login = [[NSUserDefaults standardUserDefaults] objectForKey:@"UserLogin"];
    selectedUserx.password = [[NSUserDefaults standardUserDefaults] objectForKey:@"UserPassword"];
    selectedUserx.ID = [[[NSUserDefaults standardUserDefaults] objectForKey:@"USerLoginID"] integerValue];

    NSLog(@"Currunt User  : %@", [QBSession currentSession].currentUser);

    [ServicesManager.instance logInWithUser:selectedUserx completion:^(BOOL success, NSString *errorMessage)
    {
        [[QBChat instance] connectWithUser:selectedUserx completion:^(NSError * _Nullable error) {

        }];

         if (success)
         {
             NSLog(@"Login in Quickblox : %@",selectedUser);
             [self getPublicGroup];
         }
         else
         {
             NSLog(@"Error in QuickBlox : %@",errorMessage);
         }
    }];
}

Get Public Group

- (void)getPublicGroup {

     NSMutableDictionary *extendedRequest = @{@"type" : @(1)}.mutableCopy;
     QBResponsePage *page = [QBResponsePage responsePageWithLimit:100 skip:0];
     [QBRequest dialogsForPage:page extendedRequest:extendedRequest successBlock:^(QBResponse *response, NSArray *dialogObjects, NSSet *dialogsUsersIDs, QBResponsePage *page) {
     publicGroupArray = dialogObjects.mutableCopy;
     NSLog(@"Public Group : %@",publicGroupArray);
     [self.groupCollectionview reloadData];

    } errorBlock:^(QBResponse *response) {

    }];
}

Select Any one Group and Chat With ChatViewcontroller

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    QBChatDialog *groupChatDialog = [publicGroupArray objectAtIndex:indexPath.row];
    ChatViewController *chatViewController = [[ChatViewController alloc] init];
    chatViewController.dialog = groupChatDialog;
    chatViewController.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:chatViewController animated:YES];
}

This all procedure are working perfectly but when i send message from ChatViewController it will give me error

Assertion failure in -[QMChatService sendMessage:toDialogID:saveToHistory:saveToStorage:completion:], All/September/21/ChatApp/Pods/QMServices/QMChatService/QMChatService/QMChatService.m:1338

Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Dialog have to be in memory cache!' *** First throw call stack:


Solution

  • You are trying to combine core SDK methods with QMServices' methods.

    QBRequest is part of the Quickblox SDK, QMServices are high-level API for Chat features including:

    1. Authentication service for logging to Quickblox REST and XMPP.
    2. Inbox persistent and memory storage for messages, dialogs and users.

    If you want to get dialog using QMServices try the method below:

    - (void)loadDialogWithID:(NSString *)dialogID completion:(nullable void (^)(QBChatDialog * _Nullable loadedDialog))completion;
    

    Example:

    [ServicesManager.instance.chatService loadDialogWithID:dialogID
                                                    completion:^(QBChatDialog * _Nullable loadedDialog)
     {
    
    }];
    

    This method will load dialog from the server, join it(if dialog's type is group) and store in memory and CoreDate.

    If you want to fetch dialog using core method of the SDK you should implement all described actions by yourself.