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

Commit 666cab9

Browse files
authored
Fix emoting with emoji or pills (#8105)
* 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
1 parent 7a22682 commit 666cab9

File tree

3 files changed

+19
-5
lines changed

3 files changed

+19
-5
lines changed

src/SlashCommands.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,13 +153,11 @@ export class Command {
153153
public run(roomId: string, threadId: string, args: string): RunResult {
154154
// if it has no runFn then its an ignored/nop command (autocomplete only) e.g `/me`
155155
if (!this.runFn) {
156-
reject(
156+
return reject(
157157
newTranslatableError(
158158
"Command error: Unable to handle slash command.",
159159
),
160160
);
161-
162-
return;
163161
}
164162

165163
const renderingType = threadId

src/editor/serialize.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,9 @@ export function textSerialize(model: EditorModel): string {
181181
}
182182

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

187189
export function startsWith(model: EditorModel, prefix: string, caseSensitive = true): boolean {

test/components/views/rooms/SendMessageComposer-test.tsx

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,20 @@ describe('<SendMessageComposer/>', () => {
131131
});
132132
});
133133

134+
it("allows emoting with non-text parts", () => {
135+
const model = new EditorModel([], createPartCreator(), createRenderer());
136+
const documentOffset = new DocumentOffset(16, true);
137+
model.update("/me ✨sparkles✨", "insertText", documentOffset);
138+
expect(model.parts.length).toEqual(4); // Emoji count as non-text
139+
140+
const content = createMessageContent(model, null, undefined, permalinkCreator);
141+
142+
expect(content).toEqual({
143+
body: "✨sparkles✨",
144+
msgtype: "m.emote",
145+
});
146+
});
147+
134148
it("allows sending double-slash escaped slash commands correctly", () => {
135149
const model = new EditorModel([], createPartCreator(), createRenderer());
136150
const documentOffset = new DocumentOffset(32, true);
@@ -194,7 +208,7 @@ describe('<SendMessageComposer/>', () => {
194208
});
195209
};
196210

197-
fit("renders text and placeholder correctly", () => {
211+
it("renders text and placeholder correctly", () => {
198212
const wrapper = getComponent({ placeholder: "placeholder string" });
199213

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

0 commit comments

Comments
 (0)