Skip to content

Instantly share code, notes, and snippets.

@Bashta
Created June 8, 2016 09:25
Show Gist options
  • Save Bashta/68d9280e3acc455c3179a6901a00a7d4 to your computer and use it in GitHub Desktop.
Save Bashta/68d9280e3acc455c3179a6901a00a7d4 to your computer and use it in GitHub Desktop.
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