aboutsummaryrefslogtreecommitdiff
path: root/Timeline/ClientApp/src/app/data/user.ts
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2020-07-31 01:16:10 +0800
committerGitHub <noreply@github.com>2020-07-31 01:16:10 +0800
commitfe950cad28ec6ff7bf6f399ddd31448180bc7601 (patch)
treed58a7c9a33a4cf16b128d71b94edf0110298bd13 /Timeline/ClientApp/src/app/data/user.ts
parentd900c1b8c012970db491f421e1975f5de3b450f3 (diff)
parentb8cf8379358958c1155442d0526bbfc8c4d65ded (diff)
downloadtimeline-fe950cad28ec6ff7bf6f399ddd31448180bc7601.tar.gz
timeline-fe950cad28ec6ff7bf6f399ddd31448180bc7601.tar.bz2
timeline-fe950cad28ec6ff7bf6f399ddd31448180bc7601.zip
Merge pull request #127 from crupest/offline-post
Add feature of offline post cache.
Diffstat (limited to 'Timeline/ClientApp/src/app/data/user.ts')
-rw-r--r--Timeline/ClientApp/src/app/data/user.ts14
1 files changed, 9 insertions, 5 deletions
diff --git a/Timeline/ClientApp/src/app/data/user.ts b/Timeline/ClientApp/src/app/data/user.ts
index 1be5cd3e..dec9929f 100644
--- a/Timeline/ClientApp/src/app/data/user.ts
+++ b/Timeline/ClientApp/src/app/data/user.ts
@@ -233,8 +233,12 @@ export class UserNotExistError extends Error {}
export type AvatarInfo = BlobWithUrl;
export class UserInfoService {
- private _avatarSubscriptionHub = new SubscriptionHub<string, AvatarInfo>(
+ private _avatarSubscriptionHub = new SubscriptionHub<
+ string,
+ AvatarInfo | null
+ >(
(key) => key,
+ () => null,
async (key) => {
const blob = (await getHttpUserClient().getAvatar(key)).data;
const url = URL.createObjectURL(blob);
@@ -244,7 +248,7 @@ export class UserInfoService {
};
},
(_key, data) => {
- URL.revokeObjectURL(data.url);
+ if (data != null) URL.revokeObjectURL(data.url);
}
);
@@ -265,7 +269,7 @@ export class UserInfoService {
);
}
- get avatarHub(): ISubscriptionHub<string, AvatarInfo> {
+ get avatarHub(): ISubscriptionHub<string, AvatarInfo | null> {
return this._avatarSubscriptionHub;
}
}
@@ -284,8 +288,8 @@ export function useAvatarUrl(username?: string): string | undefined {
const subscription = userInfoService.avatarHub.subscribe(
username,
- ({ url }) => {
- setAvatarUrl(url);
+ (info) => {
+ setAvatarUrl(info?.url);
}
);
return () => {