oneOnOneId static method
NOTE: If this function changes make sure to update the documentation in The_Talk_Object.md
A 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")
.
This method takes the following steps:
- 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)
return truncate(hash, 20)
For a PHP implementation, see https://gist.github.com/eteeselink/4dc3ad32cc478986ff2b5b6361a1825f. {@link https://talkjs.com/?chat | Get in touch} if you need our help implementing this in your backend language. @public
Implementation
static String oneOnOneId(
dynamic /*User|String*/ me,
dynamic /*User|String*/ other,
) {
return interop.oneOnOneId(me, other);
}