Support MSC3026 busy presence (#8043)
* Support MSC3026 busy presence * Use UnstableValue * Add the import
This commit is contained in:
parent
afadea01a0
commit
23d5ba9c89
6 changed files with 24 additions and 1 deletions
|
@ -21,6 +21,7 @@ import { User, UserEvent } from "matrix-js-sdk/src/models/user";
|
|||
import { MatrixEvent } from "matrix-js-sdk/src/models/event";
|
||||
import { EventType } from "matrix-js-sdk/src/@types/event";
|
||||
import { JoinRule } from "matrix-js-sdk/src/@types/partials";
|
||||
import { UnstableValue } from "matrix-js-sdk/src/NamespacedValue";
|
||||
|
||||
import RoomAvatar from "./RoomAvatar";
|
||||
import NotificationBadge from '../rooms/NotificationBadge';
|
||||
|
@ -50,6 +51,8 @@ interface IState {
|
|||
icon: Icon;
|
||||
}
|
||||
|
||||
const BUSY_PRESENCE_NAME = new UnstableValue("busy", "org.matrix.msc3026.busy");
|
||||
|
||||
enum Icon {
|
||||
// Note: the names here are used in CSS class names
|
||||
None = "NONE", // ... except this one
|
||||
|
@ -57,6 +60,7 @@ enum Icon {
|
|||
PresenceOnline = "ONLINE",
|
||||
PresenceAway = "AWAY",
|
||||
PresenceOffline = "OFFLINE",
|
||||
PresenceBusy = "BUSY",
|
||||
}
|
||||
|
||||
function tooltipText(variant: Icon) {
|
||||
|
@ -69,6 +73,8 @@ function tooltipText(variant: Icon) {
|
|||
return _t("Away");
|
||||
case Icon.PresenceOffline:
|
||||
return _t("Offline");
|
||||
case Icon.PresenceBusy:
|
||||
return _t("Busy");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -141,7 +147,9 @@ export default class DecoratedRoomAvatar extends React.PureComponent<IProps, ISt
|
|||
let icon = Icon.None;
|
||||
|
||||
const isOnline = this.dmUser.currentlyActive || this.dmUser.presence === 'online';
|
||||
if (isOnline) {
|
||||
if (BUSY_PRESENCE_NAME.matches(this.dmUser.presence)) {
|
||||
icon = Icon.PresenceBusy;
|
||||
} else if (isOnline) {
|
||||
icon = Icon.PresenceOnline;
|
||||
} else if (this.dmUser.presence === 'offline') {
|
||||
icon = Icon.PresenceOffline;
|
||||
|
|
|
@ -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 });
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue