Skip to content

Commit 29192d5

Browse files
authored
fix(WhoIsActivve): remove zero value (qiuwenbaike#1678)
* fix(WhoIsActivve): remove zero value
1 parent ee9382a commit 29192d5

File tree

4 files changed

+39
-24
lines changed

4 files changed

+39
-24
lines changed

dist/WhoIsActive/WhoIsActive.js

Lines changed: 17 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/WhoIsActive/modules/util/appendLastActiveMarker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const appendLastActiveMarker = async ({usernames, $elements}: {usernames: string
1010
continue;
1111
}
1212

13-
const timestamp = (await getTimestamp(username)) ?? '0';
13+
const timestamp = await getTimestamp(username);
1414

1515
if (!timestamp) {
1616
continue;

src/WhoIsActive/modules/util/appendLastActiveMarkerToUserPage.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const appendLastActiveMarkerToUserPage = async (username: string) => {
88
return;
99
}
1010

11-
const timestamp = (await getTimestamp(username)) ?? '0';
11+
const timestamp = await getTimestamp(username);
1212

1313
if (!timestamp) {
1414
return;

src/WhoIsActive/modules/util/getTimestamp.ts

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -64,18 +64,28 @@ const getLogEventsTimestamp = async (leuser: string) => {
6464
return timestamp;
6565
};
6666

67-
const getTimestamp = async (username: string) => {
68-
let timestamp: string;
67+
const getTimestamp = async (username: string): Promise<string | undefined> => {
68+
let timestamp: string | undefined;
6969

70-
if (mw.storage.get(OPTIONS.storageKey + username)) {
71-
timestamp = mw.storage.get(OPTIONS.storageKey + username) as string;
70+
if (mw.storage.getObject(OPTIONS.storageKey + username)) {
71+
timestamp = mw.storage.getObject(OPTIONS.storageKey + username) as string;
7272
} else {
73-
const ucTimestamp = (await getUserContribsTimestamp(username)) ?? '0';
74-
const leTimestamp = (await getLogEventsTimestamp(username)) ?? '0';
75-
timestamp = Number.parseInt(ucTimestamp, 10) > Number.parseInt(leTimestamp, 10) ? ucTimestamp : leTimestamp;
76-
77-
// Cache for 10 minutes
78-
mw.storage.set(OPTIONS.storageKey + username, timestamp, 10 * 60);
73+
const ucTimestamp = await getUserContribsTimestamp(username);
74+
const leTimestamp = await getLogEventsTimestamp(username);
75+
76+
if (ucTimestamp || leTimestamp) {
77+
if (ucTimestamp && leTimestamp) {
78+
timestamp =
79+
Number.parseInt(ucTimestamp, 10) > Number.parseInt(leTimestamp, 10) ? ucTimestamp : leTimestamp;
80+
} else {
81+
timestamp = ucTimestamp || leTimestamp;
82+
}
83+
84+
// Cache for 10 minutes
85+
mw.storage.setObject(OPTIONS.storageKey + username, timestamp, 10 * 60);
86+
} else {
87+
timestamp = undefined;
88+
}
7989
}
8090

8191
return timestamp;

0 commit comments

Comments
 (0)