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

Add /myavatar command #3155

Merged
merged 3 commits into from
Jun 29, 2019
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 37 additions & 17 deletions src/SlashCommands.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,26 @@ import WidgetUtils from "./utils/WidgetUtils";
import {textToHtmlRainbow} from "./utils/colour";
import Promise from "bluebird";

const singleMxcUpload = async () => {
return 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(MatrixClientPeg.get().uploadContent(file));
t3chguy marked this conversation as resolved.
Show resolved Hide resolved
},
});
};

fileSelector.click();
});
};

class Command {
constructor({name, args='', description, runFn, hideCompletionAfterSpace=false}) {
this.command = '/' + name;
Expand Down Expand Up @@ -222,23 +242,7 @@ export const CommandMap = {

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();
});
promise = singleMxcUpload();
}

return success(promise.then((url) => {
Expand All @@ -252,6 +256,22 @@ export const CommandMap = {
},
}),

myavatar: new Command({
name: 'myavatar',
args: '[<mxc_url>]',
description: _td('Changes your avatar in all rooms'),
runFn: function(roomId, args) {
let promise = Promise.resolve(args);
if (!args) {
promise = singleMxcUpload();
}

return success(promise.then((url) => {
return MatrixClientPeg.get().setAvatarUrl(url);
}));
},
}),

tint: new Command({
name: 'tint',
args: '<color1> [<color2>]',
Expand Down