Support MSC3026 busy presence (#8043)

* Support MSC3026 busy presence

* Use UnstableValue

* Add the import
This commit is contained in:
David Baker 2022-03-14 10:22:12 +00:00 committed by GitHub
parent afadea01a0
commit 23d5ba9c89
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 24 additions and 1 deletions

View file

@ -15,10 +15,13 @@ limitations under the License.
*/
import React from 'react';
import { UnstableValue } from "matrix-js-sdk/src/NamespacedValue";
import { _t } from '../../../languageHandler';
import { replaceableComponent } from "../../../utils/replaceableComponent";
const BUSY_PRESENCE_NAME = new UnstableValue("busy", "org.matrix.msc3026.busy");
interface IProps {
// number of milliseconds ago this user was last active.
// zero = unknown
@ -62,6 +65,11 @@ export default class PresenceLabel extends React.Component<IProps> {
}
private getPrettyPresence(presence: string, activeAgo: number, currentlyActive: boolean): string {
// for busy presence, we ignore the 'currentlyActive' flag: they're busy whether
// they're active or not. It can be set while the user is active in which case
// the 'active ago' ends up being 0.
if (BUSY_PRESENCE_NAME.matches(presence)) return _t("Busy");
if (!currentlyActive && activeAgo !== undefined && activeAgo > 0) {
const duration = this.getDuration(activeAgo);
if (presence === "online") return _t("Online for %(duration)s", { duration: duration });