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

Commit 76f37d6

Browse files
authored
Merge pull request #2953 from matrix-org/t3chguy/roomavatar
Command to change avatar for a single room, including upload of mxc res
2 parents 3161682 + d9b03b0 commit 76f37d6

File tree

2 files changed

+47
-2
lines changed

2 files changed

+47
-2
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.
@@ -30,6 +31,7 @@ import MultiInviter from './utils/MultiInviter';
3031
import { linkifyAndSanitizeHtml } from './HtmlUtils';
3132
import QuestionDialog from "./components/views/dialogs/QuestionDialog";
3233
import WidgetUtils from "./utils/WidgetUtils";
34+
import Promise from "bluebird";
3335

3436
class Command {
3537
constructor({name, args='', description, runFn, hideCompletionAfterSpace=false}) {
@@ -190,8 +192,8 @@ export const CommandMap = {
190192
},
191193
}),
192194

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

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

732776

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)