Skip to content

Commit 5ad860f

Browse files
author
Weblate
committed
Merge remote-tracking branch 'origin/develop' into develop
2 parents aa6e687 + 828e9d5 commit 5ad860f

4 files changed

Lines changed: 306 additions & 0 deletions

File tree

Lines changed: 276 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,276 @@
1+
/*
2+
Copyright 2017 Michael Telatynski <7t3chguy@gmail.com>
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
import React from 'react';
18+
import sdk from 'matrix-react-sdk';
19+
import { _t } from 'matrix-react-sdk/lib/languageHandler';
20+
import MatrixClientPeg from 'matrix-react-sdk/lib/MatrixClientPeg';
21+
22+
class SendCustomEvent extends React.Component {
23+
static propTypes = {
24+
roomId: React.PropTypes.string.isRequired,
25+
onBack: React.PropTypes.func.isRequired,
26+
};
27+
28+
constructor(props, context) {
29+
super(props, context);
30+
this._send = this._send.bind(this);
31+
this.onBack = this.onBack.bind(this);
32+
}
33+
34+
state = {
35+
message: null,
36+
};
37+
38+
onBack() {
39+
if (this.state.message) {
40+
this.setState({ message: null });
41+
} else {
42+
this.props.onBack();
43+
}
44+
}
45+
46+
_buttons() {
47+
return <div className="mx_Dialog_buttons">
48+
<button onClick={this.onBack}>{ _t('Back') }</button>
49+
{!this.state.message && <button onClick={this._send}>{ _t('Send') }</button>}
50+
</div>;
51+
}
52+
53+
send(content) {
54+
return MatrixClientPeg.get().sendEvent(this.props.roomId, this.refs.eventType.value, content);
55+
}
56+
57+
async _send() {
58+
let message;
59+
try {
60+
const content = JSON.parse(this.refs.evContent.value);
61+
await this.send(content);
62+
message = _t('Event sent!');
63+
} catch (e) {
64+
message = _t('Failed to send custom event.') + ' (' + e.toString() + ')';
65+
}
66+
this.setState({ message });
67+
}
68+
69+
_additionalFields() {
70+
return <div></div>;
71+
}
72+
73+
render() {
74+
if (this.state.message) {
75+
return <div>
76+
<div className="mx_Dialog_content">
77+
{this.state.message}
78+
</div>
79+
{this._buttons()}
80+
</div>;
81+
}
82+
83+
return <div>
84+
<div className="mx_Dialog_content">
85+
{this._additionalFields()}
86+
<div className="mx_TextInputDialog_label">
87+
<label htmlFor="eventType"> { _t('Event Type') } </label>
88+
</div>
89+
<div>
90+
<input id="eventType" ref="eventType" className="mx_TextInputDialog_input" size="64" />
91+
</div>
92+
93+
<div className="mx_TextInputDialog_label">
94+
<label htmlFor="evContent"> { _t('Event Content') } </label>
95+
</div>
96+
<div>
97+
<textarea id="evContent" ref="evContent" className="mx_TextInputDialog_input" defaultValue={"{\n\n}"} cols="63" rows="5" />
98+
</div>
99+
</div>
100+
{this._buttons()}
101+
</div>;
102+
}
103+
}
104+
105+
class SendCustomStateEvent extends SendCustomEvent {
106+
send(content) {
107+
return MatrixClientPeg.get().sendStateEvent(this.props.roomId, this.refs.eventType.value, content,
108+
this.refs.stateKey.value);
109+
}
110+
111+
_additionalFields() {
112+
return <div>
113+
<div className="mx_TextInputDialog_label">
114+
<label htmlFor="stateKey"> { _t('State Key') } </label>
115+
</div>
116+
<div>
117+
<input id="stateKey" ref="stateKey" className="mx_TextInputDialog_input" size="64" />
118+
</div>
119+
</div>;
120+
}
121+
}
122+
123+
class RoomStateExplorer extends React.Component {
124+
static propTypes = {
125+
roomId: React.PropTypes.string.isRequired,
126+
onBack: React.PropTypes.func.isRequired,
127+
};
128+
129+
constructor(props, context) {
130+
super(props, context);
131+
132+
const room = MatrixClientPeg.get().getRoom(this.props.roomId);
133+
this.roomStateEvents = room.currentState.events;
134+
135+
this.onBack = this.onBack.bind(this);
136+
}
137+
138+
state = {
139+
eventType: null,
140+
event: null,
141+
};
142+
143+
browseEventType(eventType) {
144+
return () => {
145+
this.setState({ eventType });
146+
};
147+
}
148+
149+
onViewSourceClick(event) {
150+
return () => {
151+
this.setState({ event: event.event });
152+
};
153+
}
154+
155+
onBack() {
156+
if (this.state.event) {
157+
this.setState({ event: null });
158+
} else if (this.state.eventType) {
159+
this.setState({ eventType: null });
160+
} else {
161+
this.props.onBack();
162+
}
163+
}
164+
165+
render() {
166+
if (this.state.event) {
167+
return <div className="mx_ViewSource">
168+
<div className="mx_Dialog_content">
169+
<pre>{JSON.stringify(this.state.event, null, 2)}</pre>
170+
</div>
171+
<div className="mx_Dialog_buttons">
172+
<button onClick={this.onBack}>{ _t('Back') }</button>
173+
</div>
174+
</div>;
175+
}
176+
177+
const rows = [];
178+
179+
if (this.state.eventType === null) {
180+
Object.keys(this.roomStateEvents).forEach((evType) => {
181+
const stateGroup = this.roomStateEvents[evType];
182+
const stateKeys = Object.keys(stateGroup);
183+
184+
let onClickFn;
185+
if (stateKeys.length > 1) {
186+
onClickFn = this.browseEventType(evType);
187+
} else if (stateKeys.length === 1) {
188+
onClickFn = this.onViewSourceClick(stateGroup[stateKeys[0]]);
189+
}
190+
191+
rows.push(<button className="mx_DevTools_RoomStateExplorer_button" key={evType} onClick={onClickFn}>
192+
{ evType }
193+
</button>);
194+
});
195+
} else {
196+
const evType = this.state.eventType;
197+
const stateGroup = this.roomStateEvents[evType];
198+
Object.keys(stateGroup).forEach((stateKey) => {
199+
const ev = stateGroup[stateKey];
200+
rows.push(<button className="mx_DevTools_RoomStateExplorer_button" key={stateKey}
201+
onClick={this.onViewSourceClick(ev)}>
202+
{ stateKey }
203+
</button>);
204+
});
205+
}
206+
207+
return <div>
208+
<div className="mx_Dialog_content">
209+
{rows}
210+
</div>
211+
<div className="mx_Dialog_buttons">
212+
<button onClick={this.onBack}>{ _t('Back') }</button>
213+
</div>
214+
</div>;
215+
}
216+
}
217+
218+
export default class DevtoolsDialog extends React.Component {
219+
static propTypes = {
220+
roomId: React.PropTypes.string.isRequired,
221+
onFinished: React.PropTypes.func.isRequired,
222+
};
223+
224+
state = {
225+
mode: null,
226+
};
227+
228+
constructor(props, context) {
229+
super(props, context);
230+
this.onBack = this.onBack.bind(this);
231+
this.onCancel = this.onCancel.bind(this);
232+
}
233+
234+
componentWillUnmount() {
235+
this._unmounted = true;
236+
}
237+
238+
_setMode(mode) {
239+
return () => {
240+
this.setState({ mode });
241+
};
242+
}
243+
244+
onBack() {
245+
this.setState({ mode: null });
246+
}
247+
248+
onCancel() {
249+
this.props.onFinished(false);
250+
}
251+
252+
render() {
253+
let body;
254+
255+
if (this.state.mode) {
256+
body = <this.state.mode {...this.props} onBack={this.onBack} />;
257+
} else {
258+
body = <div>
259+
<div className="mx_Dialog_content">
260+
<button onClick={this._setMode(SendCustomEvent)}>{ _t('Send Custom Event') }</button>
261+
<button onClick={this._setMode(SendCustomStateEvent)}>{ _t('Send Custom State Event') }</button>
262+
<button onClick={this._setMode(RoomStateExplorer)}>{ _t('Explore Room State') }</button>
263+
</div>
264+
<div className="mx_Dialog_buttons">
265+
<button onClick={this.onCancel}>{ _t('Cancel') }</button>
266+
</div>
267+
</div>;
268+
}
269+
270+
const BaseDialog = sdk.getComponent('views.dialogs.BaseDialog');
271+
return <BaseDialog className="mx_QuestionDialog" onFinished={this.props.onFinished} title={_t('Developer Tools')}>
272+
<div>Room ID: {this.props.roomId}</div>
273+
{ body }
274+
</BaseDialog>;
275+
}
276+
}

‎src/i18n/strings/en_EN.json‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"All Rooms": "All Rooms",
1010
"All notifications are currently disabled for all targets.": "All notifications are currently disabled for all targets.",
1111
"An error occurred whilst saving your email notification preferences.": "An error occurred whilst saving your email notification preferences.",
12+
"Back": "Back",
1213
"Bug report sent": "Bug report sent",
1314
"Call invitation": "Call invitation",
1415
"Cancel": "Cancel",
@@ -26,6 +27,7 @@
2627
"delete the alias.": "delete the alias.",
2728
"Delete the room alias %(alias)s and remove %(name)s from the directory?": "Delete the room alias %(alias)s and remove %(name)s from the directory?",
2829
"Describe your problem here.": "Describe your problem here.",
30+
"Developer Tools": "Developer Tools",
2931
"Direct Chat": "Direct Chat",
3032
"Directory": "Directory",
3133
"Dismiss": "Dismiss",
@@ -50,6 +52,7 @@
5052
"Failed to get public room list": "Failed to get public room list",
5153
"Failed to join the room": "Failed to join the room",
5254
"Failed to remove tag %(tagName)s from room": "Failed to remove tag %(tagName)s from room",
55+
"Failed to send custom event.": "Failed to send custom event.",
5356
"Failed to send report: ": "Failed to send report: ",
5457
"Failed to set direct chat tag": "Failed to set direct chat tag",
5558
"Failed to set Direct Message status of room": "Failed to set Direct Message status of room",
@@ -117,6 +120,9 @@
117120
"Search for a room": "Search for a room",
118121
"Send": "Send",
119122
"Send logs": "Send logs",
123+
"Send Custom Event": "Send Custom Event",
124+
"Send Custom State Event": "Send Custom State Event",
125+
"Explore Room State": "Explore Room State",
120126
"Settings": "Settings",
121127
"Source URL": "Source URL",
122128
"Sorry, your browser is <b>not</b> able to run Riot.": "Sorry, your browser is <b>not</b> able to run Riot.",
@@ -164,6 +170,10 @@
164170
"Warning": "Warning",
165171
"Checking for an update...": "Checking for an update...",
166172
"Error encountered (%(errorDetail)s).": "Error encountered (%(errorDetail)s).",
173+
"Event sent!": "Event sent!",
174+
"Event Type": "Event Type",
175+
"Event Content": "Event Content",
176+
"State Key": "State Key",
167177
"No update available.": "No update available.",
168178
"Downloading update...": "Downloading update...",
169179
"You need to be using HTTPS to place a screen-sharing call.": "You need to be using HTTPS to place a screen-sharing call.",

‎src/skins/vector/css/_components.scss‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@
7474
@import "./vector-web/views/context_menus/_MessageContextMenu.scss";
7575
@import "./vector-web/views/context_menus/_RoomTileContextMenu.scss";
7676
@import "./vector-web/views/dialogs/_ChangelogDialog.scss";
77+
@import "./vector-web/views/dialogs/_DevtoolsDialog.scss";
7778
@import "./vector-web/views/dialogs/_SetEmailDialog.scss";
7879
@import "./vector-web/views/dialogs/_SetPasswordDialog.scss";
7980
@import "./vector-web/views/directory/_NetworkDropdown.scss";
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/*
2+
Copyright 2017 Michael Telatynski <7t3chguy@gmail.com>
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
.mx_DevTools_RoomStateExplorer_button {
18+
margin-bottom: 10px;
19+
}

0 commit comments

Comments
 (0)