|
2 | 2 | import { Strings } from '../../system'; |
3 | 3 | import { Uri } from 'vscode'; |
4 | 4 | import { GitCommit, GitCommitType } from './commit'; |
| 5 | +import { GravatarDefault } from '../../configuration'; |
5 | 6 | import { Git } from '../git'; |
6 | 7 | import { GitStatusFileStatus, IGitStatusFile } from './status'; |
7 | 8 | import * as path from 'path'; |
8 | 9 |
|
9 | 10 | const gravatarCache: Map<string, Uri> = new Map(); |
10 | 11 |
|
| 12 | +export function clearGravatarCache() { |
| 13 | + gravatarCache.clear(); |
| 14 | +} |
| 15 | + |
11 | 16 | export class GitLogCommit extends GitCommit { |
12 | 17 |
|
13 | 18 | nextSha?: string; |
@@ -43,27 +48,6 @@ export class GitLogCommit extends GitCommit { |
43 | 48 | ); |
44 | 49 | } |
45 | 50 |
|
46 | | - get gravatarUri(): Uri { |
47 | | - const key = this.email |
48 | | - ? this.email.trim().toLowerCase() |
49 | | - : ''; |
50 | | - |
51 | | - let gravatar = gravatarCache.get(key); |
52 | | - if (gravatar !== undefined) return gravatar; |
53 | | - |
54 | | - gravatar = Uri.parse(`https://www.gravatar.com/avatar/${this.email ? Strings.md5(this.email) : '00000000000000000000000000000000'}.jpg?s=22&d=retro`); |
55 | | - |
56 | | - // HACK: Monkey patch Uri.toString to avoid the unwanted query string encoding |
57 | | - const originalToStringFn = gravatar.toString; |
58 | | - gravatar.toString = function(skipEncoding?: boolean | undefined) { |
59 | | - return originalToStringFn.call(gravatar, true); |
60 | | - }; |
61 | | - |
62 | | - gravatarCache.set(key, gravatar); |
63 | | - |
64 | | - return gravatar; |
65 | | - } |
66 | | - |
67 | 51 | get isMerge() { |
68 | 52 | return this.parentShas && this.parentShas.length > 1; |
69 | 53 | } |
@@ -107,6 +91,27 @@ export class GitLogCommit extends GitCommit { |
107 | 91 | return `+${added} ~${changed} -${deleted}`; |
108 | 92 | } |
109 | 93 |
|
| 94 | + getGravatarUri(fallback: GravatarDefault): Uri { |
| 95 | + const key = this.email |
| 96 | + ? `${ this.email.trim().toLowerCase() }` |
| 97 | + : ''; |
| 98 | + |
| 99 | + let gravatar = gravatarCache.get(key); |
| 100 | + if (gravatar !== undefined) return gravatar; |
| 101 | + |
| 102 | + gravatar = Uri.parse(`https://www.gravatar.com/avatar/${this.email ? Strings.md5(this.email) : '00000000000000000000000000000000'}.jpg?s=22&d=${fallback}`); |
| 103 | + |
| 104 | + // HACK: Monkey patch Uri.toString to avoid the unwanted query string encoding |
| 105 | + const originalToStringFn = gravatar.toString; |
| 106 | + gravatar.toString = function(skipEncoding?: boolean | undefined) { |
| 107 | + return originalToStringFn.call(gravatar, true); |
| 108 | + }; |
| 109 | + |
| 110 | + gravatarCache.set(key, gravatar); |
| 111 | + |
| 112 | + return gravatar; |
| 113 | + } |
| 114 | + |
110 | 115 | toFileCommit(fileName: string): GitLogCommit | undefined; |
111 | 116 | toFileCommit(status: IGitStatusFile): GitLogCommit; |
112 | 117 | toFileCommit(fileNameOrStatus: string | IGitStatusFile): GitLogCommit | undefined { |
|
0 commit comments