From 92a932158df32e8360c649df1c5280390652595b Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Thu, 9 May 2019 22:12:21 +0100 Subject: [PATCH 1/3] Command to change avatar for a single room, including upload of mxc res Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --- src/SlashCommands.js | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/src/SlashCommands.js b/src/SlashCommands.js index f72ba1e005..8757f5108a 100644 --- a/src/SlashCommands.js +++ b/src/SlashCommands.js @@ -1,6 +1,7 @@ /* Copyright 2015, 2016 OpenMarket Ltd Copyright 2018 New Vector Ltd +Copyright 2019 Michael Telatynski <7t3chguy@gmail.com> Licensed under the Apache License, Version 2.0 (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 QuestionDialog from "./components/views/dialogs/QuestionDialog"; import WidgetUtils from "./utils/WidgetUtils"; +import Promise from "bluebird"; class Command { constructor({name, args='', description, runFn, hideCompletionAfterSpace=false}) { @@ -208,6 +210,47 @@ export const CommandMap = { }, }), + roomavatar: new Command({ + name: 'roomavatar', + args: '', + 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({ name: 'tint', args: ' []', From 5cb0a81565385b33c34d9472ed355bbafa49e2b4 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Fri, 10 May 2019 20:28:28 +0100 Subject: [PATCH 2/3] Change roomavatar to myroomavatar and roomnick to match, leaving alias Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --- src/SlashCommands.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/SlashCommands.js b/src/SlashCommands.js index 8757f5108a..a1364efbe1 100644 --- a/src/SlashCommands.js +++ b/src/SlashCommands.js @@ -192,8 +192,8 @@ export const CommandMap = { }, }), - roomnick: new Command({ - name: 'roomnick', + myroomnick: new Command({ + name: 'myroomnick', args: '', description: _td('Changes your display nickname in the current room only'), runFn: function(roomId, args) { @@ -210,9 +210,9 @@ export const CommandMap = { }, }), - roomavatar: new Command({ - name: 'roomavatar', - args: '', + myroomavatar: new Command({ + name: 'myroomavatar', + args: '[]', description: _td('Changes your avatar in this current room only'), runFn: function(roomId, args) { const cli = MatrixClientPeg.get(); @@ -770,6 +770,7 @@ const aliases = { j: "join", newballsplease: "discardsession", goto: "join", // because it handles event permalinks magically + roomnick: "myroomnick", }; From d9b03b019676575ae32ecebeda77888af83a17c3 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Sun, 12 May 2019 16:42:13 +0100 Subject: [PATCH 3/3] fix i18n Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --- src/i18n/strings/en_EN.json | 1 + 1 file changed, 1 insertion(+) diff --git a/src/i18n/strings/en_EN.json b/src/i18n/strings/en_EN.json index eaea057b36..5b28cd2e7a 100644 --- a/src/i18n/strings/en_EN.json +++ b/src/i18n/strings/en_EN.json @@ -146,6 +146,7 @@ "Upgrade": "Upgrade", "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 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", "Gets or sets the room topic": "Gets or sets the room topic", "This room has no topic.": "This room has no topic.",