11/*
22Copyright 2015, 2016 OpenMarket Ltd
3+ Copyright 2017 Vector Creations Ltd
4+ Copyright 2017 New Vector Ltd
35
46Licensed under the Apache License, Version 2.0 (the "License");
57you may not use this file except in compliance with the License.
@@ -14,8 +16,6 @@ See the License for the specific language governing permissions and
1416limitations under the License.
1517*/
1618
17- 'use strict' ;
18-
1919import React from 'react' ;
2020import { _t } from 'matrix-react-sdk/lib/languageHandler' ;
2121import sdk from 'matrix-react-sdk' ;
@@ -26,26 +26,31 @@ import Analytics from 'matrix-react-sdk/lib/Analytics';
2626import rate_limited_func from 'matrix-react-sdk/lib/ratelimitedfunc' ;
2727import Modal from 'matrix-react-sdk/lib/Modal' ;
2828import AccessibleButton from 'matrix-react-sdk/lib/components/views/elements/AccessibleButton' ;
29+ import { showGroupInviteDialog } from 'matrix-react-sdk/lib/GroupInvite' ;
2930
3031module . exports = React . createClass ( {
3132 displayName : 'RightPanel' ,
3233
3334 propTypes : {
34- // TODO: This should not be a prop, it should be received from the RoomViewStore
35+ // TODO: We're trying to move away from these being props, but we need to know
36+ // whether we should be displaying a room or group member list
3537 roomId : React . PropTypes . string , // if showing panels for a given room, this is set
38+ groupId : React . PropTypes . string , // if showing panels for a given group, this is set
3639 collapsed : React . PropTypes . bool , // currently unused property to request for a minimized view of the panel
3740 } ,
3841
3942 Phase : {
40- MemberList : 'MemberList' ,
43+ RoomMemberList : 'RoomMemberList' ,
44+ GroupMemberList : 'GroupMemberList' ,
4145 FilePanel : 'FilePanel' ,
4246 NotificationPanel : 'NotificationPanel' ,
43- MemberInfo : 'MemberInfo' ,
47+ RoomMemberInfo : 'RoomMemberInfo' ,
48+ GroupMemberInfo : 'GroupMemberInfo' ,
4449 } ,
4550
4651 componentWillMount : function ( ) {
4752 this . dispatcherRef = dis . register ( this . onAction ) ;
48- var cli = MatrixClientPeg . get ( ) ;
53+ const cli = MatrixClientPeg . get ( ) ;
4954 cli . on ( "RoomState.members" , this . onRoomStateMember ) ;
5055 } ,
5156
@@ -57,14 +62,20 @@ module.exports = React.createClass({
5762 } ,
5863
5964 getInitialState : function ( ) {
60- return {
61- phase : this . Phase . MemberList
62- } ;
65+ if ( this . props . groupId ) {
66+ return {
67+ phase : this . Phase . GroupMemberList ,
68+ } ;
69+ } else {
70+ return {
71+ phase : this . Phase . RoomMemberList ,
72+ } ;
73+ }
6374 } ,
6475
6576 onMemberListButtonClick : function ( ) {
6677 Analytics . trackEvent ( 'Right Panel' , 'Member List Button' , 'click' ) ;
67- this . setState ( { phase : this . Phase . MemberList } ) ;
78+ this . setState ( { phase : this . Phase . RoomMemberList } ) ;
6879 } ,
6980
7081 onFileListButtonClick : function ( ) {
@@ -89,19 +100,23 @@ module.exports = React.createClass({
89100 return ;
90101 }
91102
92- // call ChatInviteDialog
93- dis . dispatch ( {
94- action : 'view_invite' ,
95- roomId : this . props . roomId ,
96- } ) ;
103+ if ( this . state . phase === this . Phase . GroupMemberList ) {
104+ showGroupInviteDialog ( this . props . groupId ) ;
105+ } else {
106+ // call UserPickerDialog
107+ dis . dispatch ( {
108+ action : 'view_invite' ,
109+ roomId : this . props . roomId ,
110+ } ) ;
111+ }
97112 } ,
98113
99114 onRoomStateMember : function ( ev , state , member ) {
100115 // redraw the badge on the membership list
101- if ( this . state . phase == this . Phase . MemberList && member . roomId === this . props . roomId ) {
116+ if ( this . state . phase == this . Phase . RoomMemberList && member . roomId === this . props . roomId ) {
102117 this . _delayedUpdate ( ) ;
103118 }
104- else if ( this . state . phase === this . Phase . MemberInfo && member . roomId === this . props . roomId &&
119+ else if ( this . state . phase === this . Phase . RoomMemberInfo && member . roomId === this . props . roomId &&
105120 member . userId === this . state . member . userId ) {
106121 // refresh the member info (e.g. new power level)
107122 this . _delayedUpdate ( ) ;
@@ -119,39 +134,55 @@ module.exports = React.createClass({
119134 } ) ;
120135 if ( payload . member ) {
121136 this . setState ( {
122- phase : this . Phase . MemberInfo ,
137+ phase : this . Phase . RoomMemberInfo ,
123138 member : payload . member ,
124139 } ) ;
140+ } else {
141+ if ( this . props . roomId ) {
142+ this . setState ( {
143+ phase : this . Phase . RoomMemberList
144+ } ) ;
145+ } else if ( this . props . groupId ) {
146+ this . setState ( {
147+ phase : this . Phase . GroupMemberList ,
148+ groupId : payload . groupId ,
149+ member : payload . member ,
150+ } ) ;
151+ }
125152 }
126- else {
127- this . setState ( {
128- phase : this . Phase . MemberList
129- } ) ;
130- }
131- }
132- else if ( payload . action === "view_room" ) {
133- if ( this . state . phase === this . Phase . MemberInfo ) {
134- this . setState ( {
135- phase : this . Phase . MemberList
136- } ) ;
137- }
153+ } else if ( payload . action === "view_group" ) {
154+ this . setState ( {
155+ phase : this . Phase . GroupMemberList ,
156+ groupId : payload . groupId ,
157+ member : null ,
158+ } ) ;
159+ } else if ( payload . action === "view_group_user" ) {
160+ this . setState ( {
161+ phase : this . Phase . GroupMemberInfo ,
162+ groupId : payload . groupId ,
163+ member : payload . member ,
164+ } ) ;
165+ } else if ( payload . action === "view_room" ) {
166+ this . setState ( {
167+ phase : this . Phase . RoomMemberList
168+ } ) ;
138169 }
139170 } ,
140171
141172 render : function ( ) {
142- var MemberList = sdk . getComponent ( 'rooms.MemberList' ) ;
143- var NotificationPanel = sdk . getComponent ( 'structures.NotificationPanel ' ) ;
144- var FilePanel = sdk . getComponent ( 'structures.FilePanel ' ) ;
145- var TintableSvg = sdk . getComponent ( "elements.TintableSvg" ) ;
146- var buttonGroup ;
147- var inviteGroup ;
148- var panel ;
149-
150- var filesHighlight ;
151- var membersHighlight ;
152- var notificationsHighlight ;
173+ const MemberList = sdk . getComponent ( 'rooms.MemberList' ) ;
174+ const GroupMemberList = sdk . getComponent ( 'groups.GroupMemberList ' ) ;
175+ const NotificationPanel = sdk . getComponent ( 'structures.NotificationPanel ' ) ;
176+ const FilePanel = sdk . getComponent ( 'structures.FilePanel' ) ;
177+ const TintableSvg = sdk . getComponent ( "elements.TintableSvg" ) ;
178+ let inviteGroup ;
179+ let panel ;
180+
181+ let filesHighlight ;
182+ let membersHighlight ;
183+ let notificationsHighlight ;
153184 if ( ! this . props . collapsed ) {
154- if ( this . state . phase == this . Phase . MemberList || this . state . phase === this . Phase . MemberInfo ) {
185+ if ( this . state . phase == this . Phase . RoomMemberList || this . state . phase === this . Phase . RoomMemberInfo ) {
155186 membersHighlight = < div className = "mx_RightPanel_headerButton_highlight" > </ div > ;
156187 }
157188 else if ( this . state . phase == this . Phase . FilePanel ) {
@@ -162,11 +193,11 @@ module.exports = React.createClass({
162193 }
163194 }
164195
165- var membersBadge ;
166- if ( ( this . state . phase == this . Phase . MemberList || this . state . phase === this . Phase . MemberInfo ) && this . props . roomId ) {
167- var cli = MatrixClientPeg . get ( ) ;
168- var room = cli . getRoom ( this . props . roomId ) ;
169- var user_is_in_room ;
196+ let membersBadge ;
197+ if ( ( this . state . phase == this . Phase . RoomMemberList || this . state . phase === this . Phase . RoomMemberInfo ) && this . props . roomId ) {
198+ const cli = MatrixClientPeg . get ( ) ;
199+ const room = cli . getRoom ( this . props . roomId ) ;
200+ let user_is_in_room ;
170201 if ( room ) {
171202 membersBadge = room . getJoinedMembers ( ) . length ;
172203 user_is_in_room = room . hasMembershipState (
@@ -186,64 +217,90 @@ module.exports = React.createClass({
186217
187218 }
188219
220+ let headerButtons = [ ] ;
189221 if ( this . props . roomId ) {
190- buttonGroup =
191- < div className = "mx_RightPanel_headerButtonGroup" >
192- < AccessibleButton className = "mx_RightPanel_headerButton"
193- title = { _t ( 'Members' ) } onClick = { this . onMemberListButtonClick } >
194- < div className = "mx_RightPanel_headerButton_badge" > { membersBadge ? membersBadge : < span > </ span > } </ div >
195- < TintableSvg src = "img/icons-people.svg" width = "25" height = "25" />
196- { membersHighlight }
197- </ AccessibleButton >
198- < AccessibleButton
199- className = "mx_RightPanel_headerButton mx_RightPanel_filebutton"
200- title = { _t ( 'Files' ) } onClick = { this . onFileListButtonClick } >
201- < div className = "mx_RightPanel_headerButton_badge" > </ div >
202- < TintableSvg src = "img/icons-files.svg" width = "25" height = "25" />
203- { filesHighlight }
204- </ AccessibleButton >
205- < AccessibleButton
206- className = "mx_RightPanel_headerButton mx_RightPanel_notificationbutton"
207- title = { _t ( 'Notifications' ) } onClick = { this . onNotificationListButtonClick } >
208- < div className = "mx_RightPanel_headerButton_badge" > </ div >
209- < TintableSvg src = "img/icons-notifications.svg" width = "25" height = "25" />
210- { notificationsHighlight }
211- </ AccessibleButton >
212- < div className = "mx_RightPanel_headerButton mx_RightPanel_collapsebutton" title = { _t ( "Hide panel" ) } onClick = { this . onCollapseClick } >
213- < TintableSvg src = "img/minimise.svg" width = "10" height = "16" />
214- </ div >
215- </ div > ;
222+ headerButtons . push (
223+ < AccessibleButton className = "mx_RightPanel_headerButton" key = "_membersButton"
224+ title = { _t ( 'Members' ) } onClick = { this . onMemberListButtonClick } >
225+ < div className = "mx_RightPanel_headerButton_badge" > { membersBadge ? membersBadge : < span > </ span > } </ div >
226+ < TintableSvg src = "img/icons-people.svg" width = "25" height = "25" />
227+ { membersHighlight }
228+ </ AccessibleButton >
229+ ) ;
230+ headerButtons . push (
231+ < AccessibleButton
232+ className = "mx_RightPanel_headerButton mx_RightPanel_filebutton" key = "_filesButton"
233+ title = { _t ( 'Files' ) } onClick = { this . onFileListButtonClick } >
234+ < div className = "mx_RightPanel_headerButton_badge" > </ div >
235+ < TintableSvg src = "img/icons-files.svg" width = "25" height = "25" />
236+ { filesHighlight }
237+ </ AccessibleButton >
238+ ) ;
239+ headerButtons . push (
240+ < AccessibleButton
241+ className = "mx_RightPanel_headerButton mx_RightPanel_notificationbutton" key = "_notifsButton"
242+ title = { _t ( 'Notifications' ) } onClick = { this . onNotificationListButtonClick } >
243+ < div className = "mx_RightPanel_headerButton_badge" > </ div >
244+ < TintableSvg src = "img/icons-notifications.svg" width = "25" height = "25" />
245+ { notificationsHighlight }
246+ </ AccessibleButton >
247+ ) ;
248+ }
249+
250+ if ( this . props . roomId || this . props . groupId ) {
251+ // Hiding the right panel hides it completely and relies on an 'expand' button
252+ // being put in the RoomHeader or GroupView header, so only show the minimise
253+ // button on these 2 screens or you won't be able to re-expand the panel.
254+ headerButtons . push (
255+ < div className = "mx_RightPanel_headerButton mx_RightPanel_collapsebutton" key = "_minimizeButton"
256+ title = { _t ( "Hide panel" ) } onClick = { this . onCollapseClick }
257+ >
258+ < TintableSvg src = "img/minimise.svg" width = "10" height = "16" />
259+ </ div >
260+ ) ;
216261 }
217262
218263 if ( ! this . props . collapsed ) {
219- if ( this . props . roomId && this . state . phase == this . Phase . MemberList ) {
264+ if ( this . props . roomId && this . state . phase == this . Phase . RoomMemberList ) {
220265 panel = < MemberList roomId = { this . props . roomId } key = { this . props . roomId } />
221- }
222- else if ( this . state . phase == this . Phase . MemberInfo ) {
223- var MemberInfo = sdk . getComponent ( 'rooms.MemberInfo' ) ;
266+ } else if ( this . props . groupId && this . state . phase == this . Phase . GroupMemberList ) {
267+ panel = < GroupMemberList groupId = { this . props . groupId } key = { this . props . groupId } /> ;
268+ inviteGroup = (
269+ < AccessibleButton className = "mx_RightPanel_invite" onClick = { this . onInviteButtonClick } >
270+ < div className = "mx_RightPanel_icon" >
271+ < TintableSvg src = "img/icon-invite-people.svg" width = "35" height = "35" />
272+ </ div >
273+ < div className = "mx_RightPanel_message" > { _t ( 'Invite to this group' ) } </ div >
274+ </ AccessibleButton >
275+ ) ;
276+ } else if ( this . state . phase == this . Phase . RoomMemberInfo ) {
277+ const MemberInfo = sdk . getComponent ( 'rooms.MemberInfo' ) ;
224278 panel = < MemberInfo member = { this . state . member } key = { this . props . roomId || this . state . member . userId } />
225- }
226- else if ( this . state . phase == this . Phase . NotificationPanel ) {
227- panel = < NotificationPanel />
228- }
229- else if ( this . state . phase == this . Phase . FilePanel ) {
230- panel = < FilePanel roomId = { this . props . roomId } />
279+ } else if ( this . state . phase == this . Phase . GroupMemberInfo ) {
280+ const GroupMemberInfo = sdk . getComponent ( 'groups.GroupMemberInfo' ) ;
281+ panel = < GroupMemberInfo groupMember = { this . state . member } groupId = { this . props . groupId } key = { this . state . member . user_id } /> ;
282+ } else if ( this . state . phase == this . Phase . NotificationPanel ) {
283+ panel = < NotificationPanel /> ;
284+ } else if ( this . state . phase == this . Phase . FilePanel ) {
285+ panel = < FilePanel roomId = { this . props . roomId } /> ;
231286 }
232287 }
233288
234289 if ( ! panel ) {
235290 panel = < div className = "mx_RightPanel_blank" > </ div > ;
236291 }
237292
238- var classes = "mx_RightPanel mx_fadable" ;
293+ let classes = "mx_RightPanel mx_fadable" ;
239294 if ( this . props . collapsed ) {
240295 classes += " collapsed" ;
241296 }
242297
243298 return (
244299 < aside className = { classes } style = { { opacity : this . props . opacity } } >
245300 < div className = "mx_RightPanel_header" >
246- { buttonGroup }
301+ < div className = "mx_RightPanel_headerButtonGroup" >
302+ { headerButtons }
303+ </ div >
247304 </ div >
248305 { panel }
249306 < div className = "mx_RightPanel_footer" >
0 commit comments