Created
June 8, 2016 09:25
-
-
Save Bashta/68d9280e3acc455c3179a6901a00a7d4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func createNewChatSessionForCurrentUser(otherUserId: String) -> String? { | |
guard let currentUserUsername = Backendless.sharedInstance().userService.currentUser.name else { | |
return nil | |
} | |
let chatId = Backendless.sharedInstance().randomString(36) | |
let curentUserChatDictionary = ["groupChat" : false, "singleChatMember" : otherUserId] | |
let otherUserChatDictionary = ["groupChat" : false, "singleChatMember" : currentUserUsername] | |
let chatDictionary = [otherUserId : 0, currentUserUsername : 0] | |
let chatIdDictionary = ["chatId" : chatId] | |
Firebase(url: "\(GlobalConstants.Firebase.FirebaseBaseUrl)/userChats/\(currentUserUsername)/chats/\(chatId)").setValue(curentUserChatDictionary) | |
Firebase(url: "\(GlobalConstants.Firebase.FirebaseBaseUrl)/userChats/\(otherUserId)/chats/\(chatId)").setValue(otherUserChatDictionary) | |
Firebase(url: "\(GlobalConstants.Firebase.FirebaseBaseUrl)/chats/\(chatId)/info/members").setValue(chatDictionary) | |
Firebase(url: "\(GlobalConstants.Firebase.FirebaseBaseUrl)/chats/\(chatId)/info").setValue(chatIdDictionary) | |
return chatId | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment