Add voice broadcast recording body (#9316)
* Add voice broadcast recording body * Change icon element; update css variables * Update Icon-test snapshots
This commit is contained in:
parent
d077ea1990
commit
8e719d57a2
32 changed files with 1059 additions and 7 deletions
69
src/components/atoms/Icon.tsx
Normal file
69
src/components/atoms/Icon.tsx
Normal file
|
@ -0,0 +1,69 @@
|
|||
/*
|
||||
Copyright 2022 The Matrix.org Foundation C.I.C.
|
||||
|
||||
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.
|
||||
*/
|
||||
|
||||
import React from "react";
|
||||
|
||||
import liveIcon from "../../../res/img/element-icons/live.svg";
|
||||
|
||||
export enum IconType {
|
||||
Live,
|
||||
}
|
||||
|
||||
const iconTypeMap = new Map([
|
||||
[IconType.Live, liveIcon],
|
||||
]);
|
||||
|
||||
export enum IconColour {
|
||||
Accent = "accent",
|
||||
LiveBadge = "live-badge",
|
||||
}
|
||||
|
||||
export enum IconSize {
|
||||
S16 = "16",
|
||||
}
|
||||
|
||||
interface IconProps {
|
||||
colour?: IconColour;
|
||||
size?: IconSize;
|
||||
type: IconType;
|
||||
}
|
||||
|
||||
export const Icon: React.FC<IconProps> = ({
|
||||
size = IconSize.S16,
|
||||
colour = IconColour.Accent,
|
||||
type,
|
||||
...rest
|
||||
}) => {
|
||||
const classes = [
|
||||
"mx_Icon",
|
||||
`mx_Icon_${size}`,
|
||||
`mx_Icon_${colour}`,
|
||||
];
|
||||
|
||||
const styles: React.CSSProperties = {
|
||||
maskImage: `url("${iconTypeMap.get(type)}")`,
|
||||
};
|
||||
|
||||
return (
|
||||
<i
|
||||
aria-hidden
|
||||
className={classes.join(" ")}
|
||||
role="presentation"
|
||||
style={styles}
|
||||
{...rest}
|
||||
/>
|
||||
);
|
||||
};
|
|
@ -59,6 +59,7 @@ import { IReadReceiptInfo } from "../views/rooms/ReadReceiptMarker";
|
|||
import { haveRendererForEvent } from "../../events/EventTileFactory";
|
||||
import { editorRoomKey } from "../../Editing";
|
||||
import { hasThreadSummary } from "../../utils/EventUtils";
|
||||
import { VoiceBroadcastInfoEventType } from '../../voice-broadcast';
|
||||
|
||||
const CONTINUATION_MAX_INTERVAL = 5 * 60 * 1000; // 5 minutes
|
||||
const continuedTypes = [EventType.Sticker, EventType.RoomMessage];
|
||||
|
@ -1091,11 +1092,20 @@ class CreationGrouper extends BaseGrouper {
|
|||
&& (ev.getStateKey() !== createEvent.getSender() || ev.getContent()["membership"] !== "join")) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const eventType = ev.getType();
|
||||
|
||||
// beacons are not part of room creation configuration
|
||||
// should be shown in timeline
|
||||
if (M_BEACON_INFO.matches(ev.getType())) {
|
||||
if (M_BEACON_INFO.matches(eventType)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (VoiceBroadcastInfoEventType === eventType) {
|
||||
// always show voice broadcast info events in timeline
|
||||
return false;
|
||||
}
|
||||
|
||||
if (ev.isState() && ev.getSender() === createEvent.getSender()) {
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -42,6 +42,7 @@ import MLocationBody from "./MLocationBody";
|
|||
import MjolnirBody from "./MjolnirBody";
|
||||
import MBeaconBody from "./MBeaconBody";
|
||||
import { IEventTileOps } from "../rooms/EventTile";
|
||||
import { VoiceBroadcastBody, VoiceBroadcastInfoEventType, VoiceBroadcastInfoState } from '../../../voice-broadcast';
|
||||
|
||||
// onMessageAllowed is handled internally
|
||||
interface IProps extends Omit<IBodyProps, "onMessageAllowed" | "mediaEventHelper"> {
|
||||
|
@ -74,6 +75,7 @@ const baseEvTypes = new Map<string, React.ComponentType<Partial<IBodyProps>>>([
|
|||
[M_POLL_START.altName, MPollBody],
|
||||
[M_BEACON_INFO.name, MBeaconBody],
|
||||
[M_BEACON_INFO.altName, MBeaconBody],
|
||||
[VoiceBroadcastInfoEventType, VoiceBroadcastBody],
|
||||
]);
|
||||
|
||||
export default class MessageEvent extends React.Component<IProps> implements IMediaBody, IOperableEventTile {
|
||||
|
@ -171,6 +173,10 @@ export default class MessageEvent extends React.Component<IProps> implements IMe
|
|||
) {
|
||||
BodyType = MLocationBody;
|
||||
}
|
||||
|
||||
if (type === VoiceBroadcastInfoEventType && content?.state === VoiceBroadcastInfoState.Started) {
|
||||
BodyType = VoiceBroadcastBody;
|
||||
}
|
||||
}
|
||||
|
||||
if (SettingsStore.getValue("feature_mjolnir")) {
|
||||
|
|
|
@ -54,6 +54,11 @@ import { ViewRoomPayload } from "../../../dispatcher/payloads/ViewRoomPayload";
|
|||
import { isLocalRoom } from '../../../utils/localRoom/isLocalRoom';
|
||||
import { Features } from '../../../settings/Settings';
|
||||
import { VoiceMessageRecording } from '../../../audio/VoiceMessageRecording';
|
||||
import {
|
||||
VoiceBroadcastInfoEventContent,
|
||||
VoiceBroadcastInfoEventType,
|
||||
VoiceBroadcastInfoState,
|
||||
} from '../../../voice-broadcast';
|
||||
|
||||
let instanceCount = 0;
|
||||
|
||||
|
@ -503,12 +508,18 @@ export default class MessageComposer extends React.Component<IProps, IState> {
|
|||
showStickersButton={this.showStickersButton}
|
||||
toggleButtonMenu={this.toggleButtonMenu}
|
||||
showVoiceBroadcastButton={this.showVoiceBroadcastButton}
|
||||
onStartVoiceBroadcastClick={() => {
|
||||
// Sends a voice message. To be replaced by voice broadcast during development.
|
||||
this.voiceRecordingButton.current?.onRecordStartEndClick();
|
||||
if (this.context.narrow) {
|
||||
this.toggleButtonMenu();
|
||||
}
|
||||
onStartVoiceBroadcastClick={async () => {
|
||||
const client = MatrixClientPeg.get();
|
||||
client.sendStateEvent(
|
||||
this.props.room.roomId,
|
||||
VoiceBroadcastInfoEventType,
|
||||
{
|
||||
state: VoiceBroadcastInfoState.Started,
|
||||
chunk_length: 300,
|
||||
} as VoiceBroadcastInfoEventContent,
|
||||
client.getUserId(),
|
||||
);
|
||||
this.toggleButtonMenu();
|
||||
}}
|
||||
/> }
|
||||
{ showSendButton && (
|
||||
|
|
|
@ -88,6 +88,7 @@ export function createMessageContent(
|
|||
model = unescapeMessage(model);
|
||||
|
||||
const body = textSerialize(model);
|
||||
|
||||
const content: IContent = {
|
||||
msgtype: isEmote ? "m.emote" : "m.text",
|
||||
body: body,
|
||||
|
|
|
@ -43,6 +43,7 @@ import { getMessageModerationState, MessageModerationState } from "../utils/Even
|
|||
import HiddenBody from "../components/views/messages/HiddenBody";
|
||||
import ViewSourceEvent from "../components/views/messages/ViewSourceEvent";
|
||||
import { shouldDisplayAsBeaconTile } from "../utils/beacon/timeline";
|
||||
import { shouldDisplayAsVoiceBroadcastTile } from "../voice-broadcast/utils/shouldDisplayAsVoiceBroadcastTile";
|
||||
|
||||
// Subset of EventTile's IProps plus some mixins
|
||||
export interface EventTileTypeProps {
|
||||
|
@ -220,6 +221,10 @@ export function pickFactory(
|
|||
return MessageEventFactory;
|
||||
}
|
||||
|
||||
if (shouldDisplayAsVoiceBroadcastTile(mxEvent)) {
|
||||
return MessageEventFactory;
|
||||
}
|
||||
|
||||
if (SINGULAR_STATE_EVENTS.has(evType) && mxEvent.getStateKey() !== '') {
|
||||
return noEventFactoryFactory(); // improper event type to render
|
||||
}
|
||||
|
|
|
@ -636,6 +636,7 @@
|
|||
"Send <b>%(msgtype)s</b> messages as you in your active room": "Send <b>%(msgtype)s</b> messages as you in your active room",
|
||||
"See <b>%(msgtype)s</b> messages posted to this room": "See <b>%(msgtype)s</b> messages posted to this room",
|
||||
"See <b>%(msgtype)s</b> messages posted to your active room": "See <b>%(msgtype)s</b> messages posted to your active room",
|
||||
"Live": "Live",
|
||||
"Cannot reach homeserver": "Cannot reach homeserver",
|
||||
"Ensure you have a stable internet connection, or get in touch with the server admin": "Ensure you have a stable internet connection, or get in touch with the server admin",
|
||||
"Your %(brand)s is misconfigured": "Your %(brand)s is misconfigured",
|
||||
|
|
70
src/voice-broadcast/components/VoiceBroadcastBody.tsx
Normal file
70
src/voice-broadcast/components/VoiceBroadcastBody.tsx
Normal file
|
@ -0,0 +1,70 @@
|
|||
/*
|
||||
Copyright 2022 The Matrix.org Foundation C.I.C.
|
||||
|
||||
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.
|
||||
*/
|
||||
|
||||
import React from "react";
|
||||
import { MatrixEvent, RelationType } from "matrix-js-sdk/src/matrix";
|
||||
|
||||
import { VoiceBroadcastInfoEventType, VoiceBroadcastInfoState, VoiceBroadcastRecordingBody } from "..";
|
||||
import { IBodyProps } from "../../components/views/messages/IBodyProps";
|
||||
import { MatrixClientPeg } from "../../MatrixClientPeg";
|
||||
|
||||
/**
|
||||
* Temporary component to display voice broadcasts.
|
||||
* XXX: To be refactored to some fancy store/hook/controller architecture.
|
||||
*/
|
||||
export const VoiceBroadcastBody: React.FC<IBodyProps> = ({
|
||||
getRelationsForEvent,
|
||||
mxEvent,
|
||||
}) => {
|
||||
const client = MatrixClientPeg.get();
|
||||
const relations = getRelationsForEvent?.(
|
||||
mxEvent.getId(),
|
||||
RelationType.Reference,
|
||||
VoiceBroadcastInfoEventType,
|
||||
);
|
||||
const relatedEvents = relations?.getRelations();
|
||||
const live = !relatedEvents?.find((event: MatrixEvent) => {
|
||||
return event.getContent()?.state === VoiceBroadcastInfoState.Stopped;
|
||||
});
|
||||
|
||||
const stopVoiceBroadcast = () => {
|
||||
if (!live) return;
|
||||
|
||||
client.sendStateEvent(
|
||||
mxEvent.getRoomId(),
|
||||
VoiceBroadcastInfoEventType,
|
||||
{
|
||||
state: VoiceBroadcastInfoState.Stopped,
|
||||
["m.relates_to"]: {
|
||||
rel_type: RelationType.Reference,
|
||||
event_id: mxEvent.getId(),
|
||||
},
|
||||
},
|
||||
client.getUserId(),
|
||||
);
|
||||
};
|
||||
|
||||
const room = client.getRoom(mxEvent.getRoomId());
|
||||
const senderId = mxEvent.getSender();
|
||||
const sender = mxEvent.sender;
|
||||
return <VoiceBroadcastRecordingBody
|
||||
onClick={stopVoiceBroadcast}
|
||||
live={live}
|
||||
member={sender}
|
||||
userId={senderId}
|
||||
title={`${sender?.name ?? senderId} • ${room.name}`}
|
||||
/>;
|
||||
};
|
27
src/voice-broadcast/components/atoms/LiveBadge.tsx
Normal file
27
src/voice-broadcast/components/atoms/LiveBadge.tsx
Normal file
|
@ -0,0 +1,27 @@
|
|||
/*
|
||||
Copyright 2022 The Matrix.org Foundation C.I.C.
|
||||
|
||||
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.
|
||||
*/
|
||||
|
||||
import React from "react";
|
||||
|
||||
import { Icon, IconColour, IconType } from "../../../components/atoms/Icon";
|
||||
import { _t } from "../../../languageHandler";
|
||||
|
||||
export const LiveBadge: React.FC = () => {
|
||||
return <div className="mx_LiveBadge">
|
||||
<Icon type={IconType.Live} colour={IconColour.LiveBadge} />
|
||||
{ _t("Live") }
|
||||
</div>;
|
||||
};
|
19
src/voice-broadcast/components/index.ts
Normal file
19
src/voice-broadcast/components/index.ts
Normal file
|
@ -0,0 +1,19 @@
|
|||
/*
|
||||
Copyright 2022 The Matrix.org Foundation C.I.C.
|
||||
|
||||
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.
|
||||
*/
|
||||
|
||||
export * from "./atoms/LiveBadge";
|
||||
export * from "./molecules/VoiceBroadcastRecordingBody";
|
||||
export * from "./VoiceBroadcastBody";
|
|
@ -0,0 +1,56 @@
|
|||
/*
|
||||
Copyright 2022 The Matrix.org Foundation C.I.C.
|
||||
|
||||
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.
|
||||
*/
|
||||
|
||||
import React, { MouseEventHandler } from "react";
|
||||
import { RoomMember } from "matrix-js-sdk/src/matrix";
|
||||
|
||||
import { LiveBadge } from "../..";
|
||||
import MemberAvatar from "../../../components/views/avatars/MemberAvatar";
|
||||
|
||||
interface VoiceBroadcastRecordingBodyProps {
|
||||
live: boolean;
|
||||
member: RoomMember;
|
||||
onClick: MouseEventHandler<HTMLDivElement>;
|
||||
title: string;
|
||||
userId: string;
|
||||
}
|
||||
|
||||
export const VoiceBroadcastRecordingBody: React.FC<VoiceBroadcastRecordingBodyProps> = ({
|
||||
live,
|
||||
member,
|
||||
onClick,
|
||||
title,
|
||||
userId,
|
||||
}) => {
|
||||
const liveBadge = live
|
||||
? <LiveBadge />
|
||||
: null;
|
||||
|
||||
return (
|
||||
<div
|
||||
className="mx_VoiceBroadcastRecordingBody"
|
||||
onClick={onClick}
|
||||
>
|
||||
<MemberAvatar member={member} fallbackUserId={userId} />
|
||||
<div className="mx_VoiceBroadcastRecordingBody_content">
|
||||
<div className="mx_VoiceBroadcastRecordingBody_title">
|
||||
{ title }
|
||||
</div>
|
||||
</div>
|
||||
{ liveBadge }
|
||||
</div>
|
||||
);
|
||||
};
|
|
@ -14,4 +14,30 @@ See the License for the specific language governing permissions and
|
|||
limitations under the License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Voice Broadcast module
|
||||
* {@link https://github.com/vector-im/element-meta/discussions/632}
|
||||
*/
|
||||
|
||||
import { RelationType } from "matrix-js-sdk/src/matrix";
|
||||
|
||||
export * from "./components";
|
||||
export * from "./utils";
|
||||
|
||||
export const VoiceBroadcastInfoEventType = "io.element.voice_broadcast_info";
|
||||
|
||||
export enum VoiceBroadcastInfoState {
|
||||
Started = "started",
|
||||
Paused = "paused",
|
||||
Running = "running",
|
||||
Stopped = "stopped",
|
||||
}
|
||||
|
||||
export interface VoiceBroadcastInfoEventContent {
|
||||
state: VoiceBroadcastInfoState;
|
||||
chunk_length: number;
|
||||
["m.relates_to"]?: {
|
||||
rel_type: RelationType;
|
||||
event_id: string;
|
||||
};
|
||||
}
|
||||
|
|
17
src/voice-broadcast/utils/index.ts
Normal file
17
src/voice-broadcast/utils/index.ts
Normal file
|
@ -0,0 +1,17 @@
|
|||
/*
|
||||
Copyright 2022 The Matrix.org Foundation C.I.C.
|
||||
|
||||
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.
|
||||
*/
|
||||
|
||||
export * from "./shouldDisplayAsVoiceBroadcastTile";
|
|
@ -0,0 +1,27 @@
|
|||
/*
|
||||
Copyright 2022 The Matrix.org Foundation C.I.C.
|
||||
|
||||
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.
|
||||
*/
|
||||
|
||||
import { MatrixEvent } from "matrix-js-sdk/src/matrix";
|
||||
|
||||
import { VoiceBroadcastInfoEventType, VoiceBroadcastInfoState } from "..";
|
||||
|
||||
export const shouldDisplayAsVoiceBroadcastTile = (event: MatrixEvent) => (
|
||||
event.getType?.() === VoiceBroadcastInfoEventType
|
||||
&& (
|
||||
event.getContent?.()?.state === VoiceBroadcastInfoState.Started
|
||||
|| event.isRedacted()
|
||||
)
|
||||
);
|
Loading…
Add table
Add a link
Reference in a new issue