galley-0.83.0: Conversations
Safe HaskellSafe-Inferred
LanguageGHC2021

Galley.API.One2One

Synopsis

Documentation

one2OneConvId :: BaseProtocolTag -> Qualified UserId -> Qualified UserId -> Qualified ConvId Source #

This function returns the 1-1 conversation for a given pair of users.

Let A, B denote the (not necessarily distinct) backends of the two users, with the domain of A less or equal than the domain of B in the lexicographic ordering of their ascii encodings. Given users aA and bB, the UUID and owning domain of the unique 1-1 conversation between a and b shall be a deterministic function of the input data, plus some fixed parameters, as described below.

Parameters

  • A (collision-resistant) hash function h with N bits of output, where N s a multiple of 8 strictly larger than 128; this is set to SHA256.
  • A "namespace" UUID n.

Algorithm

First, in the special case where A and B are the same backend, assume that the UUID of a is lower than that of b. If that is not the case, swap a and b in the following. This is necessary to ensure that the function we describe below is symmetric in its arguments. Let c be the bytestring obtained as the concatenation of the following 5 components:

  • the 16 bytes of the namespace n
  • the 16 bytes of the UUID of a
  • the ascii encoding of the domain of A
  • the 16 bytes of the UUID of b
  • the ascii encoding of the domain of B,

and let x = h(c) be its hashed value. The UUID of the 1-1 conversation between a and b is obtained by converting the first 128 bits of x to a UUID V5. Note that our use of V5 here is not strictly compliant with RFC 4122, since we are using a custom hash and not necessarily SHA1.

The owning domain for the conversation is set to be A if bit 128 of x (i.e. the most significant bit of the octet at index 16) is 0, and B otherwise. This is well-defined, because we assumed the number of bits of x to be strictly larger than 128.