The Talk Object
Monday, November 23, 2020 2:06 AMThe Talk
object provides utility functions to help use TalkJS.
ready
Talk.ready.then(function() {
// Use TalkJS after it has fully loaded
})
oneOnOneId
Talk.oneOnOneId(me, other)
Use this helper method to predictably compute a Conversation ID based on participants' ids in the given conversation. Use this method if you want to simply create a conversation between two users, not related to a particular product, order or transaction.
The order of the parameters does not matter. For example, Talk.oneOnOneId("a", "b")
yields the same result as Talk.oneOnOneId("b", "a")
.
- Take two ids of users and put them in an array
- Sort them lexicographically
- JSON encode them
- Hash the result using SHA1, return the first 20 characters
In pseudocode, this is what this function does:
var sorted = [me.id, other.id].sort()
var encoded = JSON.encode(sorted)
var hash = sha1(encoded) // as lowercase hex
return truncate(hash, 20)
Parameters
me User | string |
A TalkJS User or a string containing the user ID. |
other User | string |
Another TalkJS User or a string containing the user ID. |