mirror of
https://github.com/wahyd4/Yep.git
synced 2026-08-09 04:46:35 +10:00
new unreadMessages; save unreadMessagesCount to Conversation
This commit is contained in:
+3
-3
@@ -14,7 +14,7 @@ PODS:
|
||||
- FXBlurView (1.6.4)
|
||||
- JPush-iOS-SDK (1.8.8)
|
||||
- KeyboardMan (0.5.2)
|
||||
- Kingfisher (1.8.0)
|
||||
- Kingfisher (1.8.1)
|
||||
- MonkeyKing (0.0.2)
|
||||
- MZFayeClient (1.0.1):
|
||||
- Base64 (~> 1.0.1)
|
||||
@@ -53,7 +53,7 @@ DEPENDENCIES:
|
||||
|
||||
EXTERNAL SOURCES:
|
||||
MZFayeClient:
|
||||
:path: "../CatchLib-iOS/MZFayeClient/"
|
||||
:path: ../CatchLib-iOS/MZFayeClient/
|
||||
|
||||
SPEC CHECKSUMS:
|
||||
1PasswordExtension: 9f471645d378283cb88c6d4bf502e4381a42c0ad
|
||||
@@ -66,7 +66,7 @@ SPEC CHECKSUMS:
|
||||
FXBlurView: db786c2561cb49a09ae98407f52460096ab8a44f
|
||||
JPush-iOS-SDK: d4c097d8abbdd0837e24d44b41aacf64a6feddfd
|
||||
KeyboardMan: b081c254c5c0adc794a49b4e97a86cb4ac917a66
|
||||
Kingfisher: 4d40a6d8a0030b575be66593cae3aea587971a67
|
||||
Kingfisher: a20680f220c52620284fae571805a179809985c2
|
||||
MonkeyKing: 9be24307843a80f4cd3eca66adc12c67aefb83bb
|
||||
MZFayeClient: 65e7ef67e61fbe7a7a8b196130541c9f06bcb5d8
|
||||
Navi: 891defbce3c48dcf31d05d3c2cbc8b7fe6c77c30
|
||||
|
||||
@@ -41,7 +41,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
|
||||
let directory: NSURL = NSFileManager.defaultManager().containerURLForSecurityApplicationGroupIdentifier(YepConfig.appGroupID)!
|
||||
let realmPath = directory.URLByAppendingPathComponent("db.realm").path!
|
||||
|
||||
return Realm.Configuration(path: realmPath, schemaVersion: 7, migrationBlock: { migration, oldSchemaVersion in
|
||||
return Realm.Configuration(path: realmPath, schemaVersion: 8, migrationBlock: { migration, oldSchemaVersion in
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -482,6 +482,8 @@ class Conversation: Object {
|
||||
var messages: [Message] {
|
||||
return linkingObjects(Message.self, forProperty: "conversation")
|
||||
}
|
||||
|
||||
dynamic var unreadMessagesCount: Int = 0
|
||||
}
|
||||
|
||||
// MARK: Feed
|
||||
|
||||
@@ -1680,6 +1680,7 @@ func officialMessages(completion completion: Int -> Void) {
|
||||
apiRequest({_ in}, baseURL: baseURL, resource: resource, failure: defaultFailureHandler, completion: completion)
|
||||
}
|
||||
|
||||
/*
|
||||
func headUnreadMessages(failureHandler failureHandler: ((Reason, String?) -> Void)?, completion: JSONDictionary -> Void) {
|
||||
let requestParameters = [
|
||||
"page": 1,
|
||||
@@ -1713,7 +1714,7 @@ func moreUnreadMessages(inPage page: Int, withPerPage perPage: Int, failureHandl
|
||||
apiRequest({_ in}, baseURL: baseURL, resource: resource, failure: defaultFailureHandler, completion: completion)
|
||||
}
|
||||
}
|
||||
|
||||
*/
|
||||
/*
|
||||
func sentButUnreadMessages(failureHandler failureHandler: ((Reason, String?) -> Void)?, completion: JSONDictionary -> Void) {
|
||||
|
||||
@@ -1730,7 +1731,7 @@ func sentButUnreadMessages(failureHandler failureHandler: ((Reason, String?) ->
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
/*
|
||||
func unreadMessages(failureHandler failureHandler: ((Reason, String?) -> Void)?, completion: [JSONDictionary] -> Void) {
|
||||
|
||||
headUnreadMessages(failureHandler: failureHandler) { result in
|
||||
@@ -1786,6 +1787,58 @@ func unreadMessages(failureHandler failureHandler: ((Reason, String?) -> Void)?,
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
func unreadMessages(failureHandler failureHandler: ((Reason, String?) -> Void)?, completion: [JSONDictionary] -> Void) {
|
||||
|
||||
let parse: JSONDictionary -> [JSONDictionary]? = { data in
|
||||
|
||||
guard let conversationsData = data["conversations"] as? [JSONDictionary] else {
|
||||
return nil
|
||||
}
|
||||
|
||||
guard let realm = try? Realm() else {
|
||||
return nil
|
||||
}
|
||||
|
||||
var messages = [JSONDictionary]()
|
||||
|
||||
for conversationInfo in conversationsData {
|
||||
if let type = conversationInfo["conversation_type"] as? String, recipientInfo = conversationInfo["conversation"] as? JSONDictionary, unreadMessagesCount = conversationInfo["count"] as? Int {
|
||||
|
||||
var recipient: Recipient?
|
||||
switch type {
|
||||
case ConversationType.OneToOne.nameForServer:
|
||||
if let userID = recipientInfo["id"] as? String {
|
||||
recipient = Recipient(type: .OneToOne, ID: userID)
|
||||
}
|
||||
case ConversationType.Group.nameForServer:
|
||||
if let groupID = recipientInfo["id"] as? String {
|
||||
recipient = Recipient(type: .Group, ID: groupID)
|
||||
}
|
||||
default:
|
||||
break
|
||||
}
|
||||
|
||||
if let recipient = recipient, conversation = recipient.conversationInRealm(realm) {
|
||||
let _ = try? realm.write {
|
||||
conversation.unreadMessagesCount = unreadMessagesCount
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if let messagesData = conversationInfo["messages"] as? [JSONDictionary] {
|
||||
messages += messagesData
|
||||
}
|
||||
}
|
||||
|
||||
return messages
|
||||
}
|
||||
|
||||
let resource = authJsonResource(path: "/api/v2/messages/unread", method: .GET, requestParameters: [:], parse: parse)
|
||||
|
||||
apiRequest({_ in}, baseURL: baseURL, resource: resource, failure: defaultFailureHandler, completion: completion)
|
||||
}
|
||||
|
||||
struct Recipient {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user