Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Commit

Permalink
Add voice broadcast recording body (#9316)
Browse files Browse the repository at this point in the history
* Add voice broadcast recording body

* Change icon element; update css variables

* Update Icon-test snapshots
  • Loading branch information
weeman1337 authored Sep 26, 2022
1 parent d077ea1 commit 8e719d5
Show file tree
Hide file tree
Showing 32 changed files with 1,059 additions and 7 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@
"@sinonjs/fake-timers": "^9.1.2",
"@testing-library/jest-dom": "^5.16.5",
"@testing-library/react": "^12.1.5",
"@testing-library/user-event": "^14.4.3",
"@types/classnames": "^2.2.11",
"@types/commonmark": "^0.27.4",
"@types/counterpart": "^0.18.1",
Expand Down
3 changes: 3 additions & 0 deletions res/css/_components.pcss
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
@import "./_font-sizes.pcss";
@import "./_font-weights.pcss";
@import "./_spacing.pcss";
@import "./components/atoms/_Icon.pcss";
@import "./components/views/beacon/_BeaconListItem.pcss";
@import "./components/views/beacon/_BeaconStatus.pcss";
@import "./components/views/beacon/_BeaconStatusTooltip.pcss";
Expand Down Expand Up @@ -357,3 +358,5 @@
@import "./views/voip/_LegacyCallViewSidebar.pcss";
@import "./views/voip/_PiPContainer.pcss";
@import "./views/voip/_VideoFeed.pcss";
@import "./voice-broadcast/atoms/_LiveBadge.pcss";
@import "./voice-broadcast/molecules/_VoiceBroadcastRecordingBody.pcss";
34 changes: 34 additions & 0 deletions res/css/components/atoms/_Icon.pcss
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
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.
*/

.mx_Icon {
mask-position: center;
mask-repeat: no-repeat;
mask-size: contain;
}

.mx_Icon_16 {
height: 16px;
width: 16px;
}

.mx_Icon_accent {
background-color: $accent;
}

.mx_Icon_live-badge {
background-color: #fff;
}
27 changes: 27 additions & 0 deletions res/css/voice-broadcast/atoms/_LiveBadge.pcss
Original file line number Diff line number Diff line change
@@ -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.
*/

.mx_LiveBadge {
align-items: center;
background-color: $alert;
border-radius: 2px;
color: $live-badge-color;
display: flex;
font-size: $font-12px;
font-weight: $font-semi-bold;
gap: $spacing-4;
padding: 2px 4px;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
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.
*/

.mx_VoiceBroadcastRecordingBody {
align-items: flex-start;
background-color: $quinary-content;
border-radius: 8px;
display: inline-flex;
gap: $spacing-8;
padding: 12px;
}

.mx_VoiceBroadcastRecordingBody_title {
font-size: $font-12px;
font-weight: $font-semi-bold;
}
5 changes: 5 additions & 0 deletions res/themes/dark/css/_dark.pcss
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,11 @@ $location-live-secondary-color: #deddfd;
}
/* ******************** */

/* Voice Broadcast */
/* ******************** */
$live-badge-color: #ffffff;
/* ******************** */

/* One-off colors */
/* ******************** */
$progressbar-bg-color: $system;
Expand Down
5 changes: 5 additions & 0 deletions res/themes/legacy-dark/css/_legacy-dark.pcss
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,11 @@ $location-live-color: #5c56f5;
$location-live-secondary-color: #deddfd;
/* ******************** */

/* Voice Broadcast */
/* ******************** */
$live-badge-color: #ffffff;
/* ******************** */

/* ***** Mixins! ***** */

@define-mixin mx_DialogButton {
Expand Down
5 changes: 5 additions & 0 deletions res/themes/legacy-light/css/_legacy-light.pcss
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,11 @@ $location-live-color: #5c56f5;
$location-live-secondary-color: #deddfd;
/* ******************** */

/* Voice Broadcast */
/* ******************** */
$live-badge-color: #ffffff;
/* ******************** */

/* ***** Mixins! ***** */

@define-mixin mx_DialogButton {
Expand Down
5 changes: 5 additions & 0 deletions res/themes/light/css/_light.pcss
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,11 @@ $location-live-color: #5c56f5;
$location-live-secondary-color: #deddfd;
/* ******************** */

/* Voice Broadcast */
/* ******************** */
$live-badge-color: #ffffff;
/* ******************** */

/* Mixins */
/* ******************** */
@define-mixin mx_DialogButton {
Expand Down
69 changes: 69 additions & 0 deletions src/components/atoms/Icon.tsx
Original file line number Diff line number Diff line change
@@ -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}
/>
);
};
12 changes: 11 additions & 1 deletion src/components/structures/MessagePanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down Expand Up @@ -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;
}
Expand Down
6 changes: 6 additions & 0 deletions src/components/views/messages/MessageEvent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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"> {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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")) {
Expand Down
23 changes: 17 additions & 6 deletions src/components/views/rooms/MessageComposer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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 && (
Expand Down
1 change: 1 addition & 0 deletions src/components/views/rooms/SendMessageComposer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
5 changes: 5 additions & 0 deletions src/events/EventTileFactory.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}
Expand Down
1 change: 1 addition & 0 deletions src/i18n/strings/en_EN.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Loading

0 comments on commit 8e719d5

Please sign in to comment.