Merge branch 'develop' into weeman1337/mute-broadcast-notifications

This commit is contained in:
Michael Weimann 2023-01-05 18:11:55 +01:00 committed by GitHub
commit 32deddc77e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 215 additions and 96 deletions

View file

@ -29,6 +29,7 @@ import * as Avatar from "../../../Avatar";
import DMRoomMap from "../../../utils/DMRoomMap";
import { mediaFromMxc } from "../../../customisations/Media";
import { IOOBData } from "../../../stores/ThreepidInviteStore";
import { LocalRoom } from "../../../models/LocalRoom";
interface IProps extends Omit<ComponentProps<typeof BaseAvatar>, "name" | "idName" | "url" | "onClick"> {
// Room may be left unset here, but if it is,
@ -117,13 +118,26 @@ export default class RoomAvatar extends React.Component<IProps, IState> {
Modal.createDialog(ImageView, params, "mx_Dialog_lightbox", null, true);
};
private get roomIdName(): string | undefined {
const room = this.props.room;
if (room) {
const dmMapUserId = DMRoomMap.shared().getUserIdForRoomId(room.roomId);
// If the room is a DM, we use the other user's ID for the color hash
// in order to match the room avatar with their avatar
if (dmMapUserId) return dmMapUserId;
if (room instanceof LocalRoom && room.targets.length === 1) {
return room.targets[0].userId;
}
}
return this.props.room?.roomId || this.props.oobData?.roomId;
}
public render() {
const { room, oobData, viewAvatarOnClick, onClick, className, ...otherProps } = this.props;
const roomName = room?.name ?? oobData.name;
// If the room is a DM, we use the other user's ID for the color hash
// in order to match the room avatar with their avatar
const idName = room ? DMRoomMap.shared().getUserIdForRoomId(room.roomId) ?? room.roomId : oobData.roomId;
return (
<BaseAvatar
@ -132,7 +146,7 @@ export default class RoomAvatar extends React.Component<IProps, IState> {
mx_RoomAvatar_isSpaceRoom: (room?.getType() ?? this.props.oobData?.roomType) === RoomType.Space,
})}
name={roomName}
idName={idName}
idName={this.roomIdName}
urls={this.state.urls}
onClick={viewAvatarOnClick && this.state.urls[0] ? this.onRoomAvatarClick : onClick}
/>

View file

@ -1,31 +0,0 @@
/*
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 { EventType, MatrixClient, MatrixEvent, RelationType } from "matrix-js-sdk/src/matrix";
import { Relations } from "matrix-js-sdk/src/models/relations";
import { VoiceBroadcastInfoEventType } from "../voice-broadcast";
export const getReferenceRelationsForEvent = (
event: MatrixEvent,
messageType: EventType | typeof VoiceBroadcastInfoEventType,
client: MatrixClient,
): Relations | undefined => {
const room = client.getRoom(event.getRoomId());
return room
?.getUnfilteredTimelineSet()
?.relations?.getChildEventsForEvent(event.getId(), RelationType.Reference, messageType);
};

View file

@ -16,4 +16,3 @@ limitations under the License.
export { getForwardableEvent } from "./forward/getForwardableEvent";
export { getShareableLocationEvent } from "./location/getShareableLocationEvent";
export * from "./getReferenceRelationsForEvent";