Skip to content

Commit 0785022

Browse files
committed
feat: show emoji-only messages larger, like iMessage/Slack
1 parent b683891 commit 0785022

27 files changed

Lines changed: 755 additions & 14 deletions

‎KNOWLEDGE_BASE.md‎

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,18 @@ Sources: [translation endpoint](app/Http/Controllers/CommitTranslationController
263263

264264
Commit and reply text supports inline code in backticks and fenced code blocks with syntax highlighting, a **Wrap lines** toggle, and a copy control. A title after the language, as in ```` ```php title="app/Models/User.php" ````, labels the block in place of the language. Text outside code supports emoji shortcodes, clickable URLs, `@username` mentions, and `#hashtags`, which open commit search for signed-in members and stay plain text for guests. This is developer-oriented text formatting, not a full rich-text editor.
265265

266+
A commit, reply, or remotes message made of only one to three emoji, shortcodes included, shows them large, as Apple's iMessage and Slack do: about three times the text size for one emoji, twice the text size for two or three emoji.
267+
268+
In remotes, a message that only contains one to three emoji also drops its bubble, unless images or a voice note come with it. A quoted commit that only contains one to three emoji also shows those emoji large inside the quote. Notifications and pinned-message previews always show emoji at their normal size.
269+
270+
A commit or reply that only contains emoji, however many, has no **Translate** button, because there is nothing to translate.
271+
272+
Large emoji are on by default. To show emoji at their normal size instead, open Settings → Appearance → **Large emoji** and choose **Off**. This choice is saved in that browser only, so other browsers and devices keep their own setting. The mobile apps don't follow this setting; each app decides whether it shows large emoji and whether it offers its own switch.
273+
274+
Older browsers that lack the requirements to support this feature (Safari before 17, Firefox before 125) show the emoji at their normal size.
275+
276+
The signed and public APIs send the count of emoji as `jumbo_emoji` (0 to 3, 0 meaning normal size) on commits and messages, so the apps can match the web.
277+
266278
The smiley button in the commit, reply and quote composers opens the same searchable emoji picker as reactions in remotes. Picking an emoji inserts it where the caret was, or over the selected text, and puts the caret right after it.
267279

268280
In commits, replies, and remotes, start a line with `>` to render a quote block. Consecutive quoted lines stay together; an unquoted line ends the block. Quotes keep inline code, links, mentions, and emoji formatting. A `>` inside code or in the middle of a line stays literal.
@@ -273,7 +285,7 @@ Typing **#123** in a composer looks up that exact issue or pull request in the /
273285

274286
Write `color(#ff8a4c)` or `color(#fff)` outside code to show the hex value with a small color swatch. The `color(...)` markup stays in the draft and is hidden in the rendered commit. It accepts 3, 4, 6 or 8 hex digits. A bare `#` followed by a letter is a hashtag. On the web, if the text of a commit, reply, quote, or Remotes message contains a hashtag that could be a color, the composer shows the swatch syntax and offers to apply it. Colors that start with a digit can still show a swatch without the markup: `#000`, `#000000` and `#333333` are colors, while `#123` and `#333` stay plain text. The full-width `#` also works for automatic swatches, as in `#fff`. A swatch written with `color(...)` does not add the commit to a guild.
275287

276-
Sources: [body renderer](resources/js/components/commit-body.tsx), [emoji picker button](resources/js/components/emoji-picker.tsx), [colors](resources/js/lib/colors.ts), [code blocks](resources/js/components/code-block.tsx), [mention suggestions](app/Http/Controllers/MentionSuggestionController.php), [mention parsing](app/Services/Mentions.php).
288+
Sources: [body renderer](resources/js/components/commit-body.tsx), [jumbo emoji](resources/js/lib/emoji.ts), [jumbo emoji for the API](app/Services/JumboEmoji.php), [emoji picker button](resources/js/components/emoji-picker.tsx), [colors](resources/js/lib/colors.ts), [code blocks](resources/js/components/code-block.tsx), [mention suggestions](app/Http/Controllers/MentionSuggestionController.php), [mention parsing](app/Services/Mentions.php).
277289

278290
### Draft previews
279291

@@ -512,6 +524,7 @@ Settings → Appearance offers:
512524
- **Theme:** Light, Dark, or System.
513525
- **Navigation:** expanded or collapsed, on wide screens. The navigation also has its own collapse button.
514526
- **Lane dimming:** on by default; other commits fade while the pointer rests on a commit or its author.
527+
- **Large emoji:** on by default. A commit, reply, or remotes message made of only one to three emoji shows those emoji [large](#code-emoji-and-mentions). Choose **Off** to show them at their normal size.
515528
- **Replies:** how many replies show under a commit before "Show more": 1, 3, 5, 10, 15, 20, or 25 (3 by default).
516529
- **Who to follow:** show or hide the suggestions.
517530

‎app/Http/Middleware/HandleInertiaRequests.php‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,8 @@ public function share(Request $request): array
179179
'eventYear' => EventTheme::greetedYear($request),
180180
'eventThemeChoice' => EventTheme::choiceFrom(is_string($request->cookie('event_theme')) ? $request->cookie('event_theme') : null),
181181
'dimsLanes' => $request->cookie('lane_dimming') !== 'false',
182+
// Messages of only a few emoji show them large unless this device turned it off in Appearance.
183+
'showsLargeEmoji' => $request->cookie('large_emoji') !== 'false',
182184
'repliesPerPage' => RepliesPerPage::of($request)->value,
183185
'clock' => ReaderClock::of($request)->toArray(),
184186
// Relative times count from it on the server and while the browser hydrates the page, so both agree.

‎app/Http/Resources/CommitResource.php‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use App\Models\Poll;
1212
use App\Models\User;
1313
use App\Services\CommitBodies;
14+
use App\Services\JumboEmoji;
1415
use App\Services\Mentions;
1516
use Illuminate\Database\Eloquent\Collection;
1617
use Illuminate\Http\Request;
@@ -65,6 +66,8 @@ public function toArray(Request $request): array
6566
'id' => $this->id,
6667
'short_hash' => mb_substr(str_replace('-', '', $this->id), -7),
6768
'body' => $this->body,
69+
// How many emoji the body shows large, as the web does: 1 to 3 when it is nothing but them, 0 otherwise.
70+
'jumbo_emoji' => resolve(JumboEmoji::class)->count($this->body),
6871
'guild_handle' => $this->whenLoaded('guild', fn (Guild $guild): string => $guild->handle),
6972
'guild' => $this->whenLoaded('guild', fn (Guild $guild): array => [
7073
'handle' => $guild->handle,

‎app/Http/Resources/MessageResource.php‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use App\Models\MessageVoice;
1010
use App\Models\User;
1111
use App\Services\CodeSpans;
12+
use App\Services\JumboEmoji;
1213
use App\Services\Mentions;
1314
use Illuminate\Http\Request;
1415
use Illuminate\Http\Resources\Json\JsonResource;
@@ -46,6 +47,7 @@ public function toArray(Request $request): array
4647
'client_id' => $this->client_id,
4748
'body' => $this->body,
4849
'body_segments' => resolve(CodeSpans::class)->highlight($this->body),
50+
'jumbo_emoji' => $this->jumboEmoji(),
4951
'mentions' => collect(resolve(Mentions::class)->positions($this->body, users: $this->mentions ?? []))
5052
->filter(fn (array $mention): bool => $mention['id'] !== null)
5153
->values(),
@@ -88,4 +90,22 @@ public function toArray(Request $request): array
8890

8991
return $this->withGuildMentions ? ShownGuildMentions::of($shown, $request->user()) : $shown;
9092
}
93+
94+
/**
95+
* How many emoji the message shows large, as the web's thread does: 1 to 3 when its body is nothing but them and no
96+
* images or voice note come with it, 0 otherwise. Its attachments are only looked up for such a body.
97+
*/
98+
private function jumboEmoji(): int
99+
{
100+
$count = resolve(JumboEmoji::class)->count($this->body);
101+
102+
if ($count === 0) {
103+
return 0;
104+
}
105+
106+
$hasImages = $this->relationLoaded('images') ? $this->images->isNotEmpty() : $this->images()->exists();
107+
$hasVoice = $this->relationLoaded('voice') ? $this->voice instanceof MessageVoice : $this->voice()->exists();
108+
109+
return $hasImages || $hasVoice ? 0 : $count;
110+
}
91111
}

‎app/Services/JumboEmoji.php‎

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace App\Services;
6+
7+
/**
8+
* Whether a body is nothing but a few emoji, so it shows them large: the rule resources/js/lib/emoji.ts applies on the
9+
* web, sent to API clients so every surface agrees. tests/Fixtures/jumbo-emoji.json holds the cases both must pass.
10+
*/
11+
final readonly class JumboEmoji
12+
{
13+
/**
14+
* The most emoji a body shows large; more show at their normal size.
15+
*/
16+
public const int MAX = 3;
17+
18+
/**
19+
* Longer than any body of only emoji worth telling apart, counted in UTF-16 code units as the web counts it.
20+
*/
21+
private const int MAX_LENGTH = 128;
22+
23+
/**
24+
* One emoji as it shows by default (🔥), a text symbol asked to show as one (❤️), or either with a skin tone (👋🏽).
25+
* A lone regional indicator is half a flag, never an emoji of its own.
26+
*/
27+
private const string ELEMENT = '(?:(?![\x{1F1E6}-\x{1F1FF}])\p{Emoji_Presentation}\p{Emoji_Modifier}?|\p{Extended_Pictographic}\x{FE0F}|\p{Emoji_Modifier_Base}\p{Emoji_Modifier})';
28+
29+
/**
30+
* One whole emoji: a flag (🇵🇹), a keycap (1️⃣), a subdivision flag (🏴󠁧󠁢󠁳󠁣󠁴󠁿), or emoji joined by ZWJ (👩‍💻).
31+
* Bare `1`, `#` or `©` aren't.
32+
*/
33+
private const string SINGLE_EMOJI = '/^(?:[\x{1F1E6}-\x{1F1FF}]{2}|[0-9#*]\x{FE0F}\x{20E3}|\x{1F3F4}[\x{E0061}-\x{E007A}]+\x{E007F}|'.self::ELEMENT.'(?:\x{200D}'.self::ELEMENT.')*)$/u';
34+
35+
public function __construct(private EmojiShortcodes $shortcodes)
36+
{
37+
//
38+
}
39+
40+
/**
41+
* How many emoji a body shows large: one to three when it is nothing but them, 0 otherwise.
42+
*/
43+
public function count(string $body): int
44+
{
45+
$count = $this->emojiOnlyCount($body);
46+
47+
return $count <= self::MAX ? $count : 0;
48+
}
49+
50+
/**
51+
* How many emoji a body is made of when it is nothing but emoji, with shortcodes counted as theirs; 0 otherwise.
52+
*/
53+
public function emojiOnlyCount(string $body): int
54+
{
55+
if (
56+
// UTF-16 counts a character past U+FFFF, as most emoji are, twice.
57+
mb_strlen($body) + preg_match_all('/[\x{10000}-\x{10FFFF}]/u', $body) > self::MAX_LENGTH
58+
|| preg_match('/[a-z]/i', (string) preg_replace('/:[a-z0-9_+-]+:/i', '', $body)) === 1
59+
) {
60+
return 0;
61+
}
62+
63+
// \X takes one grapheme at a time, the way the web's Intl.Segmenter splits text: a whole flag or ZWJ family each.
64+
preg_match_all('/\X/u', $this->shortcodes->replace($body), $graphemes);
65+
66+
$count = 0;
67+
68+
foreach ($graphemes[0] as $grapheme) {
69+
if (preg_match('/^[\s\p{Z}\x{FEFF}]+$/u', $grapheme) === 1) {
70+
continue;
71+
}
72+
73+
if (preg_match(self::SINGLE_EMOJI, $grapheme) !== 1) {
74+
return 0;
75+
}
76+
77+
$count++;
78+
}
79+
80+
return $count;
81+
}
82+
}

‎bootstrap/app.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
$middleware->trimStrings(except: ['sdp', 'signals.*.sdp']);
4848
$middleware->append(PreventFraming::class);
4949

50-
$middleware->encryptCookies(except: ['appearance', 'sidebar_state', 'who_to_follow', 'who_to_follow_round', 'lane_dimming', 'event_theme', 'replies_per_page', 'time_zone', 'hour_cycle']);
50+
$middleware->encryptCookies(except: ['appearance', 'sidebar_state', 'who_to_follow', 'who_to_follow_round', 'lane_dimming', 'large_emoji', 'event_theme', 'replies_per_page', 'time_zone', 'hour_cycle']);
5151

5252
// Approving the app is the one page a guest should leave for GitHub, then return to. Every other page
5353
// they open while signed out stays the log. Locally, sign-in is the modal on that log.

‎resources/js/components/chat/conversation-thread.tsx‎

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import {
2525
import { MentionsBell } from '@/components/chat/mentions-bell';
2626
import {
2727
LiftedMessage,
28+
isJumboMessage,
2829
MessageImages,
2930
MessageLinkCard,
3031
MessageText,
@@ -67,6 +68,7 @@ import { UserAvatar } from '@/components/user-avatar';
6768
import { UserPreview } from '@/components/user-preview';
6869
import { useChat, useThread } from '@/hooks/use-chat';
6970
import { useImageAttachments } from '@/hooks/use-image-attachments';
71+
import { useLargeEmoji } from '@/hooks/use-large-emoji';
7072
import { useLinkCard } from '@/hooks/use-link-card';
7173
import { moveCaretToEnd, useStash } from '@/hooks/use-stash';
7274
import { useVoiceNote } from '@/hooks/use-voice-note';
@@ -1325,7 +1327,18 @@ function BubbleWithMeta({
13251327
? target.partner.lane
13261328
: (pulledBy[0]?.lane ?? user.lane);
13271329

1328-
const isOnPrimary = isMine && status !== 'staged' && status !== 'rejected';
1330+
const showsLargeEmoji = useLargeEmoji();
1331+
const isJumboEmoji =
1332+
showsLargeEmoji &&
1333+
isJumboMessage({
1334+
body: message.body,
1335+
body_segments:
1336+
'body_segments' in message ? message.body_segments : null,
1337+
images,
1338+
voice,
1339+
});
1340+
const isOnPrimary =
1341+
isMine && !isJumboEmoji && status !== 'staged' && status !== 'rejected';
13291342
const side = isMine ? 'mine' : 'theirs';
13301343
const replyToThis =
13311344
onReply !== null && bubble.kind === 'message'
@@ -1479,11 +1492,17 @@ function BubbleWithMeta({
14791492
? bubble.message.id
14801493
: undefined
14811494
}
1482-
className={bubbleClass}
1495+
className={cn(
1496+
bubbleClass,
1497+
// A few emoji alone stand on their own, without the bubble behind them.
1498+
isJumboEmoji &&
1499+
'bg-transparent text-foreground',
1500+
)}
14831501
>
14841502
<MessageText
14851503
message={message}
14861504
isMine={isOnPrimary}
1505+
isJumboable={isJumboEmoji}
14871506
/>
14881507
{bubbleActions}
14891508
</div>

‎resources/js/components/chat/message-parts.tsx‎

Lines changed: 44 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ import { CommitImages } from '@/components/commit-images';
1111
import type { ShownImage } from '@/components/commit-images';
1212
import { ImageViewer } from '@/components/image-viewer';
1313
import { LinkPreview } from '@/components/link-preview';
14+
import { useLargeEmoji } from '@/hooks/use-large-emoji';
1415
import { bodySegments } from '@/lib/code';
16+
import { jumboEmojiCount } from '@/lib/emoji';
1517
import { isReplySwipe, replyPull, replyThreshold } from '@/lib/reply-swipe';
1618
import { cn, laneTextColor } from '@/lib/utils';
1719
import type {
@@ -33,15 +35,38 @@ export type Author = { name: string; lane: Lane; isMe: boolean };
3335
const onPrimary =
3436
'[&_a]:text-primary-foreground [&_a]:underline [&_a]:decoration-primary-foreground/50 [&_a]:underline-offset-2 [&_.text-muted-foreground]:text-primary-foreground/70 [&_.fill-foreground]:fill-primary-foreground [&_blockquote]:border-neutral-200 [&_code]:bg-primary-foreground/15';
3537

38+
/**
39+
* Whether a message is nothing but one to three emoji, with no images or voice note beside them, so it shows them large
40+
* and without its bubble.
41+
*/
42+
export function isJumboMessage(message: {
43+
body: string;
44+
body_segments?: BodySegment[] | null;
45+
// Sent images and voice notes, or the files of ones still being pushed.
46+
images?: readonly unknown[] | null;
47+
voice?: unknown;
48+
}): boolean {
49+
return (
50+
(message.images ?? []).length === 0 &&
51+
(message.voice ?? null) === null &&
52+
jumboEmojiCount(message.body_segments ?? bodySegments(message.body)) > 0
53+
);
54+
}
55+
3656
export function MessageText({
3757
message,
3858
isMine,
59+
isJumboable = true,
3960
}: {
4061
message: Pick<
4162
Message,
4263
'body' | 'body_segments' | 'mentions' | 'guild_mentions'
4364
>;
4465
isMine: boolean;
66+
/**
67+
* Whether a few emoji alone show large: not beside images or a voice note, nor in a small preview.
68+
*/
69+
isJumboable?: boolean;
4570
}) {
4671
const segments: BodySegment[] =
4772
message.body_segments ?? bodySegments(message.body);
@@ -53,6 +78,7 @@ export function MessageText({
5378
guildMentions={message.guild_mentions}
5479
linksEveryMention={false}
5580
className={cn('flow-root leading-snug', { [onPrimary]: isMine })}
81+
isJumboable={isJumboable}
5682
/>
5783
);
5884
}
@@ -86,26 +112,39 @@ export function LiftedMessage({
86112
message: Message;
87113
isMine: boolean;
88114
}) {
115+
const showsLargeEmoji = useLargeEmoji();
89116
const voice = message.voice ?? null;
90117

91118
if (voice === null && message.body === '') {
92119
return null;
93120
}
94121

122+
// A few emoji alone lift as they show in the thread: large, without a bubble.
123+
const isJumbo = showsLargeEmoji && isJumboMessage(message);
124+
95125
return (
96126
<div
97127
className={cn(
98-
'w-fit max-w-full rounded-lg shadow-[0_12px_30px_-12px_rgb(0_0_0/0.45)]',
128+
'w-fit max-w-full rounded-lg',
99129
voice === null
100130
? 'px-3.5 py-2 text-[15px] wrap-anywhere'
101131
: 'p-2',
102-
isMine
103-
? 'bg-primary text-primary-foreground'
104-
: 'bg-muted text-foreground',
132+
isJumbo
133+
? 'text-foreground drop-shadow-[0_12px_18px_rgb(0_0_0/0.35)]'
134+
: cn(
135+
'shadow-[0_12px_30px_-12px_rgb(0_0_0/0.45)]',
136+
isMine
137+
? 'bg-primary text-primary-foreground'
138+
: 'bg-muted text-foreground',
139+
),
105140
)}
106141
>
107142
{voice === null ? (
108-
<MessageText message={message} isMine={isMine} />
143+
<MessageText
144+
message={message}
145+
isMine={isMine && !isJumbo}
146+
isJumboable={isJumbo}
147+
/>
109148
) : (
110149
<VoiceNote voice={voice} />
111150
)}

‎resources/js/components/chat/pinned-messages.tsx‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -842,7 +842,12 @@ function PinnedText({ message }: { message: Message }) {
842842
'max-h-[3lh] overflow-hidden': !isExpanded,
843843
})}
844844
>
845-
<MessageText message={message} isMine={false} />
845+
{/* A clipped preview, like a notification: a few emoji stay at their normal size. */}
846+
<MessageText
847+
message={message}
848+
isMine={false}
849+
isJumboable={false}
850+
/>
846851
</div>
847852
{isLong && (
848853
<button

0 commit comments

Comments
 (0)