File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -18,6 +18,7 @@ limitations under the License.
1818
1919var MatrixClientPeg = require ( "./MatrixClientPeg" ) ;
2020var dis = require ( "./dispatcher" ) ;
21+ var encryption = require ( "./encryption" ) ;
2122
2223var reject = function ( msg ) {
2324 return {
@@ -42,6 +43,25 @@ var commands = {
4243 return reject ( "Usage: /nick <display_name>" ) ;
4344 } ,
4445
46+ encrypt : function ( room_id , args ) {
47+ if ( args == "on" ) {
48+ var client = MatrixClientPeg . get ( ) ;
49+ var members = client . getRoom ( room_id ) . currentState . members ;
50+ var user_ids = Object . keys ( members ) ;
51+ return success (
52+ encryption . enableEncryption ( client , room_id , user_ids )
53+ ) ;
54+ }
55+ if ( args == "off" ) {
56+ var client = MatrixClientPeg . get ( ) ;
57+ return success (
58+ encryption . disableEncryption ( client , room_id )
59+ ) ;
60+
61+ }
62+ return reject ( "Usage: encrypt <on/off>" ) ;
63+ } ,
64+
4565 // Change the room topic
4666 topic : function ( room_id , args ) {
4767 if ( args ) {
@@ -234,4 +254,4 @@ module.exports = {
234254 }
235255 return null ; // not a command
236256 }
237- } ;
257+ } ;
Original file line number Diff line number Diff line change @@ -20,6 +20,7 @@ var React = require("react");
2020var MatrixClientPeg = require ( "../../MatrixClientPeg" ) ;
2121var PresetValues = require ( '../atoms/create_room/Presets' ) . Presets ;
2222var q = require ( 'q' ) ;
23+ var encryption = require ( "../../encryption" ) ;
2324
2425module . exports = {
2526 propTypes : {
@@ -103,22 +104,14 @@ module.exports = {
103104 var response ;
104105
105106 if ( this . state . encrypt ) {
106- var deferred = deferred . then ( function ( res ) {
107+ deferred = deferred . then ( function ( res ) {
107108 response = res ;
108- return cli . downloadKeys ( [ cli . credentials . userId ] ) ;
109- } ) . then ( function ( res ) {
110- // TODO: Check the keys are valid.
111- return cli . downloadKeys ( options . invite ) ;
112- } ) . then ( function ( res ) {
113- return cli . setRoomEncryption ( response . room_id , {
114- algorithm : "m.olm.v1.curve25519-aes-sha2" ,
115- members : options . invite ,
116- } ) ;
117- } ) . then ( function ( res ) {
118- var d = q . defer ( ) ;
119- d . resolve ( response ) ;
120- return d . promise ;
121- } ) ;
109+ return encryption . enableEncryption (
110+ cli , response . roomId , options . invite
111+ ) ;
112+ } ) . then ( function ( ) {
113+ return q ( response ) }
114+ ) ;
122115 }
123116
124117 this . setState ( {
You can’t perform that action at this time.
0 commit comments