diff --git a/Yep/AppDelegate.swift b/Yep/AppDelegate.swift index 5c0f32cf..e5106321 100644 --- a/Yep/AppDelegate.swift +++ b/Yep/AppDelegate.swift @@ -93,9 +93,11 @@ class AppDelegate: UIResponder, UIApplicationDelegate { } func application(application: UIApplication, performFetchWithCompletionHandler completionHandler: (UIBackgroundFetchResult) -> Void) { + syncUnreadMessages() { completionHandler(UIBackgroundFetchResult.NewData) } + } // MARK: APNs @@ -119,12 +121,12 @@ class AppDelegate: UIResponder, UIApplicationDelegate { println("didReceiveRemoteNotification: \(userInfo)") if let v1AccessToken = YepUserDefaults.v1AccessToken() { - APService.handleRemoteNotification(userInfo) - + if let type = userInfo["type"] as? String { if type == "message" { syncUnreadMessages() { - + completionHandler(UIBackgroundFetchResult.NewData) + APService.handleRemoteNotification(userInfo) } } } diff --git a/Yep/Services/YepService.swift b/Yep/Services/YepService.swift index 740367f8..1fad2ef5 100644 --- a/Yep/Services/YepService.swift +++ b/Yep/Services/YepService.swift @@ -961,7 +961,7 @@ func sendMessageWithMediaType(mediaType: MessageMediaType, inFilePath filePath: func markAsReadMessage(message: Message ,#failureHandler: ((Reason, String?) -> Void)?, #completion: (Bool) -> Void) { - if message.readed || message.messageID.isEmpty || message.downloadState != MessageDownloadState.Downloaded.rawValue { + if message.readed || message.messageID.isEmpty { return } diff --git a/Yep/Services/YepServiceSync.swift b/Yep/Services/YepServiceSync.swift index b9699fce..d150ba29 100644 --- a/Yep/Services/YepServiceSync.swift +++ b/Yep/Services/YepServiceSync.swift @@ -365,7 +365,8 @@ private func syncGroupWithGroupInfo(groupInfo: JSONDictionary, inRealm realm: RL func syncUnreadMessagesAndDoFurtherAction(furtherAction: () -> Void) { unreadMessages { allUnreadMessages in //println("\n allUnreadMessages: \(allUnreadMessages)") - + println("Got unread message \(allUnreadMessages.count)") + dispatch_async(realmQueue) { let realm = RLMRealm.defaultRealm() diff --git a/Yep/ViewControllers/Conversation/ConversationViewController.swift b/Yep/ViewControllers/Conversation/ConversationViewController.swift index 9f97f17c..bd60644c 100644 --- a/Yep/ViewControllers/Conversation/ConversationViewController.swift +++ b/Yep/ViewControllers/Conversation/ConversationViewController.swift @@ -18,7 +18,7 @@ class ConversationViewController: UIViewController { return messagesInConversation(self.conversation) }() - let messagesBunchCount = 12 // TODO: 分段载入的“一束”消息的数量 + let messagesBunchCount = 50 // TODO: 分段载入的“一束”消息的数量 var displayedMessagesRange = NSRange() @@ -401,11 +401,11 @@ class ConversationViewController: UIViewController { // 初始时移动一次到底部 if !conversationCollectionViewHasBeenMovedToBottomOnce { - conversationCollectionViewHasBeenMovedToBottomOnce = true + // 先调整一下初次的 contentInset setConversaitonCollectionViewOriginalContentInset() - + if displayedMessagesRange.length > 0 { conversationCollectionView.scrollToItemAtIndexPath(NSIndexPath(forItem: displayedMessagesRange.length - 1, inSection: 0), atScrollPosition: UICollectionViewScrollPosition.Bottom, animated: false) } @@ -969,7 +969,12 @@ extension ConversationViewController: UICollectionViewDataSource, UICollectionVi } } - + + override func viewDidAppear(animated: Bool) { + super.viewDidAppear(animated) + conversationCollectionViewHasBeenMovedToBottomOnce = true + } + // MARK: UIScrollViewDelegate func scrollViewDidScroll(scrollView: UIScrollView) { diff --git a/Yep/Views/Cells/Conversation/ConversationCell.swift b/Yep/Views/Cells/Conversation/ConversationCell.swift index c900452d..9e375129 100644 --- a/Yep/Views/Cells/Conversation/ConversationCell.swift +++ b/Yep/Views/Cells/Conversation/ConversationCell.swift @@ -87,8 +87,20 @@ class ConversationCell: UITableViewCell { } } } - - self.chatLabel.text = latestMessage.textContent + switch latestMessage.mediaType { + + case MessageMediaType.Audio.rawValue: + self.chatLabel.text = "[声音]" + case MessageMediaType.Video.rawValue: + self.chatLabel.text = "[视频]" + case MessageMediaType.Image.rawValue: + self.chatLabel.text = "[图片]" + case MessageMediaType.Text.rawValue: + self.chatLabel.text = latestMessage.textContent + default: + break + + } self.timeAgoLabel.text = latestMessage.createdAt.timeAgo } else {