YouBar+: track custom status text instead of game/stream activity
This commit is contained in:
parent
14152f92e3
commit
96eff341ce
1 changed files with 16 additions and 17 deletions
|
|
@ -14,18 +14,13 @@ const MessageStore = findByStoreName("MessageStore");
|
||||||
const GuildMemberStore = findByStoreName("GuildMemberStore");
|
const GuildMemberStore = findByStoreName("GuildMemberStore");
|
||||||
const RelationshipStore = findByStoreName("RelationshipStore");
|
const RelationshipStore = findByStoreName("RelationshipStore");
|
||||||
|
|
||||||
// 0 Playing, 1 Streaming, 2 Listening, 3 Watching, 4 Custom, 5 Competing - Discord's public
|
// ActivityTypes.CUSTOM_STATUS - confirmed against the decompiled bundle's getActivityFromCustomStatus,
|
||||||
// Gateway ActivityType enum, stable across clients/builds.
|
// which builds {name: "Custom Status", type: 4, state: <the actual text>, emoji}. name is always the
|
||||||
const ACTIVITY_VERBS: Record<number, string> = {
|
// literal label "Custom Status", never the user's text - state is what actually holds it.
|
||||||
0: "Playing",
|
const ACTIVITY_TYPE_CUSTOM_STATUS = 4;
|
||||||
1: "Streaming",
|
|
||||||
2: "Listening to",
|
|
||||||
3: "Watching",
|
|
||||||
5: "Competing in",
|
|
||||||
};
|
|
||||||
|
|
||||||
// Last-seen activity signature per user, so PRESENCE_UPDATE's frequent re-fires for the same
|
// Last-seen custom status per user, so PRESENCE_UPDATES' frequent re-fires don't spam a fresh
|
||||||
// ongoing activity (elapsed time ticking, etc.) don't spam a fresh notification every time.
|
// notification for the same still-active status.
|
||||||
const lastActivitySignature = new Map<string, string>();
|
const lastActivitySignature = new Map<string, string>();
|
||||||
|
|
||||||
// RelationshipTypes.PENDING_INCOMING - confirmed against the decompiled Discord bundle
|
// RelationshipTypes.PENDING_INCOMING - confirmed against the decompiled Discord bundle
|
||||||
|
|
@ -279,22 +274,26 @@ function handlePresenceUpdate(update: any) {
|
||||||
if (user.bot) return;
|
if (user.bot) return;
|
||||||
|
|
||||||
const activities = update?.activities;
|
const activities = update?.activities;
|
||||||
const activity = Array.isArray(activities) ? activities.find((a: any) => a?.type !== 4) : undefined;
|
const customStatus = Array.isArray(activities)
|
||||||
|
? activities.find((a: any) => a?.type === ACTIVITY_TYPE_CUSTOM_STATUS)
|
||||||
|
: undefined;
|
||||||
|
const statusText: string = customStatus?.state || "";
|
||||||
|
const emojiName: string | undefined = customStatus?.emoji?.name;
|
||||||
|
|
||||||
const signature = activity ? `${activity.type}:${activity.name}` : "";
|
const signature = statusText || emojiName || "";
|
||||||
if (lastActivitySignature.get(userId) === signature) return;
|
if (lastActivitySignature.get(userId) === signature) return;
|
||||||
lastActivitySignature.set(userId, signature);
|
lastActivitySignature.set(userId, signature);
|
||||||
|
|
||||||
if (!activity) return; // cleared their activity - nothing to notify about
|
if (!signature) return; // cleared their status - nothing to notify about
|
||||||
|
|
||||||
const verb = ACTIVITY_VERBS[activity.type] ?? "Playing";
|
|
||||||
const displayName = user.globalName || user.username || "A friend";
|
const displayName = user.globalName || user.username || "A friend";
|
||||||
|
const shownText = statusText || (emojiName ? `:${emojiName}:` : "");
|
||||||
|
|
||||||
pushNotification({
|
pushNotification({
|
||||||
id: `presence-${userId}-${Date.now()}`,
|
id: `presence-${userId}-${Date.now()}`,
|
||||||
category: "other",
|
category: "other",
|
||||||
title: `${displayName} started ${verb} ${activity.name}`,
|
title: `${displayName} updated their status`,
|
||||||
content: "",
|
content: shownText,
|
||||||
guildName: "",
|
guildName: "",
|
||||||
channelName: "",
|
channelName: "",
|
||||||
timestamp: new Date().toLocaleTimeString([], { hour: "2-digit", minute: "2-digit" }),
|
timestamp: new Date().toLocaleTimeString([], { hour: "2-digit", minute: "2-digit" }),
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue