Use the same MatrixClient for the duration of GroupView lifecycle
Using the pegged matrix client would lead to trying to call removeListener on `null` when GroupView is unmounted during logout.
This commit is contained in:
parent
7893927e14
commit
266a504981
1 changed files with 14 additions and 13 deletions
|
@ -435,14 +435,15 @@ export default React.createClass({
|
||||||
},
|
},
|
||||||
|
|
||||||
componentWillMount: function() {
|
componentWillMount: function() {
|
||||||
|
this._matrixClient = MatrixClientPeg.get();
|
||||||
|
this._matrixClient.on("Group.myMembership", this._onGroupMyMembership);
|
||||||
|
|
||||||
this._changeAvatarComponent = null;
|
this._changeAvatarComponent = null;
|
||||||
this._initGroupStore(this.props.groupId, true);
|
this._initGroupStore(this.props.groupId, true);
|
||||||
|
|
||||||
MatrixClientPeg.get().on("Group.myMembership", this._onGroupMyMembership);
|
|
||||||
},
|
},
|
||||||
|
|
||||||
componentWillUnmount: function() {
|
componentWillUnmount: function() {
|
||||||
MatrixClientPeg.get().removeListener("Group.myMembership", this._onGroupMyMembership);
|
this._matrixClient.removeListener("Group.myMembership", this._onGroupMyMembership);
|
||||||
this._groupStore.removeAllListeners();
|
this._groupStore.removeAllListeners();
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -464,11 +465,11 @@ export default React.createClass({
|
||||||
},
|
},
|
||||||
|
|
||||||
_initGroupStore: function(groupId, firstInit) {
|
_initGroupStore: function(groupId, firstInit) {
|
||||||
const group = MatrixClientPeg.get().getGroup(groupId);
|
const group = this._matrixClient.getGroup(groupId);
|
||||||
if (group && group.inviter && group.inviter.userId) {
|
if (group && group.inviter && group.inviter.userId) {
|
||||||
this._fetchInviterProfile(group.inviter.userId);
|
this._fetchInviterProfile(group.inviter.userId);
|
||||||
}
|
}
|
||||||
this._groupStore = GroupStoreCache.getGroupStore(MatrixClientPeg.get(), groupId);
|
this._groupStore = GroupStoreCache.getGroupStore(this._matrixClient, groupId);
|
||||||
this._groupStore.registerListener(() => {
|
this._groupStore.registerListener(() => {
|
||||||
const summary = this._groupStore.getSummary();
|
const summary = this._groupStore.getSummary();
|
||||||
if (summary.profile) {
|
if (summary.profile) {
|
||||||
|
@ -486,7 +487,7 @@ export default React.createClass({
|
||||||
groupRooms: this._groupStore.getGroupRooms(),
|
groupRooms: this._groupStore.getGroupRooms(),
|
||||||
groupRoomsLoading: !this._groupStore.isStateReady(GroupStore.STATE_KEY.GroupRooms),
|
groupRoomsLoading: !this._groupStore.isStateReady(GroupStore.STATE_KEY.GroupRooms),
|
||||||
isUserMember: this._groupStore.getGroupMembers().some(
|
isUserMember: this._groupStore.getGroupMembers().some(
|
||||||
(m) => m.userId === MatrixClientPeg.get().credentials.userId,
|
(m) => m.userId === this._matrixClient.credentials.userId,
|
||||||
),
|
),
|
||||||
error: null,
|
error: null,
|
||||||
});
|
});
|
||||||
|
@ -506,7 +507,7 @@ export default React.createClass({
|
||||||
this.setState({
|
this.setState({
|
||||||
inviterProfileBusy: true,
|
inviterProfileBusy: true,
|
||||||
});
|
});
|
||||||
MatrixClientPeg.get().getProfileInfo(userId).then((resp) => {
|
this._matrixClient.getProfileInfo(userId).then((resp) => {
|
||||||
this.setState({
|
this.setState({
|
||||||
inviterProfile: {
|
inviterProfile: {
|
||||||
avatarUrl: resp.avatar_url,
|
avatarUrl: resp.avatar_url,
|
||||||
|
@ -571,7 +572,7 @@ export default React.createClass({
|
||||||
if (!file) return;
|
if (!file) return;
|
||||||
|
|
||||||
this.setState({uploadingAvatar: true});
|
this.setState({uploadingAvatar: true});
|
||||||
MatrixClientPeg.get().uploadContent(file).then((url) => {
|
this._matrixClient.uploadContent(file).then((url) => {
|
||||||
const newProfileForm = Object.assign(this.state.profileForm, { avatar_url: url });
|
const newProfileForm = Object.assign(this.state.profileForm, { avatar_url: url });
|
||||||
this.setState({
|
this.setState({
|
||||||
uploadingAvatar: false,
|
uploadingAvatar: false,
|
||||||
|
@ -591,7 +592,7 @@ export default React.createClass({
|
||||||
_onSaveClick: function() {
|
_onSaveClick: function() {
|
||||||
this.setState({saving: true});
|
this.setState({saving: true});
|
||||||
const savePromise = this.state.isUserPrivileged ?
|
const savePromise = this.state.isUserPrivileged ?
|
||||||
MatrixClientPeg.get().setGroupProfile(this.props.groupId, this.state.profileForm) :
|
this._matrixClient.setGroupProfile(this.props.groupId, this.state.profileForm) :
|
||||||
Promise.resolve();
|
Promise.resolve();
|
||||||
savePromise.then((result) => {
|
savePromise.then((result) => {
|
||||||
this.setState({
|
this.setState({
|
||||||
|
@ -630,7 +631,7 @@ export default React.createClass({
|
||||||
|
|
||||||
_onRejectInviteClick: function() {
|
_onRejectInviteClick: function() {
|
||||||
this.setState({membershipBusy: true});
|
this.setState({membershipBusy: true});
|
||||||
MatrixClientPeg.get().leaveGroup(this.props.groupId).then(() => {
|
this._matrixClient.leaveGroup(this.props.groupId).then(() => {
|
||||||
// don't reset membershipBusy here: wait for the membership change to come down the sync
|
// don't reset membershipBusy here: wait for the membership change to come down the sync
|
||||||
}).catch((e) => {
|
}).catch((e) => {
|
||||||
this.setState({membershipBusy: false});
|
this.setState({membershipBusy: false});
|
||||||
|
@ -653,7 +654,7 @@ export default React.createClass({
|
||||||
if (!confirmed) return;
|
if (!confirmed) return;
|
||||||
|
|
||||||
this.setState({membershipBusy: true});
|
this.setState({membershipBusy: true});
|
||||||
MatrixClientPeg.get().leaveGroup(this.props.groupId).then(() => {
|
this._matrixClient.leaveGroup(this.props.groupId).then(() => {
|
||||||
// don't reset membershipBusy here: wait for the membership change to come down the sync
|
// don't reset membershipBusy here: wait for the membership change to come down the sync
|
||||||
}).catch((e) => {
|
}).catch((e) => {
|
||||||
this.setState({membershipBusy: false});
|
this.setState({membershipBusy: false});
|
||||||
|
@ -829,7 +830,7 @@ export default React.createClass({
|
||||||
const Spinner = sdk.getComponent("elements.Spinner");
|
const Spinner = sdk.getComponent("elements.Spinner");
|
||||||
const BaseAvatar = sdk.getComponent("avatars.BaseAvatar");
|
const BaseAvatar = sdk.getComponent("avatars.BaseAvatar");
|
||||||
|
|
||||||
const group = MatrixClientPeg.get().getGroup(this.props.groupId);
|
const group = this._matrixClient.getGroup(this.props.groupId);
|
||||||
if (!group) return null;
|
if (!group) return null;
|
||||||
|
|
||||||
if (group.myMembership === 'invite') {
|
if (group.myMembership === 'invite') {
|
||||||
|
@ -839,7 +840,7 @@ export default React.createClass({
|
||||||
</div>;
|
</div>;
|
||||||
}
|
}
|
||||||
const httpInviterAvatar = this.state.inviterProfile ?
|
const httpInviterAvatar = this.state.inviterProfile ?
|
||||||
MatrixClientPeg.get().mxcUrlToHttp(
|
this._matrixClient.mxcUrlToHttp(
|
||||||
this.state.inviterProfile.avatarUrl, 36, 36,
|
this.state.inviterProfile.avatarUrl, 36, 36,
|
||||||
) : null;
|
) : null;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue