Skip to content

Commit

Permalink
Add Emoji support for activity status.
Browse files Browse the repository at this point in the history
  • Loading branch information
SupertigerDev committed Dec 14, 2024
1 parent dd71b53 commit 4df91b8
Show file tree
Hide file tree
Showing 12 changed files with 288 additions and 106 deletions.
1 change: 1 addition & 0 deletions src/chat-api/RawData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@ export interface ActivityStatus {
title?: string;
subtitle?: string;
link?: string;
emoji?: string;
}
export interface RawPresence {
userId: string;
Expand Down
9 changes: 5 additions & 4 deletions src/chat-api/events/connectionEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import useStore from "../store/useStore";
import { AuthenticatedPayload } from "./connectionEventTypes";
import useVoiceUsers from "../store/useVoiceUsers";
import { StorageKeys, getStorageObject } from "@/common/localStorage";
import { ProgramWithAction, electronWindowAPI } from "@/common/Electron";
import { ProgramWithExtras, electronWindowAPI } from "@/common/Electron";
import { emitActivityStatus } from "../emits/userEmits";
import { isExperimentEnabled, useExperiment } from "@/common/experiments";
import { localRPC } from "@/common/LocalRPC";
Expand Down Expand Up @@ -61,7 +61,7 @@ electronWindowAPI()?.activityStatusChanged((window) => {
if (!window) {
return emitActivityStatus(null);
}
const programs = getStorageObject<ProgramWithAction[]>(
const programs = getStorageObject<ProgramWithExtras[]>(
StorageKeys.PROGRAM_ACTIVITY_STATUS,
[]
);
Expand All @@ -77,12 +77,13 @@ electronWindowAPI()?.activityStatusChanged((window) => {
action: program.action || "Playing",
name: program.name,
startedAt: window.createdAt,
emoji: program.emoji,
});
});

electronWindowAPI()?.rpcChanged((data) => {
if (!data) {
const programs = getStorageObject<ProgramWithAction[]>(
const programs = getStorageObject<ProgramWithExtras[]>(
StorageKeys.PROGRAM_ACTIVITY_STATUS,
[]
);
Expand Down Expand Up @@ -218,7 +219,7 @@ export const onAuthenticated = (payload: AuthenticatedPayload) => {
const t1 = performance.now();
console.log(`${t1 - t0} milliseconds.`);

const programs = getStorageObject<ProgramWithAction[]>(
const programs = getStorageObject<ProgramWithExtras[]>(
StorageKeys.PROGRAM_ACTIVITY_STATUS,
[]
);
Expand Down
4 changes: 2 additions & 2 deletions src/chat-api/events/userEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
import useFriends from "../store/useFriends";
import useAccount from "../store/useAccount";
import { StorageKeys, getStorageObject } from "@/common/localStorage";
import { ProgramWithAction, electronWindowAPI } from "@/common/Electron";
import { ProgramWithExtras, electronWindowAPI } from "@/common/Electron";
import { isExperimentEnabled } from "@/common/experiments";
import { userInfo } from "os";

Expand All @@ -34,7 +34,7 @@ export function onUserPresenceUpdate(payload: {
const wasOffline =
!user?.presence()?.status && payload.status !== UserStatus.OFFLINE;
if (wasOffline) {
const programs = getStorageObject<ProgramWithAction[]>(
const programs = getStorageObject<ProgramWithExtras[]>(
StorageKeys.PROGRAM_ACTIVITY_STATUS,
[]
);
Expand Down
3 changes: 2 additions & 1 deletion src/common/Electron.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ export interface Program {
name: string;
filename: string;
}
export type ProgramWithAction = Program & {
export type ProgramWithExtras = Program & {
action: string;
emoji?: string;
};

export interface RPC {
Expand Down
15 changes: 15 additions & 0 deletions src/common/emojiToUrl.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { unicodeToTwemojiUrl } from "@/emoji";
import env from "./env";

export const emojiToUrl = (emoji: string, hovered: boolean, size = 36) => {
if (emoji.includes(".")) {
const url = new URL(
`${env.NERIMITY_CDN}emojis/${emoji}${
!hovered && emoji?.endsWith(".gif") ? "?type=webp" : ""
}`
);
url.searchParams.set("size", size.toString());
return url.href;
}
return unicodeToTwemojiUrl(emoji);
};
9 changes: 7 additions & 2 deletions src/components/DashboardPane.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import RouterEndpoints from "@/common/RouterEndpoints";
import { A, useNavigate, useSearchParams } from "solid-navigator";
import {
createEffect,
createMemo,
createSignal,
For,
JSXElement,
Expand Down Expand Up @@ -41,6 +42,7 @@ import { MetaTitle } from "@/common/MetaTitle";
import { MentionUser } from "./markup/MentionUser";
import { useCustomScrollbar } from "./custom-scrollbar/CustomScrollbar";
import { Item } from "./ui/Item";
import { emojiToUrl } from "@/common/emojiToUrl";
const DashboardPaneContainer = styled(FlexColumn)`
justify-content: center;
align-items: center;
Expand Down Expand Up @@ -586,12 +588,15 @@ const PresenceItem = (props: { presence: Presence }) => {
return store.users.get(props.presence.userId);
};

const imgSrc = () => {
const imgSrc = createMemo(() => {
if (activity()?.emoji) {
return emojiToUrl(activity()?.emoji!, false);
}
if (!activity()?.imgSrc) return;
return `${env.NERIMITY_CDN}proxy/${encodeURIComponent(
activity()?.imgSrc!
)}/a`;
};
});

return (
<PresenceItemContainer
Expand Down
20 changes: 13 additions & 7 deletions src/components/floating-profile/FloatingProfile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ import average from "@/common/chromaJS";
import Button from "../ui/Button";
import { FlexRow } from "../ui/Flexbox";
import { emitDrawerGoToMain } from "@/common/GlobalEvents";
import { emojiToUrl } from "@/common/emojiToUrl";

interface Props {
dmPane?: boolean;
Expand Down Expand Up @@ -373,7 +374,9 @@ const DesktopProfileFlyout = (props: {
isMe() ||
(!details()?.hideFollowers && !details()?.hideFollowing)
}
>{` | `}</Show>
>
{" | "}
</Show>
<Show when={isMe() || !details()?.hideFollowers}>
<CustomLink
href={RouterEndpoints.PROFILE(user()!.id + "/followers")}
Expand Down Expand Up @@ -671,12 +674,15 @@ export const UserActivity = (props: {
})
);

const imgSrc = () => {
const imgSrc = createMemo(() => {
if (activity()?.emoji) {
return emojiToUrl(activity()?.emoji!, false);
}
if (!activity()?.imgSrc) return;
return `${env.NERIMITY_CDN}proxy/${encodeURIComponent(
activity()?.imgSrc!
)}/a`;
};
});

return (
<Show when={activity()}>
Expand All @@ -695,15 +701,15 @@ export const UserActivity = (props: {
{activity()?.name}
</Text>
</div>
<Show when={activity()?.imgSrc}>
<Show when={activity()?.imgSrc || activity()?.emoji}>
<div class={styles.richPresence}>
<Show when={imgSrc()}>
<div
class={styles.backgroundImage}
style={{
"background-image": `url(${imgSrc()})`,
}}
></div>
/>
</Show>
<img
src={imgSrc()}
Expand All @@ -720,7 +726,7 @@ export const UserActivity = (props: {
size={13}
opacity={0.9}
>
{activity()?.title}
{activity()?.title || activity()?.name}
</Text>
<Text size={13} opacity={0.6}>
{activity()?.subtitle}
Expand All @@ -742,7 +748,7 @@ export const UserActivity = (props: {
</div>
</div>
</Show>
<Show when={!activity()?.imgSrc}>
<Show when={!activity()?.imgSrc && !activity()?.emoji}>
<Text class={styles.playedFor} size={13}>
For {playedFor()}
</Text>
Expand Down
14 changes: 9 additions & 5 deletions src/components/profile-pane/ProfilePane.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ import { CreateTicketModal } from "../CreateTicketModal";
import { MetaTitle } from "@/common/MetaTitle";
import average from "@/common/chromaJS";
import { useCustomScrollbar } from "../custom-scrollbar/CustomScrollbar";
import { emojiToUrl } from "@/common/emojiToUrl";

const ActionButtonsContainer = styled(FlexRow)`
align-self: center;
Expand Down Expand Up @@ -717,12 +718,15 @@ const UserActivity = (props: {
const isLiveStream = () =>
!!activity()?.action.startsWith("Watching") && !activity()?.endsAt;

const imgSrc = () => {
const imgSrc = createMemo(() => {
if (activity()?.emoji) {
return emojiToUrl(activity()?.emoji!, false);
}
if (!activity()?.imgSrc) return;
return `${env.NERIMITY_CDN}proxy/${encodeURIComponent(
activity()?.imgSrc!
)}/a`;
};
});

createEffect(
on(activity, () => {
Expand Down Expand Up @@ -769,7 +773,7 @@ const UserActivity = (props: {
</span>
</FlexRow>

<Show when={activity()?.imgSrc}>
<Show when={activity()?.imgSrc || activity()?.emoji}>
<div class={styles.richPresence}>
<Show when={imgSrc()}>
<div
Expand All @@ -794,7 +798,7 @@ const UserActivity = (props: {
isDangerousLink
newTab
>
{activity()?.title}
{activity()?.title || activity()?.name}
</Text>

<Text size={13} opacity={0.6}>
Expand All @@ -818,7 +822,7 @@ const UserActivity = (props: {
</div>
</Show>

<Show when={!activity()?.imgSrc}>
<Show when={!activity()?.imgSrc && !activity()?.emoji}>
<Text
class={styles.playedFor}
style={{
Expand Down
Loading

0 comments on commit 4df91b8

Please sign in to comment.