Update RoomTile on status change
This commit is contained in:
parent
77cee8e67e
commit
d8de607edc
1 changed files with 57 additions and 8 deletions
|
@ -62,6 +62,7 @@ module.exports = React.createClass({
|
||||||
notifState: RoomNotifs.getRoomNotifsState(this.props.room.roomId),
|
notifState: RoomNotifs.getRoomNotifsState(this.props.room.roomId),
|
||||||
notificationCount: this.props.room.getUnreadNotificationCount(),
|
notificationCount: this.props.room.getUnreadNotificationCount(),
|
||||||
selected: this.props.room.roomId === ActiveRoomObserver.getActiveRoomId(),
|
selected: this.props.room.roomId === ActiveRoomObserver.getActiveRoomId(),
|
||||||
|
statusMessage: this._getStatusMessage(),
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -79,6 +80,33 @@ module.exports = React.createClass({
|
||||||
return Boolean(dmRooms);
|
return Boolean(dmRooms);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
_shouldShowStatusMessage() {
|
||||||
|
if (!SettingsStore.isFeatureEnabled("feature_custom_status")) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
const isInvite = this.props.room.getMyMembership() === "invite";
|
||||||
|
const isJoined = this.props.room.getMyMembership() === "join";
|
||||||
|
const looksLikeDm = this.props.room.getInvitedAndJoinedMemberCount() === 2;
|
||||||
|
return !isInvite && isJoined && looksLikeDm;
|
||||||
|
},
|
||||||
|
|
||||||
|
_getStatusMessageUser() {
|
||||||
|
const selfId = MatrixClientPeg.get().getUserId();
|
||||||
|
const otherMember = this.props.room.currentState.getMembersExcept([selfId])[0];
|
||||||
|
if (!otherMember) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return otherMember.user;
|
||||||
|
},
|
||||||
|
|
||||||
|
_getStatusMessage() {
|
||||||
|
const statusUser = this._getStatusMessageUser();
|
||||||
|
if (!statusUser) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
return statusUser._unstable_statusMessage;
|
||||||
|
},
|
||||||
|
|
||||||
onRoomTimeline: function(ev, room) {
|
onRoomTimeline: function(ev, room) {
|
||||||
if (room !== this.props.room) return;
|
if (room !== this.props.room) return;
|
||||||
this.setState({
|
this.setState({
|
||||||
|
@ -134,6 +162,16 @@ module.exports = React.createClass({
|
||||||
MatrixClientPeg.get().on("Room.name", this.onRoomName);
|
MatrixClientPeg.get().on("Room.name", this.onRoomName);
|
||||||
ActiveRoomObserver.addListener(this.props.room.roomId, this._onActiveRoomChange);
|
ActiveRoomObserver.addListener(this.props.room.roomId, this._onActiveRoomChange);
|
||||||
this.dispatcherRef = dis.register(this.onAction);
|
this.dispatcherRef = dis.register(this.onAction);
|
||||||
|
|
||||||
|
if (this._shouldShowStatusMessage()) {
|
||||||
|
const statusUser = this._getStatusMessageUser();
|
||||||
|
if (statusUser) {
|
||||||
|
statusUser.on(
|
||||||
|
"User._unstable_statusMessage",
|
||||||
|
this._onStatusMessageCommitted,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
componentWillUnmount: function() {
|
componentWillUnmount: function() {
|
||||||
|
@ -145,6 +183,16 @@ module.exports = React.createClass({
|
||||||
}
|
}
|
||||||
ActiveRoomObserver.removeListener(this.props.room.roomId, this._onActiveRoomChange);
|
ActiveRoomObserver.removeListener(this.props.room.roomId, this._onActiveRoomChange);
|
||||||
dis.unregister(this.dispatcherRef);
|
dis.unregister(this.dispatcherRef);
|
||||||
|
|
||||||
|
if (this._shouldShowStatusMessage()) {
|
||||||
|
const statusUser = this._getStatusMessageUser();
|
||||||
|
if (statusUser) {
|
||||||
|
statusUser.removeListener(
|
||||||
|
"User._unstable_statusMessage",
|
||||||
|
this._onStatusMessageCommitted,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
componentWillReceiveProps: function(props) {
|
componentWillReceiveProps: function(props) {
|
||||||
|
@ -172,6 +220,13 @@ module.exports = React.createClass({
|
||||||
return false;
|
return false;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
_onStatusMessageCommitted() {
|
||||||
|
// The status message `User` object has observed a message change.
|
||||||
|
this.setState({
|
||||||
|
statusMessage: this._getStatusMessage(),
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
onClick: function(ev) {
|
onClick: function(ev) {
|
||||||
if (this.props.onClick) {
|
if (this.props.onClick) {
|
||||||
this.props.onClick(this.props.room.roomId, ev);
|
this.props.onClick(this.props.room.roomId, ev);
|
||||||
|
@ -257,15 +312,9 @@ module.exports = React.createClass({
|
||||||
const mentionBadges = this.props.highlight && this._shouldShowMentionBadge();
|
const mentionBadges = this.props.highlight && this._shouldShowMentionBadge();
|
||||||
const badges = notifBadges || mentionBadges;
|
const badges = notifBadges || mentionBadges;
|
||||||
|
|
||||||
const isJoined = this.props.room.getMyMembership() === "join";
|
|
||||||
const looksLikeDm = this.props.room.getInvitedAndJoinedMemberCount() === 2;
|
|
||||||
let subtext = null;
|
let subtext = null;
|
||||||
if (!isInvite && isJoined && looksLikeDm && SettingsStore.isFeatureEnabled("feature_custom_status")) {
|
if (this._shouldShowStatusMessage()) {
|
||||||
const selfId = MatrixClientPeg.get().getUserId();
|
subtext = this.state.statusMessage;
|
||||||
const otherMember = this.props.room.currentState.getMembersExcept([selfId])[0];
|
|
||||||
if (otherMember && otherMember.user && otherMember.user._unstable_statusMessage) {
|
|
||||||
subtext = otherMember.user._unstable_statusMessage;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const classes = classNames({
|
const classes = classNames({
|
||||||
|
|
Loading…
Reference in a new issue