in src/components/attachments-row/attachment-actions.ts [214:262]
uploadFileToArticleComment: function (
files: NormalizedAttachment[],
comment: Partial<IssueComment>,
) {
return async (
dispatch: (arg0: any) => any,
getState: StateGetter,
getApi: ApiGetter,
): Promise<Attachment[]> => {
logEvent({
message: 'Attaching file to a comment',
analyticsId: ANALYTICS_ARTICLE_PAGE_STREAM,
});
const api: Api = getApi();
const entityId: string = getState().article.article.id;
const isDraftComment: boolean = comment.$type === ResourceTypes.DRAFT_ARTICLE_COMMENT;
const commentId: string | undefined = isDraftComment ? undefined : comment.id;
const [error, addedAttachments]: [CustomError | null, Attachment[]] = await until(
files.map((file: NormalizedAttachment) =>
api.articles.attachFileToComment(
entityId,
file,
commentId,
),
),
true,
) as [CustomError | null, Attachment[]];
if (error) {
notifyError(error);
return [];
} else {
dispatch(actions.stopImageAttaching());
dispatch(actions.toggleAttachFileDialog(false));
const visibility: Visibility | undefined = files[0].visibility;
if (visibility) {
const [err, attachmentsWithVisibility]: [CustomError | null, Attachment[]] = await until(
addedAttachments.map(
(attach: Attachment) => api.articles.updateAttachmentVisibility(entityId, attach, visibility)
),
true,
) as [CustomError | null, Attachment[]];
return err ? addedAttachments : attachmentsWithVisibility;
} else {
return addedAttachments;
}
}
};
},