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

Display favourite messages in a room-like view #9719

Closed
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
1 change: 1 addition & 0 deletions res/css/_components.pcss
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
@import "./structures/_CompatibilityPage.pcss";
@import "./structures/_ContextualMenu.pcss";
@import "./structures/_ErrorMessage.pcss";
@import "./structures/_FavouriteMessagesView.pcss";
@import "./structures/_FileDropTarget.pcss";
@import "./structures/_FilePanel.pcss";
@import "./structures/_GenericDropdownMenu.pcss";
Expand Down
96 changes: 96 additions & 0 deletions res/css/structures/_FavouriteMessagesView.pcss
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
/*
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_FavMessagesHeader {
position: fixed;
top: 0;
left: 0;
width: 100%;
flex: 0 0 50px;
border-bottom: 1px solid $primary-hairline-color;
background-color: $background;
z-index: 999;
Copy link
Contributor

Choose a reason for hiding this comment

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

Is that necessary ? 😅

}

.mx_FavMessagesHeader_Wrapper {
height: 44px;
display: flex;
align-items: center;
min-width: 0;
margin: 0 20px 0 16px;
Copy link
Contributor

Choose a reason for hiding this comment

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

Use $spacing-*

padding-top: 8px;
Copy link
Contributor

Choose a reason for hiding this comment

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

Use $spacing-*

Copy link
Contributor

Choose a reason for hiding this comment

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

Can you use spacing variables, where possible?
Like for instance here $spacing-8.

border-bottom: 1px solid $system;
justify-content: space-between;

.mx_FavMessagesHeader_Wrapper_left {
display: flex;
align-items: center;
flex: 0.4;

& > span {
color: $primary-content;
font-weight: $font-semi-bold;
font-size: $font-18px;
margin: 0 8px;
Copy link
Contributor

Choose a reason for hiding this comment

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

We can use here $spacing-8

}
}

.mx_FavMessagesHeader_Wrapper_right {
display: flex;
align-items: center;
flex: 0.6;
justify-content: flex-end;
}
}

.mx_FavMessagesHeader_sortButton::before {
mask-image: url("$(res)/img/element-icons/room/sort-twoway.svg");
Copy link
Contributor

Choose a reason for hiding this comment

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

Same comment about the mask

}

.mx_FavMessagesHeader_clearAllButton::before {
mask-image: url("$(res)/img/element-icons/room/clear-all.svg");
Copy link
Contributor

Choose a reason for hiding this comment

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

Same comment about the mask

}

.mx_FavMessagesHeader_cancelButton {
background-color: $alert;
mask: url("$(res)/img/cancel.svg");
Copy link
Contributor

@florianduros florianduros Jan 20, 2023

Choose a reason for hiding this comment

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

We are trying to get rid of mask in favour of the svg as a React component directly

Example of use:
https://github.com/matrix-org/matrix-react-sdk/blob/develop/src/components/views/rooms/wysiwyg_composer/components/FormattingButtons.tsx#L21

mask-repeat: no-repeat;
mask-position: center;
mask-size: 17px;
padding: 9px;
margin: 0 12px 0 3px;
Copy link
Contributor

Choose a reason for hiding this comment

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

Use $spacing-*

cursor: pointer;
}

.mx_FavMessagesHeader_Search {
width: 70%;
}

.mx_FavouriteMessages_emptyMarker {
display: flex;
align-items: center;
justify-content: center;
font-size: 25px;
font-weight: 600;
}

.mx_FavouriteMessages_scrollPanel {
margin-top: 25px;
}

.mx_ClearDialog {
width: 100%;
}
1 change: 1 addition & 0 deletions res/img/element-icons/room/clear-all.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions res/img/element-icons/room/sort-twoway.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions src/PageTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ enum PageType {
HomePage = "home_page",
RoomView = "room_view",
UserView = "user_view",
FavouriteMessagesView = "favourite_messages_view",
}

export default PageType;
1 change: 1 addition & 0 deletions src/PosthogTrackers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ const loggedInPageTypeMap: Record<PageType, ScreenName> = {
[PageType.HomePage]: "Home",
[PageType.RoomView]: "Room",
[PageType.UserView]: "User",
[PageType.FavouriteMessagesView]: "FavouriteMessages",
};

export default class PosthogTrackers {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
Copyright 2022 The Matrix.org Foundation C.I.C.
Copy link
Contributor

Choose a reason for hiding this comment

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

It's already 2023 🍾


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, { FC, useCallback } from "react";

import useFavouriteMessages from "../../../hooks/useFavouriteMessages";
import { _t } from "../../../languageHandler";
import BaseDialog from "../../views/dialogs/BaseDialog";
import { IDialogProps } from "../../views/dialogs/IDialogProps";
import DialogButtons from "../../views/elements/DialogButtons";

/**
* A dialog for confirming a clearing of favourite messages.
*/
const ConfirmClearFavouritesDialog: FC<IDialogProps> = (props: IDialogProps) => {
const { clearFavouriteMessages } = useFavouriteMessages();

const onConfirmClick = useCallback(() => {
clearFavouriteMessages();
props.onFinished();
}, [props, clearFavouriteMessages]);

return (
<BaseDialog
className="mx_TextInputDialog mx_ClearDialog"
onFinished={props.onFinished}
title={_t("Confirm Removal")}
>
<div className="mx_Dialog_content">
<div className="mx_TextInputDialog_label">
<span> {_t("Are you sure you wish to clear all your favourite messages? ")} </span>
</div>
</div>
<DialogButtons
primaryButton={_t("Confirm")}
onPrimaryButtonClick={onConfirmClick}
onCancel={props.onFinished}
hasCancel={true}
/>
</BaseDialog>
);
};

export default ConfirmClearFavouritesDialog;
Copy link
Contributor

Choose a reason for hiding this comment

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

Applies to the entire PR: We should use named exports.

Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
/*
Copyright 2023 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, { FC } from "react";
import { MatrixEvent } from "matrix-js-sdk/src/models/event";

import RoomContext from "../../../contexts/RoomContext";
import SettingsStore from "../../../settings/SettingsStore";
import { RoomPermalinkCreator } from "../../../utils/permalinks/Permalinks";
import DateSeparator from "../../views/messages/DateSeparator";
import EventTile from "../../views/rooms/EventTile";
import { shouldFormContinuation } from "../MessagePanel";
import { wantsDateSeparator } from "../../../DateUtils";
import { haveRendererForEvent } from "../../../events/EventTileFactory";
import { Layout } from "../../../settings/enums/Layout";
import { FavouriteMessagesStore } from "../../../stores/FavouriteMessagesStore";

interface IProps {
// an event result object
result: MatrixEvent;
// href for the highlights in this result
resultLink: string;
// a list of strings to be highlighted in the results
searchHighlights?: string[];
onHeightChanged?: () => void;
permalinkCreator?: RoomPermalinkCreator;
//a list containing the saved items events
timeline: MatrixEvent[];

// Provide this to use a different store for favourite messages
// e.g. in tests. If not supplied, we use the global default.
favouriteMessagesStore?: FavouriteMessagesStore;
}

const FavouriteMessageTile: FC<IProps> = (props: IProps) => {
let context!: React.ContextType<typeof RoomContext>;
Copy link
Contributor

Choose a reason for hiding this comment

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

context doesn't seem to be set anywhere.


const result = props.result;
const eventId = result.getId();

const ts1 = result?.getTs();
const ret = [<DateSeparator key={ts1 + "-search"} roomId={result.getRoomId()!} ts={ts1} />];
const layout = SettingsStore.getValue<Layout>("layout");
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe, we can use useSettingValue here. It will allow to have a live reload when the value in the settings is changed. It will trigger a rerender of the component

const isTwelveHour = !!SettingsStore.getValue<boolean>("showTwelveHourTimestamps");
const alwaysShowTimestamps = !!SettingsStore.getValue<boolean>("alwaysShowTimestamps");
const threadsEnabled = !!SettingsStore.getValue<boolean>("feature_threadenabled");

for (let j = 0; j < props?.timeline.length; j++) {
const mxEv = props?.timeline[j];
const highlights = props?.searchHighlights;

if (haveRendererForEvent(mxEv, context?.showHiddenEvents)) {
// do we need a date separator since the last event?
const prevEv = props.timeline[j - 1];
// is this a continuation of the previous message?
const continuation =
!dateSeparator(prevEv, mxEv) &&
shouldFormContinuation(prevEv, mxEv, context?.showHiddenEvents, threadsEnabled);

let lastInSection = true;
const nextEv = props?.timeline[j + 1];
if (nextEv) {
lastInSection =
Copy link
Contributor

Choose a reason for hiding this comment

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

const lastInSection = nextEv && 
                 ( dateSeparator(mxEv, nextEv) ||
                    mxEv.getSender() !== nextEv.getSender() ||
                    !shouldFormContinuation(mxEv, nextEv, context?.showHiddenEvents, threadsEnabled)
                    )

dateSeparator(mxEv, nextEv) ||
mxEv.getSender() !== nextEv.getSender() ||
!shouldFormContinuation(mxEv, nextEv, context?.showHiddenEvents, threadsEnabled);
}

ret.push(
<EventTile
key={`${eventId}+${j}`}
mxEvent={mxEv}
layout={layout}
highlights={highlights}
permalinkCreator={props.permalinkCreator}
highlightLink={props.resultLink}
onHeightChanged={props.onHeightChanged}
isTwelveHour={isTwelveHour}
alwaysShowTimestamps={alwaysShowTimestamps}
lastInSection={lastInSection}
continuation={continuation}
isFavouritesView={true}
favouriteMessagesStore={props.favouriteMessagesStore}
/>,
);
}
}

return (
<li data-scroll-tokens={eventId}>
<ol>{ret}</ol>
</li>
);
};

function dateSeparator(event1: MatrixEvent | undefined, event2: MatrixEvent | undefined): boolean {
if (!event1 || !event2) {
return false;
}
const date1 = event1.getDate();
const date2 = event2.getDate();
if (!date1 || !date2) {
return false;
}
return wantsDateSeparator(date1, date2);
}

export default FavouriteMessageTile;
Loading