33 title =" Add a Room"
44 ref =" modal"
55 :ok-title =" type === 'n' ? 'Create' : 'Join'"
6- :busy =" adding_room"
7- :no-close-on-backdrop =" adding_room"
8- :no-close-on-esc =" adding_room"
6+ :ok-disabled =" !can_submit"
7+ :busy =" !can_edit"
8+ :no-close-on-backdrop =" !can_edit"
9+ :no-close-on-esc =" !can_edit"
910 @ok =" handleOk"
1011 >
1112 <AlertSection ref =" alerts" />
1617 <b-form-input
1718 id =" name-input"
1819 v-model =" form.name"
19- :disabled =" adding_room "
20+ :disabled =" !can_edit "
2021 placeholder =" Room Name (optional)"
2122 />
2223 </b-form-group >
2324 </b-tab >
2425 <b-tab title =" Join a room" ></b-tab >
2526 </b-tabs >
26- <b-form-group label-for =" alias -input" >
27+ <b-form-group label-for =" room -input" >
2728 <b-input-group prepend =" #" >
2829 <b-form-input
29- id =" alias -input"
30- aria-describedby =" alias -live-feedback"
31- v-model =" form.alias "
32- :disabled =" adding_room "
30+ id =" room -input"
31+ aria-describedby =" room -live-feedback"
32+ v-model =" form.room "
33+ :disabled =" !can_edit "
3334 :required =" type === 'j'"
34- :state =" alias_valid"
35- :placeholder =" type === 'n' ? 'Room Alias (optional)' : 'Room Alias'"
35+ :state =" room_valid"
36+ :placeholder ="
37+ type === 'n' ? 'Room Alias (optional)' : 'Room Alias or ID'
38+ "
3639 />
37- <b-form-invalid-feedback id =" alias-live-feedback" >
38- Enter just the localpart of the alias.
40+ <b-form-invalid-feedback id =" room-live-feedback" >
41+ <template v-if =" type === ' n' " >
42+ Enter just the localpart of the alias to create.
43+ </template >
44+ <template v-if =" type === ' j' " >
45+ Enter both the localpart and server name with the # or ! (ex.
46+ #matrix:matrix.org)
47+ </template >
3948 </b-form-invalid-feedback >
4049 </b-input-group >
4150 </b-form-group >
4655<script >
4756import { debug } from ' @/plugins/debug'
4857import AlertSection from ' @/components/AlertSection'
58+ import { matrix_typed_state , plaintext } from ' @/plugins/matrix.js'
4959
5060export default {
5161 components: { AlertSection },
5262 data () {
5363 return {
5464 form: {
55- alias : ' ' ,
65+ room : ' ' ,
5666 name: ' ' ,
5767 tab: 0
5868 },
@@ -65,11 +75,24 @@ export default {
6575 type () {
6676 return this .form .tab === 0 ? ' n' : ' j'
6777 },
68- alias_valid () {
69- const res = / ^ [^ #:] * $ / gm .exec (this .form .alias )
70- return this .form .alias .length || this .type === ' j'
71- ? (res && res .index === 0 ) || false
72- : undefined
78+ room_valid () {
79+ if (this .type === ' n' ) {
80+ const res = / ^ [^ !#:] * $ / gm .exec (this .form .room )
81+ return res && res .index === 0 ? undefined : false
82+ } else if (this .type === ' j' ) {
83+ const res = / ^ [!#][^ !#:] + :[a-zA-Z0-9 -. ] + (:[0-9 ] + )? $ / gm .exec (
84+ this .form .room
85+ )
86+ return res && res .index === 0 ? undefined : false
87+ }
88+ return false
89+ },
90+ can_submit () {
91+ // BS has a really weird way of validating forms
92+ return this .room_valid !== false && ! this .adding_room
93+ },
94+ can_edit () {
95+ return ! this .adding_room
7396 }
7497 },
7598
@@ -86,15 +109,25 @@ export default {
86109 return
87110 }
88111
89- const alias = values .alias .trim ()
112+ const room = values .room .trim ()
90113 const name = values .name
91114 this .adding_room = true
92115 if (this .type === ' n' ) {
93116 this .$matrix .client
94117 .createRoom ({
95- room_alias_name: alias !== ' ' ? alias : undefined ,
118+ room_alias_name: room !== ' ' ? room : undefined ,
96119 name: name !== ' ' ? name : undefined
97120 })
121+ .then ((data ) =>
122+ this .$matrix .client
123+ .sendStateEvent (
124+ data .room_id ,
125+ matrix_typed_state,
126+ { type: plaintext },
127+ ' '
128+ )
129+ .then (() => data)
130+ )
98131 .then (
99132 ({ room_id }) => {
100133 if (room_id) {
@@ -115,12 +148,12 @@ export default {
115148 })
116149 } else if (this .type === ' j' ) {
117150 this .$matrix .client
118- .joinRoom (values .room , { syncRoom: false })
151+ .joinRoom (` ${ values .room } ` , { syncRoom: false })
119152 .then (
120153 ({ roomId }) => {
121- if (roomId) {
154+ /* if (roomId) {
122155 this.$router.replace('/edit/' + encodeURIComponent(roomId))
123- }
156+ } */
124157 this .hide ()
125158 },
126159 (e ) => {
@@ -139,10 +172,7 @@ export default {
139172
140173 handleOk (e ) {
141174 e .preventDefault ()
142- if (
143- this .alias_valid === false ||
144- (! this .alias_valid && this .type === ' j' )
145- ) {
175+ if (! this .can_submit ) {
146176 return
147177 }
148178 this .onFormSubmit (this .form )
0 commit comments