Use status events for avatar ring
Similar to changes in `StatusMessageContextMenu`, this changes to using the new status message event emitted in js-sdk to simplify state handling for the avatar ring when a status is present.
This commit is contained in:
parent
5b88b64950
commit
233288475e
1 changed files with 35 additions and 25 deletions
|
@ -40,38 +40,50 @@ export default class MemberStatusMessageAvatar extends React.Component {
|
||||||
|
|
||||||
constructor(props, context) {
|
constructor(props, context) {
|
||||||
super(props, context);
|
super(props, context);
|
||||||
|
|
||||||
|
this.state = {
|
||||||
|
hasStatus: this.hasStatus,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
componentWillMount() {
|
componentWillMount() {
|
||||||
if (this.props.member.userId !== MatrixClientPeg.get().getUserId()) {
|
if (this.props.member.userId !== MatrixClientPeg.get().getUserId()) {
|
||||||
throw new Error("Cannot use MemberStatusMessageAvatar on anyone but the logged in user");
|
throw new Error("Cannot use MemberStatusMessageAvatar on anyone but the logged in user");
|
||||||
}
|
}
|
||||||
|
if (!SettingsStore.isFeatureEnabled("feature_custom_status")) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const { user } = this.props.member;
|
||||||
|
if (!user) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
user.on("User._unstable_statusMessage", this._onStatusMessageCommitted);
|
||||||
}
|
}
|
||||||
|
|
||||||
componentDidMount() {
|
componentWillUmount() {
|
||||||
MatrixClientPeg.get().on("RoomState.events", this._onRoomStateEvents);
|
const { user } = this.props.member;
|
||||||
|
if (!user) {
|
||||||
if (this.props.member.user) {
|
return;
|
||||||
this.setState({message: this.props.member.user._unstable_statusMessage});
|
|
||||||
} else {
|
|
||||||
this.setState({message: ""});
|
|
||||||
}
|
}
|
||||||
|
user.removeListener(
|
||||||
|
"User._unstable_statusMessage",
|
||||||
|
this._onStatusMessageCommitted,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
componentWillUnmount() {
|
get hasStatus() {
|
||||||
if (MatrixClientPeg.get()) {
|
const { user } = this.props.member;
|
||||||
MatrixClientPeg.get().removeListener("RoomState.events", this._onRoomStateEvents);
|
if (!user) {
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
return !!user._unstable_statusMessage;
|
||||||
}
|
}
|
||||||
|
|
||||||
_onRoomStateEvents = (ev, state) => {
|
_onStatusMessageCommitted = () => {
|
||||||
if (ev.getStateKey() !== MatrixClientPeg.get().getUserId()) return;
|
// The `User` object has observed a status message change.
|
||||||
if (ev.getType() !== "im.vector.user_status") return;
|
this.setState({
|
||||||
// TODO: We should be relying on `this.props.member.user._unstable_statusMessage`
|
hasStatus: this.hasStatus,
|
||||||
// We don't currently because the js-sdk doesn't emit a specific event for this
|
});
|
||||||
// change, and we don't want to race it. This should be improved when we rip out
|
|
||||||
// the im.vector.user_status stuff and replace it with a complete solution.
|
|
||||||
this.setState({message: ev.getContent()["status"]});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
_onClick = (e) => {
|
_onClick = (e) => {
|
||||||
|
@ -104,9 +116,7 @@ export default class MemberStatusMessageAvatar extends React.Component {
|
||||||
|
|
||||||
if (customStatusFeatureEnabled) {
|
if (customStatusFeatureEnabled) {
|
||||||
onClick = this._onClick;
|
onClick = this._onClick;
|
||||||
if (this.props.member.user) {
|
hasStatus = this.state.hasStatus;
|
||||||
hasStatus = !!this.props.member.user._unstable_statusMessage;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const classes = classNames({
|
const classes = classNames({
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue