Merge pull request #2953 from matrix-org/t3chguy/roomavatar
Command to change avatar for a single room, including upload of mxc respull/21833/head
commit
76f37d691d
|
@ -1,6 +1,7 @@
|
||||||
/*
|
/*
|
||||||
Copyright 2015, 2016 OpenMarket Ltd
|
Copyright 2015, 2016 OpenMarket Ltd
|
||||||
Copyright 2018 New Vector Ltd
|
Copyright 2018 New Vector Ltd
|
||||||
|
Copyright 2019 Michael Telatynski <7t3chguy@gmail.com>
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
|
@ -30,6 +31,7 @@ import MultiInviter from './utils/MultiInviter';
|
||||||
import { linkifyAndSanitizeHtml } from './HtmlUtils';
|
import { linkifyAndSanitizeHtml } from './HtmlUtils';
|
||||||
import QuestionDialog from "./components/views/dialogs/QuestionDialog";
|
import QuestionDialog from "./components/views/dialogs/QuestionDialog";
|
||||||
import WidgetUtils from "./utils/WidgetUtils";
|
import WidgetUtils from "./utils/WidgetUtils";
|
||||||
|
import Promise from "bluebird";
|
||||||
|
|
||||||
class Command {
|
class Command {
|
||||||
constructor({name, args='', description, runFn, hideCompletionAfterSpace=false}) {
|
constructor({name, args='', description, runFn, hideCompletionAfterSpace=false}) {
|
||||||
|
@ -190,8 +192,8 @@ export const CommandMap = {
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
|
|
||||||
roomnick: new Command({
|
myroomnick: new Command({
|
||||||
name: 'roomnick',
|
name: 'myroomnick',
|
||||||
args: '<display_name>',
|
args: '<display_name>',
|
||||||
description: _td('Changes your display nickname in the current room only'),
|
description: _td('Changes your display nickname in the current room only'),
|
||||||
runFn: function(roomId, args) {
|
runFn: function(roomId, args) {
|
||||||
|
@ -208,6 +210,47 @@ export const CommandMap = {
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
|
|
||||||
|
myroomavatar: new Command({
|
||||||
|
name: 'myroomavatar',
|
||||||
|
args: '[<mxc_url>]',
|
||||||
|
description: _td('Changes your avatar in this current room only'),
|
||||||
|
runFn: function(roomId, args) {
|
||||||
|
const cli = MatrixClientPeg.get();
|
||||||
|
const room = cli.getRoom(roomId);
|
||||||
|
const userId = cli.getUserId();
|
||||||
|
|
||||||
|
let promise = Promise.resolve(args);
|
||||||
|
if (!args) {
|
||||||
|
promise = new Promise((resolve) => {
|
||||||
|
const fileSelector = document.createElement('input');
|
||||||
|
fileSelector.setAttribute('type', 'file');
|
||||||
|
fileSelector.onchange = (ev) => {
|
||||||
|
const file = ev.target.files[0];
|
||||||
|
|
||||||
|
const UploadConfirmDialog = sdk.getComponent("dialogs.UploadConfirmDialog");
|
||||||
|
Modal.createTrackedDialog('Upload Files confirmation', '', UploadConfirmDialog, {
|
||||||
|
file,
|
||||||
|
onFinished: (shouldContinue) => {
|
||||||
|
if (shouldContinue) resolve(cli.uploadContent(file));
|
||||||
|
},
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
fileSelector.click();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return success(promise.then((url) => {
|
||||||
|
const ev = room.currentState.getStateEvents('m.room.member', userId);
|
||||||
|
const content = {
|
||||||
|
...ev ? ev.getContent() : { membership: 'join' },
|
||||||
|
avatar_url: url,
|
||||||
|
};
|
||||||
|
return cli.sendStateEvent(roomId, 'm.room.member', content, userId);
|
||||||
|
}));
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
|
||||||
tint: new Command({
|
tint: new Command({
|
||||||
name: 'tint',
|
name: 'tint',
|
||||||
args: '<color1> [<color2>]',
|
args: '<color1> [<color2>]',
|
||||||
|
@ -727,6 +770,7 @@ const aliases = {
|
||||||
j: "join",
|
j: "join",
|
||||||
newballsplease: "discardsession",
|
newballsplease: "discardsession",
|
||||||
goto: "join", // because it handles event permalinks magically
|
goto: "join", // because it handles event permalinks magically
|
||||||
|
roomnick: "myroomnick",
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -146,6 +146,7 @@
|
||||||
"Upgrade": "Upgrade",
|
"Upgrade": "Upgrade",
|
||||||
"Changes your display nickname": "Changes your display nickname",
|
"Changes your display nickname": "Changes your display nickname",
|
||||||
"Changes your display nickname in the current room only": "Changes your display nickname in the current room only",
|
"Changes your display nickname in the current room only": "Changes your display nickname in the current room only",
|
||||||
|
"Changes your avatar in this current room only": "Changes your avatar in this current room only",
|
||||||
"Changes colour scheme of current room": "Changes colour scheme of current room",
|
"Changes colour scheme of current room": "Changes colour scheme of current room",
|
||||||
"Gets or sets the room topic": "Gets or sets the room topic",
|
"Gets or sets the room topic": "Gets or sets the room topic",
|
||||||
"This room has no topic.": "This room has no topic.",
|
"This room has no topic.": "This room has no topic.",
|
||||||
|
|
Loading…
Reference in New Issue