Browse Source

Ensures default gravatar style

main
Eric Amodio 2 years ago
parent
commit
f0266a59f3
2 changed files with 21 additions and 13 deletions
  1. +19
    -11
      src/avatars.ts
  2. +2
    -2
      src/container.ts

+ 19
- 11
src/avatars.ts View File

@ -1,5 +1,6 @@
import { EventEmitter, Uri } from 'vscode';
import { GravatarDefaultStyle } from './config';
import { configuration } from './configuration';
import { ContextKeys } from './constants';
import { Container } from './container';
import { getContext } from './context';
@ -186,19 +187,13 @@ function hasAvatarExpired(avatar: Avatar) {
return Date.now() >= avatar.timestamp + retryDecay[Math.min(avatar.retries, retryDecay.length - 1)];
}
function getAvatarUriFromGravatar(
hash: string,
size: number,
defaultStyle: GravatarDefaultStyle = GravatarDefaultStyle.Robot,
): Uri {
return Uri.parse(`https://www.gravatar.com/avatar/${hash}?s=${size}&d=${defaultStyle}`);
function getAvatarUriFromGravatar(hash: string, size: number, defaultStyle?: GravatarDefaultStyle): Uri {
return Uri.parse(
`https://www.gravatar.com/avatar/${hash}?s=${size}&d=${defaultStyle ?? getDefaultGravatarStyle()}`,
);
}
export function getAvatarUriFromGravatarEmail(
email: string,
size: number,
defaultStyle: GravatarDefaultStyle = GravatarDefaultStyle.Robot,
): Uri {
export function getAvatarUriFromGravatarEmail(email: string, size: number, defaultStyle?: GravatarDefaultStyle): Uri {
return getAvatarUriFromGravatar(md5(email.trim().toLowerCase(), 'hex'), size, defaultStyle);
}
@ -307,3 +302,16 @@ export function resetAvatarCache(reset: 'all' | 'failed' | 'fallback') {
break;
}
}
let defaultGravatarsStyle: GravatarDefaultStyle | undefined = undefined;
function getDefaultGravatarStyle() {
if (defaultGravatarsStyle == null) {
defaultGravatarsStyle = configuration.get('defaultGravatarsStyle', undefined, GravatarDefaultStyle.Robot);
}
return defaultGravatarsStyle;
}
export function setDefaultGravatarsStyle(style: GravatarDefaultStyle) {
defaultGravatarsStyle = style;
resetAvatarCache('fallback');
}

+ 2
- 2
src/container.ts View File

@ -5,7 +5,7 @@ import { Autolinks } from './annotations/autolinks';
import { FileAnnotationController } from './annotations/fileAnnotationController';
import { LineAnnotationController } from './annotations/lineAnnotationController';
import { ActionRunners } from './api/actionRunners';
import { resetAvatarCache } from './avatars';
import { setDefaultGravatarsStyle } from './avatars';
import { GitCodeLensController } from './codelens/codeLensController';
import type { ToggleFileAnnotationCommandArgs } from './commands';
import type { FileAnnotationType, ModeConfig } from './configuration';
@ -253,7 +253,7 @@ export class Container {
}
if (configuration.changed(e, 'defaultGravatarsStyle')) {
resetAvatarCache('fallback');
setDefaultGravatarsStyle(configuration.get('defaultGravatarsStyle'));
}
if (configuration.changed(e, 'mode')) {

Loading…
Cancel
Save