简体   繁体   English

Quickblox iOS-邮件未读

[英]Quickblox iOS - Messages Not Read

I'm having an issue with messages not being marked as read in Quickblox, even though the messages are indeed being read. 我遇到问题,即使确实正在阅读邮件,但消息在Quickblox中没有被标记为已读。

Is there an easy way to mark all messages in a dialog as read in the most recent Quickblox iOS SDK? 有没有一种简单的方法可以将对话框中的所有消息标记为在最新的Quickblox iOS SDK中已读取?

Quickblox does not handle read status of messages automatically on it's own :) In order to maintain the read status of the messages client applications has to co-operate as well :) Quickblox不会自行自动处理消息的读取状态:)为了保持消息的读取状态,客户端应用程序也必须进行协作:)

In order to receive the read status all the messages you send out for which you expect the read status has to be marked as markable :) 为了接收已读状态,您发送的所有您希望已读状态的消息都必须标记为可标记:)

Here is a sample code from QB docs 这是QB文档中的示例代码

QBChatMessage *message = [QBChatMessage markableMessage];
[message setText:@"Hi there!"];
[message setRecipientID:1022725];

Assume that user 1 sends out Hi there to User 2 :) Now the code in User 2's device should inform that user 2 has seen or read the message to quickblox server :) On informing the read status to Quickblox server fro a specific QBChatMessage, QB server sends out a notification to User 1 telling him that User 2 Has read the message :) 假设用户1向用户2发送了Hi消息:)现在,用户2的设备中的代码应通知用户2已看到或读取了消息到quickblox服务器:)在通知特定QBChatMessage,QB到Quickblox服务器的读取状态时服务器向用户1发送通知,告诉他用户2已阅读消息:)

On receiving message User 2 should inform QB server about the status using 用户2收到消息后,应使用以下信息通知QB服务器状态:

if([message markable]){
        [[QBChat instance] readMessage:message completion:^(NSError * _Nullable error) {

        }];
    }

Once User 2 informs QB server about the read status, QB server sends out notification to User1 acknowledging the same, which can be captured using :) 一旦用户2通知QB服务器有关读取状态,QB服务器就会向User1发送通知以确认该通知,可以使用:)捕获该通知。

- (void)chatDidReadMessageWithID:(NSString *)messageID dialogID:(NSString *)dialogID readerID:(NSUInteger)readerID
{

}

Once receiving the read status for a particular QBChatMessage you can update the UI to show the seen status for that message :) 收到特定QBChatMessage的读取状态后,您可以更新UI以显示该消息的可见状态:)

TIP 小费

Now as you might have noticed, read status works per message basis, this can be very much irritating and lead to complicated logic to send read status to all the messages one by one when you receive the whole lot of messages using 现在,您可能已经注意到,读取状态针对每个消息起作用,这可能非常烦人,并导致复杂的逻辑,当您使用以下方式接收全部消息时,将读取状态逐一发送给所有消息

[QBRequest messagesWithDialogID:@"54fda689535c125b0700bbfa" extendedRequest:nil forPage:resPage successBlock:^(QBResponse *response, NSArray *messages, QBResponsePage *responcePage) {

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

So simple solution is : 如此简单的解决方案是:

Rather than sending out the read status to all the messages in an array one by one you can send out the seen message only to last the message when user taps on the dialog to see the messages inside it :) 与其将读取状态一一发送给数组中的所有消息,您可以仅在用户点击对话框以查看其中的消息时才将可见消息发送到最后一条消息:)

Once the user enters the chats screen all the message belonging to that dalog will anyway be considered as read (Thats how all the messaging apps including whatsApp behaves) 一旦用户进入聊天屏幕,所有属于该日志的消息都将被视为已读(这就是包括whatsApp在内的所有消息传递应用程序的行为方式)

So sending seen status only to the last message makes sense :) And on receiving the seen status for a particular message you change the seen status to all the messages with sent date less than the message which received the seen status :) 因此,仅将可见状态发送给最后一条消息是有道理的:)并且在收到特定消息的可见状态时,您可以将可见状态更改为发送日期少于接收到可见状态的消息的所有消息:)

EDIT 编辑

Anyway All being said there are scenarios where in which you just need to send the read status to all the messages belonging to a particular dialog as your unread message count depends on the read status as well :) 总之,在某些情况下,您只需要将读取状态发送到属于特定对话框的所有消息,因为未读取消息数也取决于读取状态:)

For example if you want to update the unread message count for a particular dialog as 0 from 100 so its not advicable to send seen status to all 100 :) 例如,如果您想将特定对话框的未读消息计数从100更新为0,则不建议将可见状态发送给所有100 :)

You can make use of this API. 您可以使用此API。 Docs clearly says (and I am using it in my app as well ) you can set the read status to all messages belonging to a particular dialog just dont send the message id :) Docs清楚地说(我也正在我的应用程序中使用它),您可以将读取状态设置为属于特定对话框的所有消息,只是不发送消息ID :)

Here is the API 这是API

curl -X PUT \
-H "Content-Type: application/json" \
-H "QB-Token: eddf864695d72d33b959eec2ae6c640d817dfada" \
-d '{"read": "1", "chat_dialog_id": "53a99a7be4b094c7c6d31b41"}' \
https://api.quickblox.com/chat/Message/53aabe15e4b077ddd43e7fd3.json

Here is the link to docs :) http://quickblox.com/developers/Chat#Update_message 这是文档的链接:) http://quickblox.com/developers/Chat#Update_message

All you have to do is to 您要做的就是

1> make a web service call to api " https://api.quickblox.com/chat/Message " 1>对api“ https://api.quickblox.com/chat/Message ”进行Web服务调用

Notice 53aabe15e4b077ddd43e7fd3 is your message id :) If you want to send the seen status to all messages belonging to a particular dialog dont append it to URL :) 注意 53aabe15e4b077ddd43e7fd3是您的消息ID :)如果要将可见状态发送给属于特定对话框的所有消息,请不要将其附加到URL :)

2>In header field send Content-Type: application/json and QB-Token: current_user_token 2>在头字段中发送Content-Type:application / json和QB-Token:current_user_token

3>and in body please send read=1 and chat_dialog_id = dialog_id :) 3>并在正文中发送read = 1和chat_dialog_id = dialog_id :)

Thats it all the messages belonging to this dialog will be updated as read and hence the unread message count of the dialog will be 0 :) 就这样,属于此对话框的所有消息都将更新为已读,因此该对话框的未读消息数将为0 :)

NSURL *url = [NSURL URLWithString:@"https://api.quickblox.com/chat/Message"];
NSMutableURLRequest *mutableRequest=[NSMutableURLRequest requestWithURL:url];
[mutableRequest setHTTPMethod:@"PUT"];
[mutableRequest setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
[mutableRequest setValue:[QBSession currentSession].sessionDetails.token forHTTPHeaderField:@"QB-Token"];
NSString *jsonString=[NSString stringWithFormat:@"{\"read\": \"1\", \"chat_dialog_id\": \"%@\"}",dialogToSendReadStatus.id];
[mutableRequest setHTTPBody:[jsonString dataUsingEncoding:NSUTF8StringEncoding]];
NSURLSession *session = [NSURLSession sharedSession];
NSURLSessionDataTask *uploadTask = [session dataTaskWithRequest:mutableRequest completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
    if(error){
          DLog(@"Error");
    }
    else{
        DLog(@"%@",[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]);
    }
}];
[uploadTask resume];

I hope I answered your question :) 我希望我回答了你的问题:)

Happy coding :) 快乐的编码:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM