Merge pull request #2898 from matrix-org/travis/upgrades/permalinks
Use dedicated permalink creators in search results with multiple rooms
This commit is contained in:
commit
26928a48e3
2 changed files with 34 additions and 12 deletions
|
@ -272,6 +272,28 @@ module.exports = React.createClass({
|
||||||
return this.state.room ? this.state.room.roomId : this.state.roomId;
|
return this.state.room ? this.state.room.roomId : this.state.roomId;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
_getPermalinkCreatorForRoom: function(room) {
|
||||||
|
if (!this._permalinkCreators) this._permalinkCreators = {};
|
||||||
|
if (this._permalinkCreators[room.roomId]) return this._permalinkCreators[room.roomId];
|
||||||
|
|
||||||
|
this._permalinkCreators[room.roomId] = new RoomPermalinkCreator(room);
|
||||||
|
if (this.state.room && room.roomId === this.state.room.roomId) {
|
||||||
|
// We want to watch for changes in the creator for the primary room in the view, but
|
||||||
|
// don't need to do so for search results.
|
||||||
|
this._permalinkCreators[room.roomId].start();
|
||||||
|
} else {
|
||||||
|
this._permalinkCreators[room.roomId].load();
|
||||||
|
}
|
||||||
|
return this._permalinkCreators[room.roomId];
|
||||||
|
},
|
||||||
|
|
||||||
|
_stopAllPermalinkCreators: function() {
|
||||||
|
if (!this._permalinkCreators) return;
|
||||||
|
for (const roomId of Object.keys(this._permalinkCreators)) {
|
||||||
|
this._permalinkCreators[roomId].stop();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
_onWidgetEchoStoreUpdate: function() {
|
_onWidgetEchoStoreUpdate: function() {
|
||||||
this.setState({
|
this.setState({
|
||||||
showApps: this._shouldShowApps(this.state.room),
|
showApps: this._shouldShowApps(this.state.room),
|
||||||
|
@ -436,9 +458,7 @@ module.exports = React.createClass({
|
||||||
}
|
}
|
||||||
|
|
||||||
// stop tracking room changes to format permalinks
|
// stop tracking room changes to format permalinks
|
||||||
if (this.state.permalinkCreator) {
|
this._stopAllPermalinkCreators();
|
||||||
this.state.permalinkCreator.stop();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.refs.roomView) {
|
if (this.refs.roomView) {
|
||||||
// disconnect the D&D event listeners from the room view. This
|
// disconnect the D&D event listeners from the room view. This
|
||||||
|
@ -651,11 +671,6 @@ module.exports = React.createClass({
|
||||||
this._loadMembersIfJoined(room);
|
this._loadMembersIfJoined(room);
|
||||||
this._calculateRecommendedVersion(room);
|
this._calculateRecommendedVersion(room);
|
||||||
this._updateE2EStatus(room);
|
this._updateE2EStatus(room);
|
||||||
if (!this.state.permalinkCreator) {
|
|
||||||
const permalinkCreator = new RoomPermalinkCreator(room);
|
|
||||||
permalinkCreator.start();
|
|
||||||
this.setState({permalinkCreator});
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
|
|
||||||
_calculateRecommendedVersion: async function(room) {
|
_calculateRecommendedVersion: async function(room) {
|
||||||
|
@ -1169,6 +1184,7 @@ module.exports = React.createClass({
|
||||||
|
|
||||||
const mxEv = result.context.getEvent();
|
const mxEv = result.context.getEvent();
|
||||||
const roomId = mxEv.getRoomId();
|
const roomId = mxEv.getRoomId();
|
||||||
|
const room = cli.getRoom(roomId);
|
||||||
|
|
||||||
if (!EventTile.haveTileForEvent(mxEv)) {
|
if (!EventTile.haveTileForEvent(mxEv)) {
|
||||||
// XXX: can this ever happen? It will make the result count
|
// XXX: can this ever happen? It will make the result count
|
||||||
|
@ -1178,7 +1194,6 @@ module.exports = React.createClass({
|
||||||
|
|
||||||
if (this.state.searchScope === 'All') {
|
if (this.state.searchScope === 'All') {
|
||||||
if (roomId != lastRoomId) {
|
if (roomId != lastRoomId) {
|
||||||
const room = cli.getRoom(roomId);
|
|
||||||
|
|
||||||
// XXX: if we've left the room, we might not know about
|
// XXX: if we've left the room, we might not know about
|
||||||
// it. We should tell the js sdk to go and find out about
|
// it. We should tell the js sdk to go and find out about
|
||||||
|
@ -1199,7 +1214,7 @@ module.exports = React.createClass({
|
||||||
searchResult={result}
|
searchResult={result}
|
||||||
searchHighlights={this.state.searchHighlights}
|
searchHighlights={this.state.searchHighlights}
|
||||||
resultLink={resultLink}
|
resultLink={resultLink}
|
||||||
permalinkCreator={this.state.permalinkCreator}
|
permalinkCreator={this._getPermalinkCreatorForRoom(room)}
|
||||||
onHeightChanged={onHeightChanged} />);
|
onHeightChanged={onHeightChanged} />);
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -1724,7 +1739,7 @@ module.exports = React.createClass({
|
||||||
disabled={this.props.disabled}
|
disabled={this.props.disabled}
|
||||||
showApps={this.state.showApps}
|
showApps={this.state.showApps}
|
||||||
e2eStatus={this.state.e2eStatus}
|
e2eStatus={this.state.e2eStatus}
|
||||||
permalinkCreator={this.state.permalinkCreator}
|
permalinkCreator={this._getPermalinkCreatorForRoom(this.state.room)}
|
||||||
/>;
|
/>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1826,7 +1841,7 @@ module.exports = React.createClass({
|
||||||
showUrlPreview = {this.state.showUrlPreview}
|
showUrlPreview = {this.state.showUrlPreview}
|
||||||
className="mx_RoomView_messagePanel"
|
className="mx_RoomView_messagePanel"
|
||||||
membersLoaded={this.state.membersLoaded}
|
membersLoaded={this.state.membersLoaded}
|
||||||
permalinkCreator={this.state.permalinkCreator}
|
permalinkCreator={this._getPermalinkCreatorForRoom(this.state.room)}
|
||||||
resizeNotifier={this.props.resizeNotifier}
|
resizeNotifier={this.props.resizeNotifier}
|
||||||
/>);
|
/>);
|
||||||
|
|
||||||
|
|
|
@ -77,6 +77,7 @@ export class RoomPermalinkCreator {
|
||||||
this._bannedHostsRegexps = null;
|
this._bannedHostsRegexps = null;
|
||||||
this._allowedHostsRegexps = null;
|
this._allowedHostsRegexps = null;
|
||||||
this._serverCandidates = null;
|
this._serverCandidates = null;
|
||||||
|
this._started = false;
|
||||||
|
|
||||||
this.onMembership = this.onMembership.bind(this);
|
this.onMembership = this.onMembership.bind(this);
|
||||||
this.onRoomState = this.onRoomState.bind(this);
|
this.onRoomState = this.onRoomState.bind(this);
|
||||||
|
@ -101,11 +102,17 @@ export class RoomPermalinkCreator {
|
||||||
this.load();
|
this.load();
|
||||||
this._room.on("RoomMember.membership", this.onMembership);
|
this._room.on("RoomMember.membership", this.onMembership);
|
||||||
this._room.on("RoomState.events", this.onRoomState);
|
this._room.on("RoomState.events", this.onRoomState);
|
||||||
|
this._started = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
stop() {
|
stop() {
|
||||||
this._room.removeListener("RoomMember.membership", this.onMembership);
|
this._room.removeListener("RoomMember.membership", this.onMembership);
|
||||||
this._room.removeListener("RoomState.events", this.onRoomState);
|
this._room.removeListener("RoomState.events", this.onRoomState);
|
||||||
|
this._started = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
isStarted() {
|
||||||
|
return this._started;
|
||||||
}
|
}
|
||||||
|
|
||||||
forEvent(eventId) {
|
forEvent(eventId) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue