Fix terminals on hash room parsing

This commit is contained in:
Jack Kingsman
2026-04-02 00:23:07 -07:00
parent 4420d44838
commit 5e1bdb2cc1
3 changed files with 42 additions and 6 deletions
+26
View File
@@ -169,6 +169,32 @@ describe('MessageList channel sender rendering', () => {
expect(onChannelReferenceClick).toHaveBeenCalledWith('#mesh-room'); expect(onChannelReferenceClick).toHaveBeenCalledWith('#mesh-room');
}); });
it('links valid channel references when followed by clause punctuation', async () => {
const user = userEvent.setup();
const onChannelReferenceClick = vi.fn();
render(
<MessageList
messages={[
createMessage({
text: 'Alice: Check #mesh-room, then #ops-room; then #alpha-room.',
}),
]}
contacts={[]}
loading={false}
onChannelReferenceClick={onChannelReferenceClick}
/>
);
await user.click(screen.getByRole('button', { name: '#mesh-room' }));
await user.click(screen.getByRole('button', { name: '#ops-room' }));
await user.click(screen.getByRole('button', { name: '#alpha-room' }));
expect(onChannelReferenceClick).toHaveBeenNthCalledWith(1, '#mesh-room');
expect(onChannelReferenceClick).toHaveBeenNthCalledWith(2, '#ops-room');
expect(onChannelReferenceClick).toHaveBeenNthCalledWith(3, '#alpha-room');
});
it('links valid channel references in direct messages too', async () => { it('links valid channel references in direct messages too', async () => {
const user = userEvent.setup(); const user = userEvent.setup();
const onChannelReferenceClick = vi.fn(); const onChannelReferenceClick = vi.fn();
+15 -5
View File
@@ -122,11 +122,21 @@ describe('linked channel references', () => {
]); ]);
}); });
it('ignores invalid or embedded channel-like text', () => { it('finds linked channel references terminated by clause punctuation', () => {
expect( expect(
findLinkedChannelReferences( findLinkedChannelReferences('Join #mesh-room, then #ops2; finally #alpha-room.')
'skip #Bad #bad--name abc#ops #ops- #opsRoom #ops_room #good-room,' ).toEqual([
) { label: '#mesh-room', start: 5, end: 15 },
).toEqual([]); { label: '#ops2', start: 22, end: 27 },
{ label: '#alpha-room', start: 37, end: 48 },
]);
});
it('ignores invalid or embedded channel-like text', () => {
const references = findLinkedChannelReferences(
'skip #Bad #bad--name abc#ops #ops- #opsRoom #ops_room #good-room,'
);
expect(references.map((reference) => reference.label)).toEqual(['#good-room']);
}); });
}); });
+1 -1
View File
@@ -3,7 +3,7 @@
* Channel messages have format "sender: message". * Channel messages have format "sender: message".
*/ */
const HASHTAG_CHANNEL_NAME_PATTERN = /^[a-z0-9]+(?:-[a-z0-9]+)*$/; const HASHTAG_CHANNEL_NAME_PATTERN = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
const HASHTAG_CHANNEL_REFERENCE_PATTERN = /(^|\s)(#[a-z0-9]+(?:-[a-z0-9]+)*)(?=$|\s)/g; const HASHTAG_CHANNEL_REFERENCE_PATTERN = /(^|\s)(#[a-z0-9]+(?:-[a-z0-9]+)*)(?=$|[\s.,;:])/g;
export function parseSenderFromText(text: string): { sender: string | null; content: string } { export function parseSenderFromText(text: string): { sender: string | null; content: string } {
const colonIndex = text.indexOf(': '); const colonIndex = text.indexOf(': ');