                         completion(messages)
                     }
                 }
+
+        } else {
+            // 可能无分页
+            completion(messages)
         }
     }
 }



func unreadMessages(completion completion: [JSONDictionary] -> Void) {
    headUnreadMessages { result in
        if
            let count = result["count"] as? Int,
            let currentPage = result["current_page"] as? Int,
            let perPage = result["per_page"] as? Int {
                if count <= currentPage * perPage {
                    if let messages = result["messages"] as? [JSONDictionary] {
                        completion(messages)
                    } else {
                        completion([])
                    }

                } else {
                    var messages = [JSONDictionary]()

                    if let page1Messages = result["messages"] as? [JSONDictionary] {
                        messages += page1Messages
                    }

                    // We have more messages

                    let downloadGroup = dispatch_group_create()


                        moreUnreadMessages(inPage: page, withPerPage: perPage, failureHandler: { (reason, errorMessage) in
                            dispatch_group_leave(downloadGroup)

                        }, completion: { result in
                            if let currentPageMessages = result["messages"] as? [JSONDictionary] {
                                messages += currentPageMessages
                            }

                            dispatch_group_leave(downloadGroup)
                        })
                    }

