提交 8e42065f 编写于 作者: T Tomas Vik

fix: support displaying users without avatars

上级 0bc6135b
......@@ -32,7 +32,9 @@ export class MrItemModel extends ItemModel {
`!${iid} · ${title}`,
vscode.TreeItemCollapsibleState.Collapsed,
);
item.iconPath = vscode.Uri.parse(author.avatar_url);
if (author.avatar_url) {
item.iconPath = vscode.Uri.parse(author.avatar_url);
}
return item;
}
......@@ -91,7 +93,7 @@ export class MrItemModel extends ItemModel {
mode: vscode.CommentMode.Preview,
author: {
name: author.name,
iconPath: vscode.Uri.parse(author.avatarUrl),
iconPath: author.avatarUrl !== null ? vscode.Uri.parse(author.avatarUrl) : undefined,
},
}));
const position = notes.nodes[0]?.position as GqlPosition; // we filtered out all discussions without position
......
......@@ -8,7 +8,7 @@ import * as assert from 'assert';
import { tokenService } from '../services/token_service';
import { FetchError } from '../errors/fetch_error';
import { getUserAgentHeader } from '../utils/get_user_agent_header';
import { getAvatarUrl } from '../utils/get_avatar_url';
import { ensureAbsoluteAvatarUrl } from '../utils/ensure_absolute_avatar_url';
import { getHttpAgentOptions } from '../utils/get_http_agent_options';
import { GitLabProject, GqlProject } from './gitlab_project';
import { getRestIdFromGraphQLId } from '../utils/get_rest_id_from_graphql_id';
......@@ -43,15 +43,15 @@ export interface GqlBlob {
path: string;
}
interface GqlNoteAuthor {
avatarUrl: string;
interface GqlUser {
avatarUrl: string | null;
name: string;
username: string;
webUrl: string;
}
interface GqlNote {
id: string;
author: GqlNoteAuthor;
author: GqlUser;
createdAt: string;
system: boolean;
body: string; // TODO: remove this once the SystemNote.vue doesn't require plain text body
......@@ -335,7 +335,8 @@ export class GitLabNewService {
bodyHtml: note.bodyHtml.replace(/href="\//, `href="${this.instanceUrl}/`),
author: {
...note.author,
avatarUrl: getAvatarUrl(this.instanceUrl, note.author.avatarUrl),
avatarUrl:
note.author.avatarUrl && ensureAbsoluteAvatarUrl(this.instanceUrl, note.author.avatarUrl),
},
});
return {
......
......@@ -12,7 +12,7 @@ import { handleError, logError } from './log';
import { getUserAgentHeader } from './utils/get_user_agent_header';
import { CustomQueryType } from './gitlab/custom_query_type';
import { CustomQuery } from './gitlab/custom_query';
import { getAvatarUrl } from './utils/get_avatar_url';
import { ensureAbsoluteAvatarUrl } from './utils/ensure_absolute_avatar_url';
import { getHttpAgentOptions } from './utils/get_http_agent_options';
import { getInstanceUrl as getInstanceUrlUtil } from './utils/get_instance_url';
import { GitLabProject } from './gitlab/gitlab_project';
......@@ -27,13 +27,19 @@ interface GitLabJob {
created_at: string;
}
const normalizeAvatarUrl = (instanceUrl: string) => (issuable: RestIssuable): RestIssuable => ({
...issuable,
author: {
...issuable.author,
avatar_url: getAvatarUrl(instanceUrl, issuable.author.avatar_url),
},
});
const normalizeAvatarUrl = (instanceUrl: string) => (issuable: RestIssuable): RestIssuable => {
const { author } = issuable;
if (!author.avatar_url) {
return issuable;
}
return {
...issuable,
author: {
...author,
avatar_url: ensureAbsoluteAvatarUrl(instanceUrl, author.avatar_url),
},
};
};
const projectCache: Record<string, GitLabProject> = {};
let versionCache: string | null = null;
......
......@@ -13,7 +13,7 @@ interface RestIssuable {
title: string;
project_id: number;
web_url: string;
author: { name: string; avatar_url: string };
author: { name: string; avatar_url: string | null };
sha?: string; // only present in MR, legacy logic uses the presence to decide issuable type
references: {
full: string; // e.g. "gitlab-org/gitlab#219925"
......
import * as vscode from 'vscode';
export const getAvatarUrl = (instanceUrl: string, avatarUrl: string): string => {
export const ensureAbsoluteAvatarUrl = (instanceUrl: string, avatarUrl: string): string => {
if (!avatarUrl.startsWith('/')) {
return avatarUrl;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册