aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDominik <dominik.buettner1711@gmail.com>2022-12-23 04:16:17 +0100
committerGitHub <noreply@github.com>2022-12-23 04:16:17 +0100
commit2172cae779fb24f9bcc8c54a0b6538da0b52bafd (patch)
treec01e57cbff9d5fdd671d7856f827a4e3b70cfbf6
parente740f5545056ebe8776a6448922b3ee60684ce0d (diff)
downloadVencord-2172cae779fb24f9bcc8c54a0b6538da0b52bafd.tar.gz
Vencord-2172cae779fb24f9bcc8c54a0b6538da0b52bafd.tar.bz2
Vencord-2172cae779fb24f9bcc8c54a0b6538da0b52bafd.zip
[PlatformIndicators] Add own Status (#350)
Co-authored-by: Dominik <domi@bambus.me> Co-authored-by: HypedDomi <HypedDomi@users.noreply.github.com> Co-authored-by: Ven <vendicated@riseup.net>
-rw-r--r--src/plugins/platformIndicators.tsx59
1 files changed, 44 insertions, 15 deletions
diff --git a/src/plugins/platformIndicators.tsx b/src/plugins/platformIndicators.tsx
index 8ca0677..b7af8fb 100644
--- a/src/plugins/platformIndicators.tsx
+++ b/src/plugins/platformIndicators.tsx
@@ -23,18 +23,20 @@ import { Settings } from "@api/settings";
import ErrorBoundary from "@components/ErrorBoundary";
import { Devs } from "@utils/constants";
import definePlugin, { OptionType } from "@utils/types";
-import { findByCodeLazy } from "@webpack";
-import { PresenceStore, Tooltip } from "@webpack/common";
+import { findByCodeLazy, findByPropsLazy } from "@webpack";
+import { PresenceStore, Tooltip, UserStore } from "@webpack/common";
import { User } from "discord-types/general";
+const SessionStore = findByPropsLazy("getActiveSession");
+
function Icon(path: string, viewBox = "0 0 24 24") {
return ({ color, tooltip }: { color: string; tooltip: string; }) => (
<Tooltip text={tooltip} >
{(tooltipProps: any) => (
<svg
{...tooltipProps}
- height="18"
- width="18"
+ height="20"
+ width="20"
viewBox={viewBox}
fill={color}
>
@@ -64,10 +66,32 @@ const PlatformIcon = ({ platform, status }: { platform: Platform, status: string
const getStatus = (id: string): Record<Platform, string> => PresenceStore.getState()?.clientStatuses?.[id];
-const PlatformIndicator = ({ user }: { user: User; }) => {
+const PlatformIndicator = ({ user, inline = false, marginLeft = "4px" }: { user: User; inline?: boolean; marginLeft?: string; }) => {
if (!user || user.bot) return null;
- const status = getStatus(user.id);
+ if (user.id === UserStore.getCurrentUser().id) {
+ const sessions = SessionStore.getSessions();
+ if (typeof sessions !== "object") return null;
+ const sortedSessions = Object.values(sessions).sort(({ status: a }: any, { status: b }: any) => {
+ if (a === b) return 0;
+ if (a === "online") return 1;
+ if (b === "online") return -1;
+ if (a === "idle") return 1;
+ if (b === "idle") return -1;
+ return 0;
+ });
+
+ const ownStatus = Object.values(sortedSessions).reduce((acc: any, curr: any) => {
+ if (curr.clientInfo.client !== "unknown")
+ acc[curr.clientInfo.client] = curr.status;
+ return acc;
+ }, {});
+
+ const { clientStatuses } = PresenceStore.getState();
+ clientStatuses[UserStore.getCurrentUser().id] = ownStatus;
+ }
+
+ const status = PresenceStore.getState()?.clientStatuses?.[user.id] as Record<Platform, string>;
if (!status) return null;
const icons = Object.entries(status).map(([platform, status]) => (
@@ -80,19 +104,24 @@ const PlatformIndicator = ({ user }: { user: User; }) => {
if (!icons.length) return null;
- const indicator =
- <span
+ return (
+ <div
className="vc-platform-indicator"
- style={{ marginLeft: "4px", gap: "4px" }}
+ style={{
+ marginLeft,
+ gap: "4px",
+ display: inline ? "inline-flex" : "flex",
+ alignItems: "center",
+ transform: inline ? "translateY(4px)" : undefined
+ }}
>
{icons}
- </span>;
-
- return indicator;
+ </div>
+ );
};
const badge: ProfileBadge = {
- component: PlatformIndicator,
+ component: p => <PlatformIndicator {...p} marginLeft="" />,
position: BadgePosition.START,
shouldShow: userInfo => !!Object.keys(getStatus(userInfo.user.id) ?? {}).length,
key: "indicator"
@@ -119,7 +148,7 @@ const indicatorLocations = {
<ErrorBoundary noop>
<PlatformIndicator user={
props.decorations[1]?.find(i => i.key === "new-member")?.props.message?.author
- } />
+ } inline />
</ErrorBoundary>
),
onDisable: () => removeDecoration("platform-indicator")
@@ -166,7 +195,7 @@ export default definePlugin({
description: `Show indicators ${value.description.toLowerCase()}`,
// onChange doesn't give any way to know which setting was changed, so restart required
restartNeeded: true,
- default: false
+ default: true
}];
})
)