This repository has been archived by the owner on Sep 11, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 827
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
removed dead code related favorite messages panel
- Loading branch information
1 parent
9eaf48b
commit 57a6de5
Showing
12 changed files
with
262 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
/* | ||
Copyright 2015 OpenMarket Ltd | ||
Copyright 2019 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 { 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 "../messages/DateSeparator"; | ||
import EventTile from "./EventTile"; | ||
import { shouldFormContinuation } from "../../structures/MessagePanel"; | ||
import { wantsDateSeparator } from "../../../DateUtils"; | ||
import { haveRendererForEvent } from "../../../events/EventTileFactory"; | ||
|
||
interface IProps { | ||
// an event result object | ||
result: MatrixEvent; | ||
// href for the highlights in this result | ||
resultLink?: string; | ||
onHeightChanged?: () => void; | ||
permalinkCreator?: RoomPermalinkCreator; | ||
//a list containing the saved items events | ||
timeline?: MatrixEvent[]; | ||
} | ||
|
||
export default class FavouriteMessageTile extends React.Component<IProps> { | ||
static contextType = RoomContext; | ||
public context!: React.ContextType<typeof RoomContext>; | ||
|
||
constructor(props, context) { | ||
super(props, context); | ||
} | ||
|
||
public render() { | ||
const result = this.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"); | ||
const isTwelveHour = SettingsStore.getValue("showTwelveHourTimestamps"); | ||
const alwaysShowTimestamps = SettingsStore.getValue("alwaysShowTimestamps"); | ||
const threadsEnabled = SettingsStore.getValue("feature_thread"); | ||
|
||
for (let j = 0; j < this.props.timeline.length; j++) { | ||
const mxEv = this.props.timeline[j]; | ||
|
||
if (haveRendererForEvent(mxEv, this.context?.showHiddenEvents)) { | ||
// do we need a date separator since the last event? | ||
const prevEv = this.props.timeline[j - 1]; | ||
// is this a continuation of the previous message? | ||
const continuation = prevEv && | ||
!wantsDateSeparator(prevEv.getDate(), mxEv.getDate()) && | ||
shouldFormContinuation( | ||
prevEv, | ||
mxEv, | ||
this.context?.showHiddenEvents, | ||
threadsEnabled, | ||
); | ||
|
||
let lastInSection = true; | ||
const nextEv = this.props.timeline[j + 1]; | ||
if (nextEv) { | ||
const willWantDateSeparator = wantsDateSeparator(mxEv.getDate(), nextEv.getDate()); | ||
lastInSection = ( | ||
willWantDateSeparator || | ||
mxEv.getSender() !== nextEv.getSender() || | ||
!shouldFormContinuation( | ||
mxEv, | ||
nextEv, | ||
this.context?.showHiddenEvents, | ||
threadsEnabled, | ||
) | ||
); | ||
} | ||
|
||
ret.push( | ||
<EventTile | ||
key={`${eventId}+${j}`} | ||
mxEvent={mxEv} | ||
layout={layout} | ||
permalinkCreator={this.props.permalinkCreator} | ||
highlightLink={this.props.resultLink} | ||
onHeightChanged={this.props.onHeightChanged} | ||
isTwelveHour={isTwelveHour} | ||
alwaysShowTimestamps={alwaysShowTimestamps} | ||
lastInSection={lastInSection} | ||
continuation={continuation} | ||
/>, | ||
); | ||
} | ||
} | ||
|
||
return <li data-scroll-tokens={eventId}> | ||
<ol>{ ret }</ol> | ||
</li>; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.