Desktop: react to messages, reactions in other languages, and edits
- Right-click a message (or photo): a quick reaction row above Copy, + for every emoji, and "Customize quick reactions…" there to change the row (saved in settings as quickReactions; default ❤️ 👍 👎 😂 ‼️ ❓). Yours shows sunk; clicking it again takes it back. A reaction goes out as an ordinary text worded like an iPhone's ("Loved “…”", "Reacted 🎉 to “…”", "Removed a heart from “…”"), long messages quoted cut short. - Tapbacks in other languages ("Le encanta “…”", "Hat „…“ geliebt", "A aimé « … »"...): read from the words around the quote, and only folded when the quote matches an earlier message. A failed reaction stays in view. - "Edited to “…”": applied to the sender's message from the last 20 minutes that reads most like it (or their only one); the bubble says "Edited", and clicking it shows the earlier texts. Reactions to the old text still land. - Popovers re-fit the window when they grow.
This commit is contained in:
@@ -0,0 +1,95 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import {
|
||||
editPreview,
|
||||
foldConversation,
|
||||
foldEdits,
|
||||
likeness,
|
||||
parseEdit,
|
||||
} from "@shared/edits";
|
||||
|
||||
const MIN = 60_000;
|
||||
let nextId = 1;
|
||||
const msg = (
|
||||
body: string,
|
||||
min: number,
|
||||
opts: { out?: boolean; sender?: string } = {},
|
||||
) => ({
|
||||
id: nextId++,
|
||||
body,
|
||||
ts: 1_700_000_000_000 + min * MIN,
|
||||
direction: (opts.out ? "out" : "in") as "in" | "out",
|
||||
contact: "5550001111",
|
||||
...(opts.sender ? { sender: opts.sender } : {}),
|
||||
});
|
||||
|
||||
describe("parseEdit", () => {
|
||||
it("reads the new text", () => {
|
||||
expect(parseEdit("Edited to “see you at 9:30”")).toBe("see you at 9:30");
|
||||
expect(parseEdit('Edited to "ok"')).toBe("ok");
|
||||
expect(parseEdit("Editado a “nos vemos”")).toBe("nos vemos");
|
||||
expect(parseEdit("Edited the plan")).toBeNull();
|
||||
expect(editPreview("Edited to “see you”")).toBe("✏️ see you");
|
||||
});
|
||||
it("likeness", () => {
|
||||
expect(likeness("abc", "abc")).toBe(1);
|
||||
expect(likeness("see you at 9", "see you at 9:30")).toBeGreaterThan(0.7);
|
||||
});
|
||||
});
|
||||
|
||||
describe("foldEdits", () => {
|
||||
it("applies a small edit and keeps the history", () => {
|
||||
const a = msg("see you at 9", 0);
|
||||
const b = msg("sounds good", 1, { out: true });
|
||||
const e = msg("Edited to “see you at 9:30”", 3);
|
||||
const { shown, versions } = foldEdits([a, b, e]);
|
||||
expect(shown.map((m) => m.body)).toEqual([
|
||||
"see you at 9:30",
|
||||
"sounds good",
|
||||
]);
|
||||
expect(versions.get(a.id)?.map((v) => v.body)).toEqual([
|
||||
"see you at 9",
|
||||
"see you at 9:30",
|
||||
]);
|
||||
});
|
||||
|
||||
it("chains edits and picks the most alike of several", () => {
|
||||
const a = msg("grab milk", 0);
|
||||
const b = msg("and the dog food from the shelf", 1);
|
||||
const e1 = msg("Edited to “and the cat food from the shelf”", 2);
|
||||
const e2 = msg("Edited to “and the cat food from the top shelf”", 4);
|
||||
const { shown, versions } = foldEdits([a, b, e1, e2]);
|
||||
expect(shown.map((m) => m.body)).toEqual([
|
||||
"grab milk",
|
||||
"and the cat food from the top shelf",
|
||||
]);
|
||||
expect(versions.get(b.id)?.length).toBe(3);
|
||||
});
|
||||
|
||||
it("takes a big change when theirs is the only message in the window", () => {
|
||||
const a = msg("yes", 0);
|
||||
const e = msg("Edited to “actually no, sorry”", 2);
|
||||
expect(foldEdits([a, e]).shown.map((m) => m.body)).toEqual([
|
||||
"actually no, sorry",
|
||||
]);
|
||||
});
|
||||
|
||||
it("leaves it when it can't tell", () => {
|
||||
const a = msg("pizza tonight?", 0);
|
||||
const b = msg("or tacos", 1);
|
||||
const e = msg("Edited to “never mind, I am busy”", 2);
|
||||
expect(foldEdits([a, b, e]).shown).toHaveLength(3);
|
||||
// someone else's message is never the one edited
|
||||
const c = msg("hello there", 0, { out: true });
|
||||
const f = msg("Edited to “hello there!”", 1);
|
||||
expect(foldEdits([c, f]).shown).toHaveLength(2);
|
||||
});
|
||||
|
||||
it("reactions to the old text still land", () => {
|
||||
const a = msg("see you at 9", 0);
|
||||
const r = msg("Loved “see you at 9”", 1, { out: true });
|
||||
const e = msg("Edited to “see you at 9:30”", 2);
|
||||
const { shown, reactions } = foldConversation([a, r, e]);
|
||||
expect(shown.map((m) => m.body)).toEqual(["see you at 9:30"]);
|
||||
expect(reactions.get(a.id)?.[0].emoji).toBe("❤️");
|
||||
});
|
||||
});
|
||||
+97
-1
@@ -1,5 +1,5 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { foldReactions, parseReaction, reactionPreview } from '@shared/reactions'
|
||||
import { foldReactions, parseReaction, parseReactions, reactionPreview, reactionText, sameEmoji } from '@shared/reactions'
|
||||
|
||||
let nextId = 1
|
||||
const msg = (body: string, opts: { out?: boolean; sender?: string; media?: boolean; ts?: number } = {}) => ({
|
||||
@@ -97,3 +97,99 @@ describe('reactionPreview', () => {
|
||||
expect(reactionPreview('just text')).toBeNull()
|
||||
})
|
||||
})
|
||||
|
||||
describe('other languages', () => {
|
||||
const emoji = (body: string) => parseReaction(body)?.emoji
|
||||
it('reads Spanish, Portuguese, French, German, Italian tapbacks', () => {
|
||||
expect(emoji('Le encanta “nos vemos”')).toBe('❤️')
|
||||
expect(emoji('Le encantó “nos vemos”')).toBe('❤️')
|
||||
expect(emoji('Le gusta “nos vemos”')).toBe('👍')
|
||||
expect(emoji('No le gustó “nos vemos”')).toBe('👎')
|
||||
expect(emoji('Le hace gracia “nos vemos”')).toBe('😂')
|
||||
expect(emoji('Se rió de “nos vemos”')).toBe('😂')
|
||||
expect(emoji('Enfatizó “nos vemos”')).toBe('‼️')
|
||||
expect(emoji('Cuestionó “nos vemos”')).toBe('❓')
|
||||
expect(emoji('Reaccionó con 🎉 a “nos vemos”')).toBe('🎉')
|
||||
expect(emoji('Amou “até já”')).toBe('❤️')
|
||||
expect(emoji('Curtiu “até já”')).toBe('👍')
|
||||
expect(emoji('Não curtiu “até já”')).toBe('👎')
|
||||
expect(emoji('Riu de “até já”')).toBe('😂')
|
||||
expect(emoji('A adoré « à plus »')).toBe('❤️')
|
||||
expect(emoji('A aimé « à plus »')).toBe('👍')
|
||||
expect(emoji('N’a pas aimé « à plus »')).toBe('👎')
|
||||
expect(parseReaction('A aimé « à plus »')?.target).toEqual({ text: 'à plus' })
|
||||
expect(emoji('Hat „bis dann“ geliebt')).toBe('❤️')
|
||||
expect(emoji('Hat über „bis dann“ gelacht')).toBe('😂')
|
||||
expect(emoji('Gefällt „bis dann“ nicht')).toBe('👎')
|
||||
expect(emoji('Ha messo Mi piace a “a dopo”')).toBe('👍')
|
||||
expect(emoji('Le encantó una imagen')).toBe('❤️')
|
||||
expect(parseReaction('Le encantó una imagen')?.target).toEqual({ media: true })
|
||||
})
|
||||
|
||||
it('reads removals, even with the reaction quoted too', () => {
|
||||
const r = parseReactions('Quitó un “me gusta” de “nos vemos”')
|
||||
expect(r.some((x) => x.removed && x.emoji === '👍' && 'text' in x.target && x.target.text === 'nos vemos')).toBe(true)
|
||||
expect(parseReaction('Quitó un corazón de “nos vemos”')).toMatchObject({ emoji: '❤️', removed: true })
|
||||
})
|
||||
|
||||
it('leaves people writing alone', () => {
|
||||
expect(parseReaction('Me encanta “Bad Bunny”')).toBeNull()
|
||||
expect(parseReaction('I love “Bad Bunny”')).toBeNull()
|
||||
expect(parseReaction('Mi canción favorita es “Despacito”, ¿y la tuya?')).toBeNull()
|
||||
expect(parseReaction('nos vemos')).toBeNull()
|
||||
})
|
||||
|
||||
it('folds only onto a message it quotes', () => {
|
||||
const a = msg('nos vemos a las 9', { out: true })
|
||||
const b = msg('Le encanta “nos vemos a las 9”', { sender: '5550001111' })
|
||||
const c = msg('Le encanta “Bad Bunny”', { sender: '5550002222' })
|
||||
const { shown, reactions } = foldReactions([a, b, c])
|
||||
expect(shown).toEqual([a, c])
|
||||
expect(reactions.get(a.id)?.[0].emoji).toBe('❤️')
|
||||
})
|
||||
|
||||
it('keeps a failed reaction in view', () => {
|
||||
const a = msg('hi')
|
||||
const r = { ...msg('Loved “hi”', { out: true }), status: 'failed' }
|
||||
expect(foldReactions([a, r]).shown).toEqual([a, r])
|
||||
})
|
||||
|
||||
it('shows loose readings in previews only once placed', () => {
|
||||
expect(reactionPreview('Le encanta “nos vemos”')).toBeNull()
|
||||
})
|
||||
})
|
||||
|
||||
describe('reactionText', () => {
|
||||
it('words a reaction like an iPhone', () => {
|
||||
expect(reactionText('❤️', { body: 'see you at 9' })).toBe('Loved “see you at 9”')
|
||||
expect(reactionText('❤', { body: 'x' })).toBe('Loved “x”')
|
||||
expect(reactionText('😂', { body: 'lol' })).toBe('Laughed at “lol”')
|
||||
expect(reactionText('🎉', { body: 'we won' })).toBe('Reacted 🎉 to “we won”')
|
||||
expect(reactionText('👍', { body: '', media: [{}] })).toBe('Liked an image')
|
||||
expect(reactionText('❤️', { body: 'hi' }, true)).toBe('Removed a heart from “hi”')
|
||||
expect(reactionText('🎉', { body: 'hi' }, true)).toBe('Removed a 🎉 from “hi”')
|
||||
})
|
||||
|
||||
it('round-trips through the parser, long messages cut short', () => {
|
||||
const long = 'word '.repeat(60).trim()
|
||||
for (const e of ['❤️', '👍', '👎', '😂', '‼️', '❓', '🎉', '👨👩👧']) {
|
||||
for (const removed of [false, true]) {
|
||||
const a = msg(long)
|
||||
const r = msg(reactionText(e, a, removed), { out: true })
|
||||
const p = parseReaction(r.body)
|
||||
expect(p?.removed).toBe(removed)
|
||||
expect(sameEmoji(p?.emoji, e)).toBe(true)
|
||||
if (!removed) expect(foldReactions([a, r]).reactions.get(a.id)?.[0].emoji).toBe(p?.emoji)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
it('a second reaction replaces mine; the same one again takes it back', () => {
|
||||
const a = msg('dinner?')
|
||||
const r1 = msg(reactionText('👍', a), { out: true })
|
||||
const r2 = msg(reactionText('❤️', a), { out: true })
|
||||
expect(foldReactions([a, r1, r2]).reactions.get(a.id)?.map((r) => r.emoji)).toEqual(['❤️'])
|
||||
const r3 = msg(reactionText('❤️', a, true), { out: true })
|
||||
expect(foldReactions([a, r1, r2, r3]).reactions.has(a.id)).toBe(false)
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user