Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/components/views/composer/HistoryVisibleBanner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { type Room } from "matrix-js-sdk/src/matrix";

import { HistoryVisibleBannerViewModel } from "../../../viewmodels/composer/HistoryVisibleBannerViewModel";

export const HistoryVisibleBanner: React.FC<{ room: Room }> = ({ room }) => {
const vm = useCreateAutoDisposedViewModel(() => new HistoryVisibleBannerViewModel({ room }));
export const HistoryVisibleBanner: React.FC<{ room: Room; threadId?: string | null }> = (props) => {
const vm = useCreateAutoDisposedViewModel(() => new HistoryVisibleBannerViewModel(props));
return <HistoryVisibleBannerView vm={vm} />;
};
2 changes: 1 addition & 1 deletion src/components/views/rooms/MessageComposer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -675,7 +675,7 @@ export class MessageComposer extends React.Component<IProps, IState> {

return (
<div className={classes} ref={this.ref} role="region" aria-label={_t("a11y|message_composer")}>
<HistoryVisibleBanner room={this.props.room} />
<HistoryVisibleBanner room={this.props.room} threadId={threadId} />
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[random question: would it not be easier to suppress the banner here, than having to thread threadId down into the viewmodel, and do the calculation there?]

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm inclined to agree; my excuse for not writing that way is that I'm not entirely sure where we want to draw the line on what should and should not be included in the MVVM logic as opposed to in the component itself.

I opted to do this in the MVVM logic since it's where the rest of the logic is, and even if suppression here is technically more React-esque, doing it in MVVM does keep the component logic in one place.

<div className="mx_MessageComposer_wrapper">
<UserIdentityWarning room={this.props.room} key={this.props.room.roomId} />
<ReplyPreview
Expand Down
11 changes: 8 additions & 3 deletions src/viewmodels/composer/HistoryVisibleBannerViewModel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { SettingLevel } from "../../settings/SettingLevel";

interface Props {
room: Room;
threadId?: string | null;
}

export class HistoryVisibleBannerViewModel
Expand All @@ -33,21 +34,25 @@ export class HistoryVisibleBannerViewModel
*/
private readonly acknowledgedWatcher: string;

private static readonly computeSnapshot = (room: Room): HistoryVisibleBannerViewSnapshot => {
private static readonly computeSnapshot = (
room: Room,
threadId?: string | null,
): HistoryVisibleBannerViewSnapshot => {
const featureEnabled = SettingsStore.getValue("feature_share_history_on_invite");
const acknowledged = SettingsStore.getValue("acknowledgedHistoryVisibility", room.roomId);

return {
visible:
featureEnabled &&
!threadId &&
room.hasEncryptionStateEvent() &&
room.getHistoryVisibility() !== HistoryVisibility.Joined &&
!acknowledged,
};
};

public constructor(props: Props) {
super(props, HistoryVisibleBannerViewModel.computeSnapshot(props.room));
super(props, HistoryVisibleBannerViewModel.computeSnapshot(props.room, props.threadId));

this.disposables.trackListener(props.room, RoomStateEvent.Update, () => this.setSnapshot());

Expand Down Expand Up @@ -77,7 +82,7 @@ export class HistoryVisibleBannerViewModel
);
}

this.snapshot.set(HistoryVisibleBannerViewModel.computeSnapshot(this.props.room));
this.snapshot.set(HistoryVisibleBannerViewModel.computeSnapshot(this.props.room, this.props.threadId));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,29 @@ describe("HistoryVisibleBannerViewModel", () => {
vm.dispose();
});

it("should not show the banner in threads", () => {
upsertRoomStateEvents(room, [
mkEvent({
event: true,
type: "m.room.encryption",
user: "@user1:server",
content: {},
}),
mkEvent({
event: true,
type: "m.room.history_visibility",
user: "@user1:server",
content: {
history_visibility: "shared",
},
}),
]);

const vm = new HistoryVisibleBannerViewModel({ room, threadId: "some thread ID" });
expect(vm.getSnapshot().visible).toBe(false);
vm.dispose();
});

it("should show the banner in encrypted rooms with non-joined history visibility", async () => {
upsertRoomStateEvents(room, [
mkEvent({
Expand Down
Loading