It's cumbersome for the library users to specify domain ID to
use some APIs.
Before this commit, createPairTalk implicitly calls getDomains
to obtain all domains the logged-in user belongs to, then choose
the first domain's ID from the result.
But there're several problems in this way:
If the logged-in user belongs to several domains, createPairTalk
can try to make a pair talk with user who doesn't belong to the
domain, which would cause an error.
Calling getDomains every time is inefficient.
Solution
Add clientCurrentDomain :: Domain to Client with its getter
and setter.
Used for some RPC functions which requires a domain ID for
its argument (e.g. createPairTalk, createUploadAuth).
Can be updated with setCurrentDomain if required.
Add directInitialDomainId :: Maybe DomainId to Config
for the library users to specify the domain ID by themselves.
If Nothing (by default), withClient calls getDomains
to obtain all domains the logged-in user belongs to, then choose
the first domain's ID from the result.
It's just like createPairTalk before this commit does.
And it frees the library users from specifying a domain ID
every time, as well as enable them to customize a domain ID!
Problem
It's cumbersome for the library users to specify domain ID to use some APIs. Before this commit,
createPairTalk
implicitly callsgetDomains
to obtain all domains the logged-in user belongs to, then choose the first domain's ID from the result.But there're several problems in this way:
createPairTalk
can try to make a pair talk with user who doesn't belong to the domain, which would cause an error.getDomains
every time is inefficient.Solution
clientCurrentDomain :: Domain
toClient
with its getter and setter.createPairTalk
,createUploadAuth
).setCurrentDomain
if required.directInitialDomainId :: Maybe DomainId
toConfig
for the library users to specify the domain ID by themselves.Nothing
(by default),withClient
callsgetDomains
to obtain all domains the logged-in user belongs to, then choose the first domain's ID from the result. It's just likecreatePairTalk
before this commit does. And it frees the library users from specifying a domain ID every time, as well as enable them to customize a domain ID!