How to Update a Sent Message in Quickblox iOS

How to update a sent message in Quickblox IOS

There is a method in QBRequest:

/**
Update existing chat message - mark it as read.

@param message Сhat message to update.
@param successBlock Block with response instance if request succeded.
@param errorBlock Block with response instance if request failed.

@return An instance of QBRequest for cancel operation mainly.
*/
+ (QBRequest *)updateMessage:(QBChatMessage *)message
successBlock:(nullable void(^)(QBResponse *response))successBlock
errorBlock:(nullable QBRequestErrorBlock)errorBlock;

The usage is the same as in android pretty much. Here you can read which fields you can update: http://quickblox.com/developers/Chat#Fields_to_update_2

How to update message status in ChatList using Quick blox sample?

First you should get the message with the extended request using date_send as key and dialog's lastMessageDate as value. Then using the instance of the MessageStatusStringBuilder class you can get the status of the last message.

 QBChatDialog *dialog = ... // your dialog

QBResponsePage *resPage = [QBResponsePage responsePageWithLimit:1 skip:0];

NSMutableDictionary *extendedRequest = @{@"date_sent" : [NSString stringWithFormat:@"%tu", (NSUInteger)[dialog.lastMessageDate timeIntervalSince1970]]}.mutableCopy;

[QBRequest messagesWithDialogID:dialog.ID extendedRequest:extendedRequest forPage:resPage successBlock:^(QBResponse *response, NSArray *messages, QBResponsePage *responcePage) {

NSLog(@"status = %@",[self.stringBuilder statusFromMessage:[messages firstObject]]);

} errorBlock:^(QBResponse *response) {

NSLog(@"error: %@", response.error);

}];

QuickBlox iOS SDK Update Message

There is an API method to update a message.

Note, that it is only possible to update following parameters: read, delivered, message.

In SDK, there is no updateMessage method, but there are methods for updating read and delivered fields, such as markMessagesAsRead, markMessagesAsDelivered.

Custom parameters cannot be updated neither by API nor SDK methods.

How to update Read and Delivery status of sent and received messages using Quickblox IOS?

There are docs for read and delivered status in the link you provided.

To make this answer more explicit, there are several ways to mark messages as read and delivered. For delivered marking there is only XMPP way available, use this method from QBChat to do it:

/**
* Send "delivered" status for message.
*
* @param message QBChatMessage message to mark as delivered.
* @param completion Completion block with failure error.
*/
- (void)markAsDelivered:(QB_NONNULL QBChatMessage *)message completion:(QB_NULLABLE QBChatCompletionBlock)completion;

For read marker you can use either REST request using QBRequest method:

/**
Mark messages as read.

@note Updates message "read" status only on server.

@param dialogID dialog ID.
@param messagesIDs Set of chat message IDs to mark as read. If messageIDs is nil then all messages in dialog will be marked as read.
@param successBlock Block with response instance if request succeded.
@param errorBlock Block with response instance if request failed.
@return An instance, which conforms Cancelable protocol. Use this instance to cancel the operation.
*/
+ (QB_NONNULL QBRequest *)markMessagesAsRead:(QB_NONNULL NSSet QB_GENERIC(NSString *) *)messagesIDs
dialogID:(QB_NONNULL NSString *)dialogID
successBlock:(QB_NULLABLE void(^)(QBResponse * QB_NONNULL_S response))successBlock
errorBlock:(QB_NULLABLE QBRequestErrorBlock)errorBlock;

or XMPP method of QBChat:

/**
* Send "read" status for message and update "read" status on a server
*
* @param message QBChatMessage message to mark as read.
* @param completion Completion block with failure error.
*/
- (void)readMessage:(QB_NONNULL QBChatMessage *)message completion:(QB_NULLABLE QBChatCompletionBlock)completion;

Anyway look closer to samples and documentation if you need a "live" example.

send message using quickblox

Instead of you're code like:

[chatDialog sendMessage:message completionBlock:^(NSError * _Nullable error)
{
NSLog(@"Message sent");

}];

Use the following code:

   [QBRequest createMessage:message successBlock:^(QBResponse *response, QBChatMessage *createdMessage) {
NSLog(@"success: %@", createdMessage);
} errorBlock:^(QBResponse *response) {
NSLog(@"ERROR: %@", response.error);
}];

I use Code like:

  #pragma mark Tool bar Actions
- (void)didPressSendButton:(UIButton *)button
withMessageText:(NSString *)text
senderId:(NSUInteger)senderId
senderDisplayName:(NSString *)senderDisplayName
date:(NSDate *)date {
[[QBChat instance] addDelegate:self];
QBChatMessage *message = [QBChatMessage message];
[message setText:text];
message.senderID = senderId;
message.recipientID= [[NSUserDefaults standardUserDefaults] integerForKey:@"CurrentRecipientID"];
message.dateSent = [NSDate date];
NSMutableDictionary *params = [NSMutableDictionary dictionary];
params[@"save_to_history"] = @YES;
[message setCustomParameters:params];
[QBRequest createMessage:message successBlock:^(QBResponse *response, QBChatMessage *createdMessage) {
NSLog(@"success: %@", createdMessage);
[self.chatSectionManager addMessage:createdMessage];
} errorBlock:^(QBResponse *response) {
NSLog(@"ERROR: %@", response.error);
}];

[self finishSendingMessageAnimated:YES];

}

How to retrieve the last message from Quickblox in iOS?

If you have been joined the room, just access lastMessageText directly:

dialog.lastMessageText

Or get the last message with a certain ID using QBRequest:

QBRequest.messagesWithDialogID("ID",
extendedRequest: ["sort_desc" : "date_sent", "limit" : 1],
forPage: nil,
successBlock: { (response, messages, page) -> Void in
println(messages)
},
errorBlock: { (response) -> Void in
println(response)
}
)

How to send a message to all quickblox Online users

You can find the details in below link: https://quickblox.com/developers/SimpleSample-messages_users-ios

  1. Broadcasting the same message to all users. It's a simple method which can be used in informational apps that do not authenticate users and where same push notification messages are broadcasted to everybody. This way when you want to send a push message you may 1) simply go to Admin panel -> Push Notifications -> type your message in Simple mode -> and hit "Send" for all of your users to receive the message; 2) Send a push using Push Notifications API (explained below). Following this way you only need to create ONE QuickBlox User which will have all of your users' devices associated with it. Then simply send your pushes to that User.

https://github.com/QuickBlox/quickblox-android-sdk/issues/239



Related Topics



Leave a reply



Submit