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

Extend slash command '/topic' to display the room topic #2532

Merged
merged 18 commits into from
Feb 7, 2019
Merged
27 changes: 23 additions & 4 deletions src/SlashCommands.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,12 @@ import SettingsStore, {SettingLevel} from './settings/SettingsStore';
import {MATRIXTO_URL_PATTERN} from "./linkify-matrix";
import * as querystring from "querystring";
import MultiInviter from './utils/MultiInviter';
import * as linkify from 'linkifyjs';
import linkifyString from 'linkifyjs/string';
import linkifyMatrix from './linkify-matrix';
import sanitizeHtml from 'sanitize-html';

linkifyMatrix(linkify);

class Command {
constructor({name, args='', description, runFn, hideCompletionAfterSpace=false}) {
Expand Down Expand Up @@ -137,13 +142,27 @@ export const CommandMap = {

topic: new Command({
name: 'topic',
args: '<topic>',
description: _td('Sets the room topic'),
args: '[<topic>]',
description: _td('Gets or sets the room topic'),
runFn: function(roomId, args) {
const cli = MatrixClientPeg.get();
if (args) {
return success(MatrixClientPeg.get().setRoomTopic(roomId, args));
return success(cli.setRoomTopic(roomId, args));
}
return reject(this.getUsage());
const room = cli.getRoom(roomId);
if (!room) return reject('Bad room ID: ' + roomId);

const topicEvents = room.currentState.getStateEvents('m.room.topic', '');
const topic = topicEvents.getContent().topic;
const topicHtml = linkifyString(sanitizeHtml(topic));

const QuestionDialog = sdk.getComponent('dialogs.QuestionDialog');
Modal.createTrackedDialog('Slash Commands', 'Topic', QuestionDialog, {
title: room.name,
description: <div dangerouslySetInnerHTML={{ __html: topicHtml }} />,
hasCancelButton: false,
});
return success();
},
}),

Expand Down
2 changes: 1 addition & 1 deletion src/i18n/strings/en_EN.json
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@
"Upgrades a room to a new version": "Upgrades a room to a new version",
"Changes your display nickname": "Changes your display nickname",
"Changes colour scheme of current room": "Changes colour scheme of current room",
"Sets the room topic": "Sets the room topic",
"Gets or sets the room topic": "Gets or sets the room topic",
"Sets the room name": "Sets the room name",
"Invites user with given id to current room": "Invites user with given id to current room",
"Joins room with given alias": "Joins room with given alias",
Expand Down