only listen and dispatch to room-local dispatcher in room view, composer

pull/21833/head
Bruno Windels 2018-11-22 15:15:24 +00:00
parent 9a24249fb5
commit 44200a6f78
3 changed files with 39 additions and 42 deletions

View File

@ -35,7 +35,6 @@ const ContentMessages = require("../../ContentMessages");
const Modal = require("../../Modal"); const Modal = require("../../Modal");
const sdk = require('../../index'); const sdk = require('../../index');
const CallHandler = require('../../CallHandler'); const CallHandler = require('../../CallHandler');
const dis = require("../../dispatcher");
const Tinter = require("../../Tinter"); const Tinter = require("../../Tinter");
const rate_limited_func = require('../../ratelimitedfunc'); const rate_limited_func = require('../../ratelimitedfunc');
const ObjectUtils = require('../../ObjectUtils'); const ObjectUtils = require('../../ObjectUtils');
@ -151,7 +150,7 @@ module.exports = React.createClass({
}, },
componentWillMount: function() { componentWillMount: function() {
this.dispatcherRef = dis.register(this.onAction); this.dispatcherRef = this.props.roomViewStore.getDispatcher().register(this.onAction);
MatrixClientPeg.get().on("Room", this.onRoom); MatrixClientPeg.get().on("Room", this.onRoom);
MatrixClientPeg.get().on("Room.timeline", this.onRoomTimeline); MatrixClientPeg.get().on("Room.timeline", this.onRoomTimeline);
MatrixClientPeg.get().on("Room.name", this.onRoomName); MatrixClientPeg.get().on("Room.name", this.onRoomName);
@ -200,7 +199,7 @@ module.exports = React.createClass({
editingRoomSettings: store.isEditingSettings(), editingRoomSettings: store.isEditingSettings(),
}; };
if (this.state.editingRoomSettings && !newState.editingRoomSettings) dis.dispatch({action: 'focus_composer'}); if (this.state.editingRoomSettings && !newState.editingRoomSettings) this.props.roomViewStore.getDispatcher().dispatch({action: 'focus_composer'});
// Temporary logging to diagnose https://github.com/vector-im/riot-web/issues/4307 // Temporary logging to diagnose https://github.com/vector-im/riot-web/issues/4307
console.log( console.log(
@ -362,7 +361,7 @@ module.exports = React.createClass({
// XXX: EVIL HACK to autofocus inviting on empty rooms. // XXX: EVIL HACK to autofocus inviting on empty rooms.
// We use the setTimeout to avoid racing with focus_composer. // We use the setTimeout to avoid racing with focus_composer.
if (this.state.room && if (this.props.isActive !== false && this.state.room &&
this.state.room.getJoinedMemberCount() == 1 && this.state.room.getJoinedMemberCount() == 1 &&
this.state.room.getLiveTimeline() && this.state.room.getLiveTimeline() &&
this.state.room.getLiveTimeline().getEvents() && this.state.room.getLiveTimeline().getEvents() &&
@ -416,7 +415,7 @@ module.exports = React.createClass({
roomView.removeEventListener('dragleave', this.onDragLeaveOrEnd); roomView.removeEventListener('dragleave', this.onDragLeaveOrEnd);
roomView.removeEventListener('dragend', this.onDragLeaveOrEnd); roomView.removeEventListener('dragend', this.onDragLeaveOrEnd);
} }
dis.unregister(this.dispatcherRef); this.props.roomViewStore.getDispatcher().unregister(this.dispatcherRef);
if (MatrixClientPeg.get()) { if (MatrixClientPeg.get()) {
MatrixClientPeg.get().removeListener("Room", this.onRoom); MatrixClientPeg.get().removeListener("Room", this.onRoom);
MatrixClientPeg.get().removeListener("Room.timeline", this.onRoomTimeline); MatrixClientPeg.get().removeListener("Room.timeline", this.onRoomTimeline);
@ -791,7 +790,7 @@ module.exports = React.createClass({
}, },
onSearchResultsResize: function() { onSearchResultsResize: function() {
dis.dispatch({ action: 'timeline_resize' }, true); this.props.roomViewStore.getDispatcher().dispatch({ action: 'timeline_resize' }, true);
}, },
onSearchResultsFillRequest: function(backwards) { onSearchResultsFillRequest: function(backwards) {
@ -812,7 +811,7 @@ module.exports = React.createClass({
onInviteButtonClick: function() { onInviteButtonClick: function() {
// call AddressPickerDialog // call AddressPickerDialog
dis.dispatch({ this.props.roomViewStore.getDispatcher().dispatch({
action: 'view_invite', action: 'view_invite',
roomId: this.state.room.roomId, roomId: this.state.room.roomId,
}); });
@ -834,7 +833,7 @@ module.exports = React.createClass({
// Join this room once the user has registered and logged in // Join this room once the user has registered and logged in
const signUrl = this.props.thirdPartyInvite ? const signUrl = this.props.thirdPartyInvite ?
this.props.thirdPartyInvite.inviteSignUrl : undefined; this.props.thirdPartyInvite.inviteSignUrl : undefined;
dis.dispatch({ this.props.roomViewStore.getDispatcher().dispatch({
action: 'do_after_sync_prepared', action: 'do_after_sync_prepared',
deferred_action: { deferred_action: {
action: 'join_room', action: 'join_room',
@ -844,7 +843,7 @@ module.exports = React.createClass({
// Don't peek whilst registering otherwise getPendingEventList complains // Don't peek whilst registering otherwise getPendingEventList complains
// Do this by indicating our intention to join // Do this by indicating our intention to join
dis.dispatch({ this.props.roomViewStore.getDispatcher().dispatch({
action: 'will_join', action: 'will_join',
}); });
@ -855,20 +854,20 @@ module.exports = React.createClass({
if (submitted) { if (submitted) {
this.props.onRegistered(credentials); this.props.onRegistered(credentials);
} else { } else {
dis.dispatch({ this.props.roomViewStore.getDispatcher().dispatch({
action: 'cancel_after_sync_prepared', action: 'cancel_after_sync_prepared',
}); });
dis.dispatch({ this.props.roomViewStore.getDispatcher().dispatch({
action: 'cancel_join', action: 'cancel_join',
}); });
} }
}, },
onDifferentServerClicked: (ev) => { onDifferentServerClicked: (ev) => {
dis.dispatch({action: 'start_registration'}); this.props.roomViewStore.getDispatcher().dispatch({action: 'start_registration'});
close(); close();
}, },
onLoginClick: (ev) => { onLoginClick: (ev) => {
dis.dispatch({action: 'start_login'}); this.props.roomViewStore.getDispatcher().dispatch({action: 'start_login'});
close(); close();
}, },
}).close; }).close;
@ -878,7 +877,7 @@ module.exports = React.createClass({
Promise.resolve().then(() => { Promise.resolve().then(() => {
const signUrl = this.props.thirdPartyInvite ? const signUrl = this.props.thirdPartyInvite ?
this.props.thirdPartyInvite.inviteSignUrl : undefined; this.props.thirdPartyInvite.inviteSignUrl : undefined;
dis.dispatch({ this.props.roomViewStore.getDispatcher().dispatch({
action: 'join_room', action: 'join_room',
opts: { inviteSignUrl: signUrl, viaServers: this.props.viaServers }, opts: { inviteSignUrl: signUrl, viaServers: this.props.viaServers },
}); });
@ -934,10 +933,10 @@ module.exports = React.createClass({
}, },
uploadFile: async function(file) { uploadFile: async function(file) {
dis.dispatch({action: 'focus_composer'}); this.props.roomViewStore.getDispatcher().dispatch({action: 'focus_composer'});
if (MatrixClientPeg.get().isGuest()) { if (MatrixClientPeg.get().isGuest()) {
dis.dispatch({action: 'require_registration'}); this.props.roomViewStore.getDispatcher().dispatch({action: 'require_registration'});
return; return;
} }
@ -961,14 +960,14 @@ module.exports = React.createClass({
} }
// Send message_sent callback, for things like _checkIfAlone because after all a file is still a message. // Send message_sent callback, for things like _checkIfAlone because after all a file is still a message.
dis.dispatch({ this.props.roomViewStore.getDispatcher().dispatch({
action: 'message_sent', action: 'message_sent',
}); });
}, },
injectSticker: function(url, info, text) { injectSticker: function(url, info, text) {
if (MatrixClientPeg.get().isGuest()) { if (MatrixClientPeg.get().isGuest()) {
dis.dispatch({action: 'require_registration'}); this.props.roomViewStore.getDispatcher().dispatch({action: 'require_registration'});
return; return;
} }
@ -1169,7 +1168,7 @@ module.exports = React.createClass({
}, },
onSettingsClick: function() { onSettingsClick: function() {
dis.dispatch({ action: 'open_room_settings' }); this.props.roomViewStore.getDispatcher().dispatch({ action: 'open_room_settings' });
}, },
onSettingsSaveClick: function() { onSettingsSaveClick: function() {
@ -1202,31 +1201,31 @@ module.exports = React.createClass({
}); });
// still editing room settings // still editing room settings
} else { } else {
dis.dispatch({ action: 'close_settings' }); this.props.roomViewStore.getDispatcher().dispatch({ action: 'close_settings' });
} }
}).finally(() => { }).finally(() => {
this.setState({ this.setState({
uploadingRoomSettings: false, uploadingRoomSettings: false,
}); });
dis.dispatch({ action: 'close_settings' }); this.props.roomViewStore.getDispatcher().dispatch({ action: 'close_settings' });
}).done(); }).done();
}, },
onCancelClick: function() { onCancelClick: function() {
console.log("updateTint from onCancelClick"); console.log("updateTint from onCancelClick");
this.updateTint(); this.updateTint();
dis.dispatch({ action: 'close_settings' }); this.props.roomViewStore.getDispatcher().dispatch({ action: 'close_settings' });
if (this.state.forwardingEvent) { if (this.state.forwardingEvent) {
dis.dispatch({ this.props.roomViewStore.getDispatcher().dispatch({
action: 'forward_event', action: 'forward_event',
event: null, event: null,
}); });
} }
dis.dispatch({action: 'focus_composer'}); this.props.roomViewStore.getDispatcher().dispatch({action: 'focus_composer'});
}, },
onLeaveClick: function() { onLeaveClick: function() {
dis.dispatch({ this.props.roomViewStore.getDispatcher().dispatch({
action: 'leave_room', action: 'leave_room',
room_id: this.state.room.roomId, room_id: this.state.room.roomId,
}); });
@ -1234,7 +1233,7 @@ module.exports = React.createClass({
onForgetClick: function() { onForgetClick: function() {
MatrixClientPeg.get().forget(this.state.room.roomId).done(function() { MatrixClientPeg.get().forget(this.state.room.roomId).done(function() {
dis.dispatch({ action: 'view_next_room' }); this.props.roomViewStore.getDispatcher().dispatch({ action: 'view_next_room' });
}, function(err) { }, function(err) {
const errCode = err.errcode || _t("unknown error code"); const errCode = err.errcode || _t("unknown error code");
const ErrorDialog = sdk.getComponent("dialogs.ErrorDialog"); const ErrorDialog = sdk.getComponent("dialogs.ErrorDialog");
@ -1251,7 +1250,7 @@ module.exports = React.createClass({
rejecting: true, rejecting: true,
}); });
MatrixClientPeg.get().leave(this.state.roomId).done(function() { MatrixClientPeg.get().leave(this.state.roomId).done(function() {
dis.dispatch({ action: 'view_next_room' }); this.props.roomViewStore.getDispatcher().dispatch({ action: 'view_next_room' });
self.setState({ self.setState({
rejecting: false, rejecting: false,
}); });
@ -1277,7 +1276,7 @@ module.exports = React.createClass({
// using /leave rather than /join. In the short term though, we // using /leave rather than /join. In the short term though, we
// just ignore them. // just ignore them.
// https://github.com/vector-im/vector-web/issues/1134 // https://github.com/vector-im/vector-web/issues/1134
dis.dispatch({ this.props.roomViewStore.getDispatcher().dispatch({
action: 'view_room_directory', action: 'view_room_directory',
}); });
}, },
@ -1296,7 +1295,7 @@ module.exports = React.createClass({
// jump down to the bottom of this room, where new events are arriving // jump down to the bottom of this room, where new events are arriving
jumpToLiveTimeline: function() { jumpToLiveTimeline: function() {
this.refs.messagePanel.jumpToLiveTimeline(); this.refs.messagePanel.jumpToLiveTimeline();
dis.dispatch({action: 'focus_composer'}); this.props.roomViewStore.getDispatcher().dispatch({action: 'focus_composer'});
}, },
// jump up to wherever our read marker is // jump up to wherever our read marker is
@ -1386,7 +1385,7 @@ module.exports = React.createClass({
}, },
onFullscreenClick: function() { onFullscreenClick: function() {
dis.dispatch({ this.props.roomViewStore.getDispatcher().dispatch({
action: 'video_fullscreen', action: 'video_fullscreen',
fullscreen: true, fullscreen: true,
}, true); }, true);

View File

@ -130,7 +130,7 @@ export default class MessageComposer extends React.Component {
onUploadClick(ev) { onUploadClick(ev) {
if (MatrixClientPeg.get().isGuest()) { if (MatrixClientPeg.get().isGuest()) {
dis.dispatch({action: 'require_registration'}); this.props.roomViewStore.getDispatcher().dispatch({action: 'require_registration'});
return; return;
} }
@ -192,7 +192,7 @@ export default class MessageComposer extends React.Component {
if (!call) { if (!call) {
return; return;
} }
dis.dispatch({ this.props.roomViewStore.getDispatcher().dispatch({
action: 'hangup', action: 'hangup',
// hangup the call for this room, which may not be the room in props // hangup the call for this room, which may not be the room in props
// (e.g. conferences which will hangup the 1:1 room instead) // (e.g. conferences which will hangup the 1:1 room instead)
@ -201,7 +201,7 @@ export default class MessageComposer extends React.Component {
} }
onCallClick(ev) { onCallClick(ev) {
dis.dispatch({ this.props.roomViewStore.getDispatcher().dispatch({
action: 'place_call', action: 'place_call',
type: ev.shiftKey ? "screensharing" : "video", type: ev.shiftKey ? "screensharing" : "video",
room_id: this.props.room.roomId, room_id: this.props.room.roomId,
@ -209,7 +209,7 @@ export default class MessageComposer extends React.Component {
} }
onVoiceCallClick(ev) { onVoiceCallClick(ev) {
dis.dispatch({ this.props.roomViewStore.getDispatcher().dispatch({
action: 'place_call', action: 'place_call',
type: "voice", type: "voice",
room_id: this.props.room.roomId, room_id: this.props.room.roomId,
@ -245,7 +245,7 @@ export default class MessageComposer extends React.Component {
ev.preventDefault(); ev.preventDefault();
const replacementRoomId = this.state.tombstone.getContent()['replacement_room']; const replacementRoomId = this.state.tombstone.getContent()['replacement_room'];
dis.dispatch({ this.props.roomViewStore.getDispatcher().dispatch({
action: 'view_room', action: 'view_room',
highlighted: true, highlighted: true,
room_id: replacementRoomId, room_id: replacementRoomId,

View File

@ -41,8 +41,6 @@ import sdk from '../../../index';
import { _t, _td } from '../../../languageHandler'; import { _t, _td } from '../../../languageHandler';
import Analytics from '../../../Analytics'; import Analytics from '../../../Analytics';
import dis from '../../../dispatcher';
import * as RichText from '../../../RichText'; import * as RichText from '../../../RichText';
import * as HtmlUtils from '../../../HtmlUtils'; import * as HtmlUtils from '../../../HtmlUtils';
import Autocomplete from './Autocomplete'; import Autocomplete from './Autocomplete';
@ -120,7 +118,7 @@ function onSendMessageFailed(err, room) {
// XXX: temporary logging to try to diagnose // XXX: temporary logging to try to diagnose
// https://github.com/vector-im/riot-web/issues/3148 // https://github.com/vector-im/riot-web/issues/3148
console.log('MessageComposer got send failure: ' + err.name + '('+err+')'); console.log('MessageComposer got send failure: ' + err.name + '('+err+')');
dis.dispatch({ this.props.roomViewStore.getDispatcher().dispatch({
action: 'message_send_failed', action: 'message_send_failed',
}); });
} }
@ -344,12 +342,12 @@ export default class MessageComposerInput extends React.Component {
} }
componentWillMount() { componentWillMount() {
this.dispatcherRef = dis.register(this.onAction); this.dispatcherRef = this.props.roomViewStore.getDispatcher().register(this.onAction);
this.historyManager = new ComposerHistoryManager(this.props.room.roomId, 'mx_slate_composer_history_'); this.historyManager = new ComposerHistoryManager(this.props.room.roomId, 'mx_slate_composer_history_');
} }
componentWillUnmount() { componentWillUnmount() {
dis.unregister(this.dispatcherRef); this.props.roomViewStore.getDispatcher().unregister(this.dispatcherRef);
} }
_collectEditor = (e) => { _collectEditor = (e) => {
@ -1208,14 +1206,14 @@ export default class MessageComposerInput extends React.Component {
// Clear reply_to_event as we put the message into the queue // Clear reply_to_event as we put the message into the queue
// if the send fails, retry will handle resending. // if the send fails, retry will handle resending.
dis.dispatch({ this.props.roomViewStore.getDispatcher().dispatch({
action: 'reply_to_event', action: 'reply_to_event',
event: null, event: null,
}); });
} }
this.client.sendMessage(this.props.room.roomId, content).then((res) => { this.client.sendMessage(this.props.room.roomId, content).then((res) => {
dis.dispatch({ this.props.roomViewStore.getDispatcher().dispatch({
action: 'message_sent', action: 'message_sent',
}); });
}).catch((e) => { }).catch((e) => {