Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Commit

Permalink
Fix emoting with emoji or pills (#8105)
Browse files Browse the repository at this point in the history
* Fix emoting with emoji or pills

* Fix some slash command errors not being shown

* Re-enable mistakenly skipped SendMessageComposer tests

* Test emoting with non-text parts
  • Loading branch information
robintown committed Mar 21, 2022
1 parent 7a22682 commit 666cab9
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
4 changes: 1 addition & 3 deletions src/SlashCommands.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -153,13 +153,11 @@ export class Command {
public run(roomId: string, threadId: string, args: string): RunResult {
// if it has no runFn then its an ignored/nop command (autocomplete only) e.g `/me`
if (!this.runFn) {
reject(
return reject(
newTranslatableError(
"Command error: Unable to handle slash command.",
),
);

return;
}

const renderingType = threadId
Expand Down
4 changes: 3 additions & 1 deletion src/editor/serialize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,9 @@ export function textSerialize(model: EditorModel): string {
}

export function containsEmote(model: EditorModel): boolean {
return startsWith(model, "/me ", false) && model.parts[0]?.text?.length > 4;
const hasCommand = startsWith(model, "/me ", false);
const hasArgument = model.parts[0]?.text?.length > 4 || model.parts.length > 1;
return hasCommand && hasArgument;
}

export function startsWith(model: EditorModel, prefix: string, caseSensitive = true): boolean {
Expand Down
16 changes: 15 additions & 1 deletion test/components/views/rooms/SendMessageComposer-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,20 @@ describe('<SendMessageComposer/>', () => {
});
});

it("allows emoting with non-text parts", () => {
const model = new EditorModel([], createPartCreator(), createRenderer());
const documentOffset = new DocumentOffset(16, true);
model.update("/me ✨sparkles✨", "insertText", documentOffset);
expect(model.parts.length).toEqual(4); // Emoji count as non-text

const content = createMessageContent(model, null, undefined, permalinkCreator);

expect(content).toEqual({
body: "✨sparkles✨",
msgtype: "m.emote",
});
});

it("allows sending double-slash escaped slash commands correctly", () => {
const model = new EditorModel([], createPartCreator(), createRenderer());
const documentOffset = new DocumentOffset(32, true);
Expand Down Expand Up @@ -194,7 +208,7 @@ describe('<SendMessageComposer/>', () => {
});
};

fit("renders text and placeholder correctly", () => {
it("renders text and placeholder correctly", () => {
const wrapper = getComponent({ placeholder: "placeholder string" });

expect(wrapper.find('[aria-label="placeholder string"]')).toHaveLength(1);
Expand Down

0 comments on commit 666cab9

Please sign in to comment.