π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Guard comment emoji segmentation on older browsers
Anand Baburajan2b853bcb06e5
diff --git a/web/apps/space/src/utils/comments.ts b/web/apps/space/src/utils/comments.tsindex b605757e7a..a3bad2ad2f 100644--- a/web/apps/space/src/utils/comments.ts+++ b/web/apps/space/src/utils/comments.ts@@ -96,18 +96,23 @@ export const commentReactionGroups = (}));};-const commentEmojiSegmenter = new Intl.Segmenter(undefined, {- granularity: "grapheme",-});+const commentEmojiSegmenter =+ typeof Intl !== "undefined" && typeof Intl.Segmenter == "function"+ ? new Intl.Segmenter(undefined, { granularity: "grapheme" })+ : null;export const isEmojiOnlyComment = (text: string) => {- const segments = [- ...commentEmojiSegmenter.segment(text.replace(/\s/g, "")),- ];+ const compact = text.replace(/\s/g, "");+ const segments = commentEmojiSegmenter+ ? Array.from(+ commentEmojiSegmenter.segment(compact),+ ({ segment }) => segment,+ )+ : Array.from(compact);return (segments.length > 0 &&segments.length <= 3 &&- segments.every(({ segment }) =>+ segments.every((segment) =>/\p{Extended_Pictographic}|\p{Regional_Indicator}|\u20E3/u.test(segment,),diff --git a/web/apps/space/tests/comments.test.ts b/web/apps/space/tests/comments.test.tsindex f07a2cb334..2de6b59991 100644--- a/web/apps/space/tests/comments.test.ts+++ b/web/apps/space/tests/comments.test.ts@@ -1,4 +1,4 @@-import { expect, test } from "vitest";+import { expect, test, vi } from "vitest";import type { SpaceComment, SpaceNotification } from "../src/services/space";import {commentNotificationText,@@ -84,6 +84,22 @@ test.each(["", " ", "123", "Nice π", "ππππ", "aΜ", "hello"])((text) => expect(isEmojiOnlyComment(text)).toBe(false),);+test("comments load and classify simple emojis without Intl.Segmenter", async () => {+ const descriptor = Object.getOwnPropertyDescriptor(Intl, "Segmenter")!;+ Reflect.deleteProperty(Intl, "Segmenter");+ vi.resetModules();+ try {+ const comments = await import("../src/utils/comments");+ expect(comments.isEmojiOnlyComment("π π₯ͺ")).toBe(true);+ expect(comments.isEmojiOnlyComment("Nice π")).toBe(false);+ expect(comments.isEmojiOnlyComment("ππππ")).toBe(false);+ expect(comments.isEmojiOnlyComment("π¨βπ©βπ§βπ¦")).toBe(false);+ } finally {+ Object.defineProperty(Intl, "Segmenter", descriptor);+ vi.resetModules();+ }+});+test("reactions stay grouped by emoji with your group and your row first", () => {const reactions = [reaction("alice", "β€οΈ"),