This repository has been archived by the owner on Sep 11, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 828
Implement user-controlled presence #1482
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
6cd0773
Add MemberPresenceAvatar and control presence ourselves
turt2live 49c19bc
Merge branch 'develop' into travis/presence
turt2live 854394c
Merge branch 'develop' into travis/presence
turt2live 0b20681
Put presence management behind a labs setting
turt2live 788e16a
Linting
turt2live 03800b7
Support more positioning options on context menus
turt2live c483717
Make onClick be a context menu for presence
turt2live 7307bc4
Respond to updates from presence context menu
turt2live 5c99709
Undo i18n change to make merge easier
turt2live e773585
Merge remote-tracking branch 'matrix-org/develop' into travis/presence
turt2live 24000ee
Re-add i18n for labs
turt2live File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,157 @@ | ||
/* | ||
Copyright 2017 Travis Ralston | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
import React from "react"; | ||
import * as sdk from "../../../index"; | ||
import MatrixClientPeg from "../../../MatrixClientPeg"; | ||
import AccessibleButton from '../elements/AccessibleButton'; | ||
import Presence from "../../../Presence"; | ||
import dispatcher from "../../../dispatcher"; | ||
import UserSettingsStore from "../../../UserSettingsStore"; | ||
import * as ContextualMenu from "../../structures/ContextualMenu"; | ||
|
||
module.exports = React.createClass({ | ||
displayName: 'MemberPresenceAvatar', | ||
|
||
propTypes: { | ||
member: React.PropTypes.object.isRequired, | ||
width: React.PropTypes.number, | ||
height: React.PropTypes.number, | ||
resizeMethod: React.PropTypes.string, | ||
}, | ||
|
||
getDefaultProps: function() { | ||
return { | ||
width: 40, | ||
height: 40, | ||
resizeMethod: 'crop', | ||
}; | ||
}, | ||
|
||
getInitialState: function() { | ||
const presenceState = this.props.member.user.presence; | ||
const presenceMessage = this.props.member.user.presenceStatusMsg; | ||
return { | ||
status: presenceState, | ||
message: presenceMessage, | ||
}; | ||
}, | ||
|
||
componentWillMount: function() { | ||
MatrixClientPeg.get().on("User.presence", this.onUserPresence); | ||
this.dispatcherRef = dispatcher.register(this.onAction); | ||
}, | ||
|
||
componentWillUnmount: function() { | ||
if (MatrixClientPeg.get()) { | ||
MatrixClientPeg.get().removeListener("User.presence", this.onUserPresence); | ||
} | ||
dispatcher.unregister(this.dispatcherRef); | ||
}, | ||
|
||
onAction: function(payload) { | ||
if (payload.action !== "self_presence_updated") return; | ||
if (this.props.member.userId !== MatrixClientPeg.get().getUserId()) return; | ||
this.setState({ | ||
status: payload.statusInfo.presence, | ||
message: payload.statusInfo.status_msg, | ||
}); | ||
}, | ||
|
||
onUserPresence: function(event, user) { | ||
if (user.userId !== MatrixClientPeg.get().getUserId()) return; | ||
this.setState({ | ||
status: user.presence, | ||
message: user.presenceStatusMsg, | ||
}); | ||
}, | ||
|
||
onStatusChange: function(newStatus) { | ||
Presence.stopMaintainingStatus(); | ||
if (newStatus === "online") { | ||
Presence.setState(newStatus); | ||
} else Presence.setState(newStatus, null, true); | ||
}, | ||
|
||
onClick: function(e) { | ||
const PresenceContextMenu = sdk.getComponent('context_menus.PresenceContextMenu'); | ||
const elementRect = e.target.getBoundingClientRect(); | ||
|
||
// The window X and Y offsets are to adjust position when zoomed in to page | ||
const x = (elementRect.left + window.pageXOffset) - (elementRect.width / 2) + 3; | ||
const chevronOffset = 12; | ||
let y = elementRect.top + (elementRect.height / 2) + window.pageYOffset; | ||
y = y - (chevronOffset + 4); // where 4 is 1/4 the height of the chevron | ||
|
||
ContextualMenu.createMenu(PresenceContextMenu, { | ||
chevronOffset: chevronOffset, | ||
chevronFace: 'bottom', | ||
left: x, | ||
top: y, | ||
menuWidth: 125, | ||
currentStatus: this.state.status, | ||
onChange: this.onStatusChange, | ||
}); | ||
|
||
e.stopPropagation(); | ||
// const presenceState = this.props.member.user.presence; | ||
// const presenceLastActiveAgo = this.props.member.user.lastActiveAgo; | ||
// const presenceLastTs = this.props.member.user.lastPresenceTs; | ||
// const presenceCurrentlyActive = this.props.member.user.currentlyActive; | ||
// const presenceMessage = this.props.member.user.presenceStatusMsg; | ||
}, | ||
|
||
render: function() { | ||
const MemberAvatar = sdk.getComponent("avatars.MemberAvatar"); | ||
|
||
let onClickFn = null; | ||
if (this.props.member.userId === MatrixClientPeg.get().getUserId()) { | ||
onClickFn = this.onClick; | ||
} | ||
|
||
const avatarNode = ( | ||
<MemberAvatar member={this.props.member} width={this.props.width} height={this.props.height} | ||
resizeMethod={this.props.resizeMethod} /> | ||
); | ||
let statusNode = ( | ||
<span className={"mx_MemberPresenceAvatar_status mx_MemberPresenceAvatar_status_" + this.state.status} /> | ||
); | ||
|
||
// LABS: Disable presence management functions for now | ||
if (!UserSettingsStore.isFeatureEnabled("feature_presence_management")) { | ||
statusNode = null; | ||
onClickFn = null; | ||
} | ||
|
||
let avatar = ( | ||
<div className="mx_MemberPresenceAvatar"> | ||
{ avatarNode } | ||
{ statusNode } | ||
</div> | ||
); | ||
if (onClickFn) { | ||
avatar = ( | ||
<AccessibleButton onClick={onClickFn} className="mx_MemberPresenceAvatar" element="div"> | ||
{ avatarNode } | ||
{ statusNode } | ||
</AccessibleButton> | ||
); | ||
} | ||
return avatar; | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
surprised the linter doesn't complain bitterly about this - the codestyle is to avoid oneliner if & else blocks please :)