QuickBlox / quickblox-ios-sdk

QuickBlox iOS SDK for messaging and video calling
https://quickblox.com/developers/IOS
MIT License
397 stars 358 forks source link

Can I send message from dialog created with init(id)? #853

Closed EugeneEl closed 7 years ago

EugeneEl commented 7 years ago

New Issue Checklist

Environment details

Info Value
iOS Version 10.0
Quickblox iOS SDK version 2.10
Xcode Version Xcode 8.3

I wonder can I send private message from dialog simply created with init() public init(dialogID: String?, type: QBChatDialogType)

If I already know dialogID.

I tried to do this but my message didn't appeared in database. So I cannot understand is it possible to send message simply with created manually chatDialog instance (not received in response from API). Or chatDialog properties should be fulfilled and it is insufficient to simply create chatDialog instance with id and send message with it? And I should keep an instance of chatDialog received from Quickbox server?

If it is possible to use dialogId created with id what might be an issue that message send successfully (success result) but not appeared in admin database (save to history is used)?

Thanks.

ghost commented 7 years ago

Hi @EugeneGoloboyar, try the code bellow:

QBChatDialog *chatDialog = [[QBChatDialog alloc] initWithDialogID:@"dialogID" type:QBChatDialogTypePrivate];
chatDialog.occupantIDs = @[youID, recipientID];

QBChatMessage *message = [QBChatMessage message];
if (dialog.type == QBChatDialogTypePrivate) {
    message.recipientID = dialog.recipientID;
    message.markable = YES;
}
message.senderID = currentUser.ID;
message.dialogID = chatDialog.ID;
message.text = @"message text";

NSMutableDictionary *params = [NSMutableDictionary dictionary];
params[@"save_to_history"] = @YES; //use this to save your message in database
[message setCustomParameters:params];

[chatDialog sendMessage:message completionBlock:^(NSError * _Nullable error) {

}];
EugeneEl commented 7 years ago

Thanks for quick reply, works now! As I understand senderID and dialogID are obligatory parameters for message and for occupantsIDs in chatDialog.