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

Commit 909354c

Browse files
authored
Merge branch 'develop' into t3chguy/cmd_rainbow
2 parents 9f9a245 + 99e2ac7 commit 909354c

File tree

4 files changed

+67
-4
lines changed

4 files changed

+67
-4
lines changed

src/SlashCommands.js

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/*
22
Copyright 2015, 2016 OpenMarket Ltd
33
Copyright 2018 New Vector Ltd
4+
Copyright 2019 Michael Telatynski <7t3chguy@gmail.com>
45
56
Licensed under the Apache License, Version 2.0 (the "License");
67
you may not use this file except in compliance with the License.
@@ -31,6 +32,7 @@ import { linkifyAndSanitizeHtml } from './HtmlUtils';
3132
import QuestionDialog from "./components/views/dialogs/QuestionDialog";
3233
import WidgetUtils from "./utils/WidgetUtils";
3334
import {textToHtmlRainbow} from "./utils/colour";
35+
import Promise from "bluebird";
3436

3537
class Command {
3638
constructor({name, args='', description, runFn, hideCompletionAfterSpace=false}) {
@@ -191,8 +193,8 @@ export const CommandMap = {
191193
},
192194
}),
193195

194-
roomnick: new Command({
195-
name: 'roomnick',
196+
myroomnick: new Command({
197+
name: 'myroomnick',
196198
args: '<display_name>',
197199
description: _td('Changes your display nickname in the current room only'),
198200
runFn: function(roomId, args) {
@@ -209,6 +211,47 @@ export const CommandMap = {
209211
},
210212
}),
211213

214+
myroomavatar: new Command({
215+
name: 'myroomavatar',
216+
args: '[<mxc_url>]',
217+
description: _td('Changes your avatar in this current room only'),
218+
runFn: function(roomId, args) {
219+
const cli = MatrixClientPeg.get();
220+
const room = cli.getRoom(roomId);
221+
const userId = cli.getUserId();
222+
223+
let promise = Promise.resolve(args);
224+
if (!args) {
225+
promise = new Promise((resolve) => {
226+
const fileSelector = document.createElement('input');
227+
fileSelector.setAttribute('type', 'file');
228+
fileSelector.onchange = (ev) => {
229+
const file = ev.target.files[0];
230+
231+
const UploadConfirmDialog = sdk.getComponent("dialogs.UploadConfirmDialog");
232+
Modal.createTrackedDialog('Upload Files confirmation', '', UploadConfirmDialog, {
233+
file,
234+
onFinished: (shouldContinue) => {
235+
if (shouldContinue) resolve(cli.uploadContent(file));
236+
},
237+
});
238+
};
239+
240+
fileSelector.click();
241+
});
242+
}
243+
244+
return success(promise.then((url) => {
245+
const ev = room.currentState.getStateEvents('m.room.member', userId);
246+
const content = {
247+
...ev ? ev.getContent() : { membership: 'join' },
248+
avatar_url: url,
249+
};
250+
return cli.sendStateEvent(roomId, 'm.room.member', content, userId);
251+
}));
252+
},
253+
}),
254+
212255
tint: new Command({
213256
name: 'tint',
214257
args: '<color1> [<color2>]',
@@ -748,6 +791,7 @@ const aliases = {
748791
j: "join",
749792
newballsplease: "discardsession",
750793
goto: "join", // because it handles event permalinks magically
794+
roomnick: "myroomnick",
751795
};
752796

753797

src/components/views/dialogs/RoomSettingsDialog.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/*
22
Copyright 2019 New Vector Ltd
3+
Copyright 2019 Michael Telatynski <7t3chguy@gmail.com>
34
45
Licensed under the Apache License, Version 2.0 (the "License");
56
you may not use this file except in compliance with the License.
@@ -24,13 +25,30 @@ import GeneralRoomSettingsTab from "../settings/tabs/room/GeneralRoomSettingsTab
2425
import SecurityRoomSettingsTab from "../settings/tabs/room/SecurityRoomSettingsTab";
2526
import sdk from "../../../index";
2627
import MatrixClientPeg from "../../../MatrixClientPeg";
28+
import dis from "../../../dispatcher";
2729

2830
export default class RoomSettingsDialog extends React.Component {
2931
static propTypes = {
3032
roomId: PropTypes.string.isRequired,
3133
onFinished: PropTypes.func.isRequired,
3234
};
3335

36+
componentWillMount() {
37+
this._dispatcherRef = dis.register(this._onAction);
38+
}
39+
40+
componentWillUnmount() {
41+
dis.unregister(this._dispatcherRef);
42+
}
43+
44+
_onAction = (payload) => {
45+
// When room changes below us, close the room settings
46+
// whilst the modal is open this can only be triggered when someone hits Leave Room
47+
if (payload.action === 'view_next_room') {
48+
this.props.onFinished();
49+
}
50+
};
51+
3452
_getTabs() {
3553
const tabs = [];
3654

src/components/views/rooms/MemberInfo.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -735,8 +735,8 @@ module.exports = withMatrixClient(React.createClass({
735735
// we're only inviting one user.
736736
const inviter = new MultiInviter(roomId);
737737
await inviter.invite([member.userId]).then(() => {
738-
if (inviter.getCompletionState(userId) !== "invited")
739-
throw new Error(inviter.getErrorText(userId));
738+
if (inviter.getCompletionState(member.userId) !== "invited")
739+
throw new Error(inviter.getErrorText(member.userId));
740740
});
741741
} catch (err) {
742742
const ErrorDialog = sdk.getComponent('dialogs.ErrorDialog');

src/i18n/strings/en_EN.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@
146146
"Upgrade": "Upgrade",
147147
"Changes your display nickname": "Changes your display nickname",
148148
"Changes your display nickname in the current room only": "Changes your display nickname in the current room only",
149+
"Changes your avatar in this current room only": "Changes your avatar in this current room only",
149150
"Changes colour scheme of current room": "Changes colour scheme of current room",
150151
"Gets or sets the room topic": "Gets or sets the room topic",
151152
"This room has no topic.": "This room has no topic.",

0 commit comments

Comments
 (0)