11/*
22Copyright 2015, 2016 OpenMarket Ltd
33Copyright 2018 New Vector Ltd
4+ Copyright 2019 Michael Telatynski <7t3chguy@gmail.com>
45
56Licensed under the Apache License, Version 2.0 (the "License");
67you may not use this file except in compliance with the License.
@@ -31,6 +32,7 @@ import { linkifyAndSanitizeHtml } from './HtmlUtils';
3132import QuestionDialog from "./components/views/dialogs/QuestionDialog" ;
3233import WidgetUtils from "./utils/WidgetUtils" ;
3334import { textToHtmlRainbow } from "./utils/colour" ;
35+ import Promise from "bluebird" ;
3436
3537class 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
0 commit comments