Changeset View
Changeset View
Standalone View
Standalone View
keyserver/src/responders/activity-responders.js
// @flow | // @flow | ||||
import t from 'tcomb'; | import t from 'tcomb'; | ||||
import type { TList } from 'tcomb'; | import type { TList } from 'tcomb'; | ||||
import type { | import { | ||||
UpdateActivityResult, | type UpdateActivityResult, | ||||
UpdateActivityRequest, | type UpdateActivityRequest, | ||||
SetThreadUnreadStatusRequest, | type SetThreadUnreadStatusRequest, | ||||
SetThreadUnreadStatusResult, | type SetThreadUnreadStatusResult, | ||||
ActivityUpdate, | type ActivityUpdate, | ||||
setThreadUnreadStatusResult, | |||||
updateActivityResultValidator, | |||||
} from 'lib/types/activity-types.js'; | } from 'lib/types/activity-types.js'; | ||||
import { tShape } from 'lib/utils/validation-utils.js'; | import { tShape } from 'lib/utils/validation-utils.js'; | ||||
import type { Viewer } from '../session/viewer.js'; | import type { Viewer } from '../session/viewer.js'; | ||||
import { | import { | ||||
activityUpdater, | activityUpdater, | ||||
setThreadUnreadStatus, | setThreadUnreadStatus, | ||||
} from '../updaters/activity-updaters.js'; | } from '../updaters/activity-updaters.js'; | ||||
import { validateInput } from '../utils/validation-utils.js'; | import { validateInput, validateOutput } from '../utils/validation-utils.js'; | ||||
const activityUpdatesInputValidator: TList<Array<ActivityUpdate>> = t.list( | const activityUpdatesInputValidator: TList<Array<ActivityUpdate>> = t.list( | ||||
tShape({ | tShape({ | ||||
focus: t.Bool, | focus: t.Bool, | ||||
threadID: t.String, | threadID: t.String, | ||||
latestMessage: t.maybe(t.String), | latestMessage: t.maybe(t.String), | ||||
}), | }), | ||||
); | ); | ||||
const inputValidator = tShape({ | const inputValidator = tShape({ | ||||
updates: activityUpdatesInputValidator, | updates: activityUpdatesInputValidator, | ||||
}); | }); | ||||
async function updateActivityResponder( | async function updateActivityResponder( | ||||
viewer: Viewer, | viewer: Viewer, | ||||
input: any, | input: any, | ||||
): Promise<UpdateActivityResult> { | ): Promise<UpdateActivityResult> { | ||||
const request: UpdateActivityRequest = input; | const request: UpdateActivityRequest = input; | ||||
await validateInput(viewer, inputValidator, request); | await validateInput(viewer, inputValidator, request); | ||||
return await activityUpdater(viewer, request); | const result = await activityUpdater(viewer, request); | ||||
return validateOutput(viewer, updateActivityResultValidator, result); | |||||
} | } | ||||
const setThreadUnreadStatusValidator = tShape({ | const setThreadUnreadStatusValidator = tShape({ | ||||
threadID: t.String, | threadID: t.String, | ||||
unread: t.Bool, | unread: t.Bool, | ||||
latestMessage: t.maybe(t.String), | latestMessage: t.maybe(t.String), | ||||
}); | }); | ||||
async function threadSetUnreadStatusResponder( | async function threadSetUnreadStatusResponder( | ||||
viewer: Viewer, | viewer: Viewer, | ||||
input: any, | input: any, | ||||
): Promise<SetThreadUnreadStatusResult> { | ): Promise<SetThreadUnreadStatusResult> { | ||||
const request: SetThreadUnreadStatusRequest = input; | const request: SetThreadUnreadStatusRequest = input; | ||||
await validateInput(viewer, setThreadUnreadStatusValidator, request); | await validateInput(viewer, setThreadUnreadStatusValidator, request); | ||||
return await setThreadUnreadStatus(viewer, request); | const result = await setThreadUnreadStatus(viewer, request); | ||||
return validateOutput(viewer, setThreadUnreadStatusResult, result); | |||||
} | } | ||||
export { | export { | ||||
activityUpdatesInputValidator, | activityUpdatesInputValidator, | ||||
updateActivityResponder, | updateActivityResponder, | ||||
threadSetUnreadStatusResponder, | threadSetUnreadStatusResponder, | ||||
}; | }; |