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