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

Commit

Permalink
remove dead code related to favourited messages
Browse files Browse the repository at this point in the history
  • Loading branch information
yaya-usman committed Aug 16, 2022
1 parent aec87bc commit ecd568b
Show file tree
Hide file tree
Showing 9 changed files with 120 additions and 25 deletions.
1 change: 1 addition & 0 deletions src/PageTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ enum PageType {
RoomView = "room_view",
UserView = "user_view",
LegacyGroupView = "legacy_group_view",
FavouriteMessagesView = "favourite_messages_view"
}

export default PageType;
88 changes: 88 additions & 0 deletions src/components/structures/FavouriteMessagesView.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/*
Copyright 2015, 2016 OpenMarket Ltd
Copyright 2017 Vector Creations Ltd
Copyright 2018, 2019 New Vector Ltd
Copyright 2019 - 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 { MatrixClient, MatrixEvent } from 'matrix-js-sdk/src/matrix';
import React, { useContext, useRef } from 'react';

import MatrixClientContext from '../../contexts/MatrixClientContext';
import { _t } from '../../languageHandler';
import FavouriteMessageTile from '../views/rooms/FavouriteMessageTile';
import ScrollPanel from './ScrollPanel';

function getFavouriteMessagesTiles(cli: MatrixClient, favouriteMessageEvents) {
const ret = [];
let lastRoomId: string;

for (let i = (favouriteMessageEvents?.length || 0) - 1; i >= 0; i--) {
const timeline = [] as MatrixEvent[];
const resultObj = favouriteMessageEvents[i];
const roomId = resultObj.roomId;
const room = cli.getRoom(roomId);
const mxEvent = room.findEventById(resultObj.eventId);
timeline.push(mxEvent);

if (roomId !== lastRoomId) {
ret.push(<li key={mxEvent?.getId() + "-room"}>
<h2>{ _t("Room") }: { room.name }</h2>
</li>);
lastRoomId = roomId;
}

const resultLink = "#/room/"+roomId+"/"+mxEvent.getId();

ret.push(
<FavouriteMessageTile
key={mxEvent.getId()}
result={mxEvent}
resultLink={resultLink}
timeline={timeline}
/>,
);
}
return ret;
}

let favouriteMessagesPanel;

const FavouriteMessagesView = () => {
const favouriteMessageEvents= JSON.parse(
localStorage?.getItem("io_element_favouriteMessages") ?? "[]") as any[];

const favouriteMessagesPanelRef = useRef<ScrollPanel>();
const cli = useContext<MatrixClient>(MatrixClientContext);

if (favouriteMessageEvents?.length === 0) {
favouriteMessagesPanel = (<h2 className="mx_RoomView_topMarker">{ _t("No Saved Messages") }</h2>);
} else {
favouriteMessagesPanel = (
<ScrollPanel
ref={favouriteMessagesPanelRef}
className="mx_RoomView_searchResultsPanel "
>
{ getFavouriteMessagesTiles(cli, favouriteMessageEvents) }
</ScrollPanel>
);
}

return (
<> { favouriteMessagesPanel } </>
);
};

export default FavouriteMessagesView;
1 change: 1 addition & 0 deletions src/components/structures/LeftPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,7 @@ export default class LeftPanel extends React.Component<IProps, IState> {
onResize={this.refreshStickyHeaders}
onListCollapse={this.refreshStickyHeaders}
ref={this.roomListRef}
pageType={this.props.pageType}
/>;

const containerClasses = classNames({
Expand Down
5 changes: 5 additions & 0 deletions src/components/structures/LoggedInView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ import LegacyGroupView from "./LegacyGroupView";
import { IConfigOptions } from "../../IConfigOptions";
import LeftPanelLiveShareWarning from '../views/beacon/LeftPanelLiveShareWarning';
import { UserOnboardingPage } from '../views/user-onboarding/UserOnboardingPage';
import FavouriteMessagesView from './FavouriteMessagesView';

// We need to fetch each pinned message individually (if we don't already have it)
// so each pinned message may trigger a request. Limit the number per room for sanity.
Expand Down Expand Up @@ -645,6 +646,10 @@ class LoggedInView extends React.Component<IProps, IState> {
case PageTypes.LegacyGroupView:
pageElement = <LegacyGroupView groupId={this.props.currentGroupId} />;
break;

case PageTypes.FavouriteMessagesView:
pageElement = <FavouriteMessagesView />;
break;
}

const wrapperClasses = classNames({
Expand Down
12 changes: 12 additions & 0 deletions src/components/structures/MatrixChat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -803,6 +803,9 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
hideAnalyticsToast();
SettingsStore.setValue("pseudonymousAnalyticsOptIn", null, SettingLevel.ACCOUNT, true);
break;
case Action.ViewFavouriteMessages:
this.viewFavouriteMessages();
break;
case Action.PseudonymousAnalyticsReject:
hideAnalyticsToast();
SettingsStore.setValue("pseudonymousAnalyticsOptIn", null, SettingLevel.ACCOUNT, false);
Expand Down Expand Up @@ -1007,6 +1010,11 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
this.themeWatcher.recheck();
}

private viewFavouriteMessages() {
this.setPage(PageType.FavouriteMessagesView);
this.notifyNewScreen('favourite_messages');
}

private viewUser(userId: string, subAction: string) {
// Wait for the first sync so that `getRoom` gives us a room object if it's
// in the sync response
Expand Down Expand Up @@ -1704,6 +1712,10 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
dis.dispatch({
action: Action.ViewHomePage,
});
} else if (screen === 'favourite_messages') {
dis.dispatch({
action: Action.ViewFavouriteMessages,
});
} else if (screen === 'start') {
this.showScreen('home');
dis.dispatch({
Expand Down
21 changes: 4 additions & 17 deletions src/components/views/rooms/RoomList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import React, { ComponentType, createRef, ReactComponentElement, RefObject } fro

import { IState as IRovingTabIndexState, RovingTabIndexProvider } from "../../../accessibility/RovingTabIndex";
import MatrixClientContext from "../../../contexts/MatrixClientContext";
import { TimelineRenderingType } from "../../../contexts/RoomContext";
import { shouldShowComponent } from "../../../customisations/helpers/UIComponents";
import { Action } from "../../../dispatcher/actions";
import defaultDispatcher from "../../../dispatcher/dispatcher";
Expand All @@ -31,6 +30,7 @@ import { ViewRoomPayload } from "../../../dispatcher/payloads/ViewRoomPayload";
import { useEventEmitterState } from "../../../hooks/useEventEmitter";
import { _t, _td } from "../../../languageHandler";
import { MatrixClientPeg } from "../../../MatrixClientPeg";
import PageType from "../../../PageTypes";
import PosthogTrackers from "../../../PosthogTrackers";
import SettingsStore from "../../../settings/SettingsStore";
import { UIComponent } from "../../../settings/UIFeature";
Expand Down Expand Up @@ -72,14 +72,14 @@ interface IProps {
resizeNotifier: ResizeNotifier;
isMinimized: boolean;
activeSpace: SpaceKey;
pageType: PageType;
}

interface IState {
sublists: ITagMap;
currentRoomId?: string;
suggestedRooms: ISuggestedRoom[];
feature_favourite_messages: boolean;
timelineRenderingType: TimelineRenderingType;
}

export const TAG_ORDER: TagID[] = [
Expand Down Expand Up @@ -413,7 +413,6 @@ export default class RoomList extends React.PureComponent<IProps, IState> {
sublists: {},
suggestedRooms: SpaceStore.instance.suggestedRooms,
feature_favourite_messages: SettingsStore.getValue("feature_favourite_messages"),
timelineRenderingType: TimelineRenderingType.Room,
};
}

Expand Down Expand Up @@ -457,8 +456,6 @@ export default class RoomList extends React.PureComponent<IProps, IState> {
metricsViaKeyboard: true,
});
}
// RoomViewStore.instance.setFavouriteStatus(false);
// console.log(RoomViewStore.instance.getFavouriteStatus());
} else if (payload.action === Action.PstnSupportUpdated) {
this.updateLists();
}
Expand Down Expand Up @@ -522,7 +519,6 @@ export default class RoomList extends React.PureComponent<IProps, IState> {
this.props.onResize();
});
}
RoomViewStore.instance.setFavouriteStatus(false);
};

private renderSuggestedRooms(): ReactComponentElement<typeof ExtraTile>[] {
Expand Down Expand Up @@ -576,23 +572,14 @@ export default class RoomList extends React.PureComponent<IProps, IState> {
resizeMethod="crop"
/>);

// const opts = { createOpts: {
// name: "Favourites",
// } };

// const callFavRoomMethod = async () => {
// const favouriteRoomId = await createRoom(opts);
// console.log("FAVOURITE FAKE ROOMID", favouriteRoomId);
// };

const onFavouriteClicked = () => {
RoomViewStore.instance.setFavouriteStatus(true);
defaultDispatcher.dispatch({ action: Action.ViewFavouriteMessages });
};

return [
<ExtraTile
isMinimized={this.props.isMinimized}
isSelected={false}
isSelected={this.props.pageType === PageType.FavouriteMessagesView}
displayName="Favourite Messages"
avatar={avatar}
onClick={onFavouriteClicked}
Expand Down
5 changes: 5 additions & 0 deletions src/dispatcher/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -331,4 +331,9 @@ export enum Action {
* Fired when we want to view a thread, either a new one or an existing one
*/
ShowThread = "show_thread",

/**
* Fired when we want to view favourited messages panel
*/
ViewFavouriteMessages = "view_favourite_messages",
}
1 change: 1 addition & 0 deletions src/i18n/strings/en_EN.json
Original file line number Diff line number Diff line change
Expand Up @@ -3109,6 +3109,7 @@
"Pause": "Pause",
"Play": "Play",
"Couldn't load page": "Couldn't load page",
"No Saved Messages": "No Saved Messages",
"Drop file here to upload": "Drop file here to upload",
"You must <a>register</a> to use this functionality": "You must <a>register</a> to use this functionality",
"You must join the room to see its files": "You must join the room to see its files",
Expand Down
11 changes: 3 additions & 8 deletions src/stores/RoomViewStore.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -164,12 +164,6 @@ export class RoomViewStore extends Store<ActionPayload> {
this.__emitChange();
}

public setFavouriteStatus = (val: boolean) => {
dis.dispatch({ action: "view_favourite_messages", val });
};

public getFavouriteStatus = () => this.state.isFavouriteClicked;

protected __onDispatch(payload): void { // eslint-disable-line @typescript-eslint/naming-convention
switch (payload.action) {
// view_room:
Expand All @@ -191,9 +185,10 @@ export class RoomViewStore extends Store<ActionPayload> {
wasContextSwitch: false,
});
break;
case "view_favourite_messages":
case Action.ViewFavouriteMessages:
this.setState({
isFavouriteClicked: payload.val,
roomId: null,
roomAlias: null,
});
break;
case Action.ViewRoomError:
Expand Down

0 comments on commit ecd568b

Please sign in to comment.