mirror of
https://github.com/wahyd4/Yep.git
synced 2026-08-10 21:36:49 +10:00
adjust lastReadAt from Server (it may old few seconds)
This commit is contained in:
@@ -176,14 +176,16 @@ class FayeService: NSObject, MZFayeClientDelegate {
|
||||
if let messageDataInfo = messageInfo["message"] as? JSONDictionary {
|
||||
|
||||
if let
|
||||
last_read_at = messageDataInfo["last_read_at"] as? NSTimeInterval,
|
||||
recipient_type = messageDataInfo["recipient_type"] as? String,
|
||||
recipient_id = messageDataInfo["recipient_id"] as? String {
|
||||
lastReadAt = messageDataInfo["last_read_at"] as? NSTimeInterval,
|
||||
recipientType = messageDataInfo["recipient_type"] as? String,
|
||||
recipientID = messageDataInfo["recipient_id"] as? String {
|
||||
|
||||
println("Mark recipient_id \(recipient_id) As Read")
|
||||
println("Mark recipient_id \(recipientID) As Read")
|
||||
|
||||
let lastReadAt = lastReadAt + 5 // 治标:服务器返回的时间可能较旧,会导致最后一条消息无法被标记
|
||||
|
||||
dispatch_async(dispatch_get_main_queue()) {
|
||||
NSNotificationCenter.defaultCenter().postNotificationName(MessageNotification.MessageBatchMarkAsRead, object: ["last_read_at": last_read_at, "recipient_type": recipient_type, "recipient_id": recipient_id])
|
||||
NSNotificationCenter.defaultCenter().postNotificationName(MessageNotification.MessageBatchMarkAsRead, object: ["last_read_at": lastReadAt, "recipient_type": recipientType, "recipient_id": recipientID])
|
||||
//self?.delegate?.fayeMessagesMarkAsReadByRecipient(last_read_at, recipientType: recipient_type, recipientID: recipient_id)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2103,6 +2103,8 @@ func createAndSendMessageWithMediaType(mediaType: MessageMediaType, inFilePath f
|
||||
|
||||
let message = Message()
|
||||
|
||||
println("send newMessage.createdUnixTime: \(message.createdUnixTime)")
|
||||
|
||||
// 确保本地刚创建的消息比任何已有的消息都要新
|
||||
if let latestMessage = realm.objects(Message).sorted("createdUnixTime", ascending: true).last {
|
||||
if message.createdUnixTime < latestMessage.createdUnixTime {
|
||||
|
||||
@@ -1998,6 +1998,8 @@ class ConversationViewController: BaseViewController {
|
||||
|
||||
private func markAsReadAllSentMesagesBeforeUnixTime(unixTime: NSTimeInterval) {
|
||||
|
||||
println("markAsReadAllSentMesagesBeforeUnixTime: \(unixTime)")
|
||||
|
||||
dispatch_async(dispatch_get_main_queue()) { [weak self] in
|
||||
|
||||
guard let recipient = self?.conversation.recipient else {
|
||||
@@ -2042,7 +2044,7 @@ class ConversationViewController: BaseViewController {
|
||||
}
|
||||
|
||||
if recipientID == conversation.recipient?.ID && recipientType == conversation.recipient?.type.nameForServer {
|
||||
self.markAsReadAllSentMesagesBeforeUnixTime(lastReadUnixTime)
|
||||
markAsReadAllSentMesagesBeforeUnixTime(lastReadUnixTime)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user