Skip to content

Commit 5bdac05

Browse files
wesbillmanPinky
andauthored
Fix custom emoji status in profile popover (#874)
Signed-off-by: Wes <[email protected]> Co-authored-by: Pinky <44b8e82baa6e0e254e0208d68f335c283c94e7b78dd1fa10d5a49d3f13dd0435@sprout-oss.stage.blox.sqprod.co>
1 parent b295f51 commit 5bdac05

4 files changed

Lines changed: 142 additions & 6 deletions

File tree

‎desktop/playwright.config.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ export default defineConfig({
2525
"**/channel-browser.spec.ts",
2626
"**/messaging.spec.ts",
2727
"**/custom-emoji.spec.ts",
28+
"**/profile-custom-emoji-status.spec.ts",
2829
"**/custom-emoji-screenshots.spec.ts",
2930
"**/channel-mute-screenshots.spec.ts",
3031
"**/channel-star-screenshots.spec.ts",

‎desktop/src/features/profile/ui/ProfilePopover.tsx‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { ProfileAvatar } from "@/features/profile/ui/ProfileAvatar";
66
import { PresenceDot } from "@/features/presence/ui/PresenceBadge";
77
import { getPresenceLabel } from "@/features/presence/lib/presence";
88
import { SetStatusDialog } from "@/features/user-status/ui/SetStatusDialog";
9+
import { StatusEmoji } from "@/features/user-status/ui/StatusEmoji";
910
import type { PresenceStatus } from "@/shared/api/types";
1011
import { isMacPlatform } from "@/shared/lib/platform";
1112

@@ -179,7 +180,10 @@ export function ProfilePopover({
179180
{hasUserStatus ? (
180181
<span className="flex min-w-0 flex-1 items-center gap-1 truncate text-popover-foreground">
181182
{userStatusEmoji ? (
182-
<span className="shrink-0">{userStatusEmoji}</span>
183+
<StatusEmoji
184+
className="h-3.5 w-3.5 shrink-0"
185+
value={userStatusEmoji}
186+
/>
183187
) : null}
184188
<span className="truncate">{userStatusText}</span>
185189
</span>

‎desktop/src/testing/e2eBridge.ts‎

Lines changed: 90 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
import {
1212
KIND_STREAM_MESSAGE_EDIT,
1313
KIND_SYSTEM_MESSAGE,
14+
KIND_USER_STATUS,
1415
} from "@/shared/constants/kinds";
1516
import type {
1617
RawAcpProviderCatalogEntry,
@@ -393,6 +394,13 @@ type MockSubscription = {
393394
kinds: number[] | null;
394395
};
395396

397+
type MockFilter = {
398+
"#d"?: string[];
399+
"#h"?: string[];
400+
authors?: string[];
401+
kinds?: number[];
402+
};
403+
396404
type MockSocket = {
397405
handler: WsHandler;
398406
subscriptions: Map<string, MockSubscription>;
@@ -1230,6 +1238,7 @@ const mockChannels: MockChannel[] = [
12301238
];
12311239

12321240
const mockMessages = new Map<string, RelayEvent[]>();
1241+
const mockUserStatuses: RelayEvent[] = [];
12331242
let mockRelayMembers: RawRelayMember[] = [];
12341243
const mockSockets = new Map<number, MockSocket>();
12351244
let mockWebsocketSendMutexWedged = false;
@@ -1923,6 +1932,17 @@ function emitMockLiveEvent(channelId: string, event: RelayEvent) {
19231932
}
19241933
}
19251934

1935+
function emitMockGlobalEvent(event: RelayEvent) {
1936+
for (const socket of mockSockets.values()) {
1937+
for (const [subId, subscription] of socket.subscriptions) {
1938+
if (subscription.kinds && !subscription.kinds.includes(event.kind)) {
1939+
continue;
1940+
}
1941+
sendWsText(socket.handler, ["EVENT", subId, event]);
1942+
}
1943+
}
1944+
}
1945+
19261946
function hasMockLiveSubscription(channelId: string, kind?: number) {
19271947
for (const socket of mockSockets.values()) {
19281948
for (const subscription of socket.subscriptions.values()) {
@@ -1954,6 +1974,46 @@ function recordMockMessage(channelId: string, event: RelayEvent) {
19541974
touchMockChannel(channel);
19551975
}
19561976

1977+
function resetMockUserStatuses() {
1978+
mockUserStatuses.length = 0;
1979+
}
1980+
1981+
function recordMockUserStatus(event: RelayEvent) {
1982+
const dTag = event.tags.find((tag) => tag[0] === "d")?.[1];
1983+
if (dTag) {
1984+
const index = mockUserStatuses.findIndex(
1985+
(stored) =>
1986+
stored.pubkey.toLowerCase() === event.pubkey.toLowerCase() &&
1987+
stored.tags.some((tag) => tag[0] === "d" && tag[1] === dTag),
1988+
);
1989+
if (index >= 0) {
1990+
mockUserStatuses.splice(index, 1);
1991+
}
1992+
}
1993+
1994+
mockUserStatuses.push(event);
1995+
}
1996+
1997+
function filterMockUserStatuses(filter: MockFilter) {
1998+
const authors = filter.authors?.map((author) => author.toLowerCase());
1999+
const dTags = filter["#d"];
2000+
2001+
return mockUserStatuses
2002+
.filter((event) => {
2003+
if (authors && !authors.includes(event.pubkey.toLowerCase())) {
2004+
return false;
2005+
}
2006+
if (
2007+
dTags &&
2008+
!event.tags.some((tag) => tag[0] === "d" && dTags.includes(tag[1]))
2009+
) {
2010+
return false;
2011+
}
2012+
return true;
2013+
})
2014+
.sort((a, b) => b.created_at - a.created_at);
2015+
}
2016+
19572017
function emitMockChannelMessage(
19582018
channelId: string,
19592019
content: string,
@@ -5022,11 +5082,7 @@ function sendToMockSocket(args: {
50225082
return;
50235083
}
50245084

5025-
const filter = rest[1] as {
5026-
"#h"?: string[];
5027-
kinds?: number[];
5028-
authors?: string[];
5029-
};
5085+
const filter = rest[1] as MockFilter;
50305086
if (filter.kinds?.includes(13534)) {
50315087
sendWsText(socket.handler, [
50325088
"EVENT",
@@ -5052,6 +5108,14 @@ function sendToMockSocket(args: {
50525108
return;
50535109
}
50545110

5111+
if (filter.kinds?.includes(KIND_USER_STATUS)) {
5112+
for (const statusEvent of filterMockUserStatuses(filter)) {
5113+
sendWsText(socket.handler, ["EVENT", subId, statusEvent]);
5114+
}
5115+
sendWsText(socket.handler, ["EOSE", subId]);
5116+
return;
5117+
}
5118+
50555119
const channelId = filter["#h"]?.[0];
50565120
if (!channelId) {
50575121
sendWsText(socket.handler, ["EOSE", subId]);
@@ -5109,6 +5173,26 @@ function sendToMockSocket(args: {
51095173
return;
51105174
}
51115175

5176+
if (event.kind === KIND_USER_STATUS) {
5177+
const hasGeneralDTag = event.tags.some(
5178+
(tag) => tag[0] === "d" && tag[1] === "general",
5179+
);
5180+
if (!hasGeneralDTag) {
5181+
sendWsText(socket.handler, [
5182+
"OK",
5183+
event.id,
5184+
false,
5185+
"invalid: user status missing d tag.",
5186+
]);
5187+
return;
5188+
}
5189+
5190+
recordMockUserStatus(event);
5191+
emitMockGlobalEvent(event);
5192+
sendWsText(socket.handler, ["OK", event.id, true, ""]);
5193+
return;
5194+
}
5195+
51125196
const channelId = getChannelIdFromTags(event.tags);
51135197
if (!channelId) {
51145198
sendWsText(socket.handler, [
@@ -5152,6 +5236,7 @@ export function maybeInstallE2eTauriMocks() {
51525236
resetMockTeams();
51535237
resetMockWorkflows();
51545238
resetMockMesh();
5239+
resetMockUserStatuses();
51555240
mockWebsocketSendMutexWedged = false;
51565241
mockWindows("main");
51575242
window.__SPROUT_E2E_COMMANDS__ = [];
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import { expect, test } from "@playwright/test";
2+
3+
import { installMockBridge } from "../helpers/bridge";
4+
5+
const SHORTCODE = "sprout";
6+
const STATUS_TEXT = "testing custom status";
7+
8+
async function openProfilePopover(page: import("@playwright/test").Page) {
9+
await page.getByTestId("open-settings").click();
10+
await expect(page.getByTestId("profile-popover")).toBeVisible();
11+
}
12+
13+
test.beforeEach(async ({ page }) => {
14+
await installMockBridge(page);
15+
const PNG = Buffer.from(
16+
"iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAGUlEQVR4nGMwuBPxnxLMMGrAqAGjBgwXAwBwOGMf1PPhVwAAAABJRU5ErkJggg==",
17+
"base64",
18+
);
19+
await page.route("https://example.com/e2e/**", (route) =>
20+
route.fulfill({ contentType: "image/png", body: PNG }),
21+
);
22+
});
23+
24+
test("profile popover renders a custom emoji status as an image", async ({
25+
page,
26+
}) => {
27+
await page.goto("/");
28+
await openProfilePopover(page);
29+
30+
await page.getByTestId("profile-popover-set-status").click();
31+
await expect(page.getByTestId("set-status-dialog")).toBeVisible();
32+
await page.getByLabel("Choose status emoji").click();
33+
34+
const picker = page.locator("em-emoji-picker");
35+
await picker.locator("input[type='search']").fill(SHORTCODE);
36+
await picker.locator(`button[title='${SHORTCODE}']`).first().click();
37+
await page.getByTestId("set-status-input").fill(STATUS_TEXT);
38+
await page.getByTestId("set-status-save").click();
39+
40+
await openProfilePopover(page);
41+
42+
const statusButton = page.getByTestId("profile-popover-set-status");
43+
await expect(statusButton).toContainText(STATUS_TEXT);
44+
await expect(statusButton.locator(`img[alt=":${SHORTCODE}:"]`)).toBeVisible();
45+
await expect(statusButton).not.toContainText(`:${SHORTCODE}:`);
46+
});

0 commit comments

Comments
 (0)