Commit bab9ced1 authored by Alejandro Celaya's avatar Alejandro Celaya Committed by Alejandro Celaya

Migrate annotation-user to TypeScript

parent ac984496
/** import type { Annotation } from '../../types/api';
* @typedef {import("../../types/api").Annotation} Annotation import type { SidebarSettings } from '../../types/config';
* @typedef {import('../../types/config').SidebarSettings} SidebarSettings
*/
import { isThirdPartyUser, username } from './account-id'; import { isThirdPartyUser, username } from './account-id';
/** /**
...@@ -15,18 +13,12 @@ import { isThirdPartyUser, username } from './account-id'; ...@@ -15,18 +13,12 @@ import { isThirdPartyUser, username } from './account-id';
* *
* Return the string that should be used for display on an annotation: either the * Return the string that should be used for display on an annotation: either the
* username or the display name. * username or the display name.
*
* @param {Pick<Annotation, 'user'|'user_info'>} annotation
* @param {string} defaultAuthority
* @param {boolean} displayNamesEnabled
*
* @return {string}
*/ */
export function annotationDisplayName( export function annotationDisplayName(
annotation, annotation: Pick<Annotation, 'user' | 'user_info'>,
defaultAuthority, defaultAuthority: string,
displayNamesEnabled displayNamesEnabled: boolean
) { ): string {
const isThirdParty = isThirdPartyUser(annotation.user, defaultAuthority); const isThirdParty = isThirdPartyUser(annotation.user, defaultAuthority);
const useDisplayName = displayNamesEnabled || isThirdParty; const useDisplayName = displayNamesEnabled || isThirdParty;
...@@ -39,18 +31,13 @@ export function annotationDisplayName( ...@@ -39,18 +31,13 @@ export function annotationDisplayName(
* Return a URL to the annotation author's user page, when available. Author * Return a URL to the annotation author's user page, when available. Author
* links for third-party users are only available if a `usernameUrl` is * links for third-party users are only available if a `usernameUrl` is
* provided in `settings`. * provided in `settings`.
*
* @param {Pick<Annotation, 'user'>} annotation
* @param {SidebarSettings} settings
* @param {string} defaultAuthority
* @param {string} [userLink]
*/ */
export function annotationAuthorLink( export function annotationAuthorLink(
annotation, annotation: Pick<Annotation, 'user'>,
settings, settings: SidebarSettings,
defaultAuthority, defaultAuthority: string,
userLink userLink?: string
) { ): string | undefined {
const isThirdParty = isThirdPartyUser(annotation.user, defaultAuthority); const isThirdParty = isThirdPartyUser(annotation.user, defaultAuthority);
if (!isThirdParty && userLink) { if (!isThirdParty && userLink) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment