Log the user in and return a fact that represents their identity. This method is only valid in the browser.
login<U>(
): Promise<{
userFact: U;
profile: Profile
}>;
None
Display messages sent to the logged in user.
function messagesToUser(u) {
return j.match({
type: 'Chat.Message',
to: u
});
}
function displayMessage(m) {
// Show the message on the UI.
}
const { userFact } = await j.login();
j.watch(userFact, j.for(messagesToUser), displayMessage);
Create a fact representing the user's display name so that other people can read it.
function namesForUser(u) {
return j.match({
type: 'Chat.User.Name',
user: u
}).suchThat(nameIsCurrent);
}
function nameIsCurrent(n) {
return j.notExists({
type: 'Chat.User.Name',
prior: [n]
});
}
const { userFact, profile } = await j.login();
const names = await j.query(userFact, j.for(namesForUser));
if (names.length != 1 || names[0].value !== profile.displayName) {
await j.fact({
type: 'Chat.User.Name',
user: userFact,
prior: names,
value: profile.displayName
});
}