diff --git a/src/plugins/memberListActivities/README.md b/src/plugins/memberListActivities/README.md new file mode 100644 index 000000000..fe67bad79 --- /dev/null +++ b/src/plugins/memberListActivities/README.md @@ -0,0 +1,5 @@ +# MemberListActivities + +Shows activity icons in the member list + +![Screenshot](screenshot.png) diff --git a/src/plugins/memberListActivities/components/SpotifyIcon.tsx b/src/plugins/memberListActivities/components/SpotifyIcon.tsx new file mode 100644 index 000000000..9210169e2 --- /dev/null +++ b/src/plugins/memberListActivities/components/SpotifyIcon.tsx @@ -0,0 +1,11 @@ +/* + * Vencord, a Discord client mod + * Copyright (c) 2024 Vendicated and contributors + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +import type { SVGProps } from "react"; + +export function SpotifyIcon(props: SVGProps) { + return (); +} diff --git a/src/plugins/memberListActivities/index.tsx b/src/plugins/memberListActivities/index.tsx new file mode 100644 index 000000000..f4cdd0f95 --- /dev/null +++ b/src/plugins/memberListActivities/index.tsx @@ -0,0 +1,123 @@ +/* + * Vencord, a modification for Discord's desktop app + * Copyright (c) 2023 Vendicated and contributors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . +*/ + +import "./styles.css"; + +import { definePluginSettings } from "@api/Settings"; +import { classNameFactory } from "@api/Styles"; +import ErrorBoundary from "@components/ErrorBoundary"; +import { Devs } from "@utils/constants"; +import definePlugin from "@utils/types"; + +import { SpotifyIcon } from "./components/SpotifyIcon"; + +export const settings = definePluginSettings({ +}); + +interface Activity { + created_at: number; + id: string; + name: string; + state: string; + type: number; + flags?: number; + sync_id?: string; + details?: string; + application_id?: string; + assets?: { + large_text?: string; + large_image?: string; + small_text?: string; + small_image?: string; + }; +} + +const cl = classNameFactory("vc-mla-"); + +export default definePlugin({ + name: "MemberListActivities", + description: "Shows activity icons in the member list", + authors: [Devs.D3SOX], + tags: ["activity"], + settings, + + patchActivityList: (activities: Activity[]) => { + const icons: JSX.Element[] = []; + + if (activities.some(activity => activity.name === "Spotify")) { + icons.push(); + } + + const applications = activities.filter(activity => activity.application_id); + applications.forEach(activity => { + const { assets } = activity; + if (assets) { + + const addImage = (image: string, alt: string) => { + if (image.startsWith("mp:external/")) { + const externalLink = image.replace(/mp:external\/.{0,43}\//, "").replaceAll("https/", "https://"); + console.log("patch activity list external link", image, externalLink); + if (externalLink) { + icons.push({alt}/); + } + } else { + const src = `https://cdn.discordapp.com/app-assets/${activity.application_id}/${image}.png`; + icons.push({alt}/); + } + }; + + // Prefer small image + const smallImage = assets.small_image; + if (smallImage) { + addImage(smallImage, assets.small_text ?? "Small Text"); + } else { + const largeImage = assets.large_image; + if (largeImage) { + addImage(largeImage, assets.large_text ?? "Large Text"); + } + } + + } + }); + + if (icons.length) { + return +
+ {icons.map((icon, i) => ( +
+ {icon} +
+ ))} +
+
; + } + + return false; + }, + + patches: [ + { + // Patch activity icons + find: "default.getHangStatusActivity():null!", + replacement: { + match: /(\i).some\((\i).default\)\?/, + replace: "$&$self.patchActivityList(l,d,_)?$self.patchActivityList(l,d,_):" + } + }, + ], +}); diff --git a/src/plugins/memberListActivities/screenshot.png b/src/plugins/memberListActivities/screenshot.png new file mode 100644 index 000000000..645f8d612 Binary files /dev/null and b/src/plugins/memberListActivities/screenshot.png differ diff --git a/src/plugins/memberListActivities/styles.css b/src/plugins/memberListActivities/styles.css new file mode 100644 index 000000000..4a66255b1 --- /dev/null +++ b/src/plugins/memberListActivities/styles.css @@ -0,0 +1,20 @@ +.vc-mla-row { + display: flex; + flex-wrap: nowrap; + align-items: center; + margin-left: 5px; + text-align: center; + gap: 3px; +} + +.vc-mla-icon { + height: 20px; + width: 20px; + border-radius: 50%; +} + +.vc-mla-icon img { + width: 100%; + height: 100%; + object-fit: cover; +}