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

Commit 81653cf

Browse files
authored
Merge pull request #9086 from yaya-usman/favouriteMessages_Panel
Starred_Messages_Feature_Contd_II/Outreachy
2 parents 35ba389 + a53f7f8 commit 81653cf

File tree

4 files changed

+46
-2
lines changed

4 files changed

+46
-2
lines changed

src/components/views/rooms/RoomList.tsx

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,12 @@ interface IState {
7777
sublists: ITagMap;
7878
currentRoomId?: string;
7979
suggestedRooms: ISuggestedRoom[];
80+
feature_favourite_messages: boolean;
8081
}
8182

8283
export const TAG_ORDER: TagID[] = [
8384
DefaultTagID.Invite,
85+
DefaultTagID.SavedItems,
8486
DefaultTagID.Favourite,
8587
DefaultTagID.DM,
8688
DefaultTagID.Untagged,
@@ -351,6 +353,11 @@ const TAG_AESTHETICS: ITagAestheticsMap = {
351353
isInvite: false,
352354
defaultHidden: false,
353355
},
356+
[DefaultTagID.SavedItems]: {
357+
sectionLabel: _td("Saved Items"),
358+
isInvite: false,
359+
defaultHidden: false,
360+
},
354361
[DefaultTagID.DM]: {
355362
sectionLabel: _td("People"),
356363
isInvite: false,
@@ -392,6 +399,7 @@ export default class RoomList extends React.PureComponent<IProps, IState> {
392399
private dispatcherRef;
393400
private roomStoreToken: fbEmitter.EventSubscription;
394401
private treeRef = createRef<HTMLDivElement>();
402+
private favouriteMessageWatcher: string;
395403

396404
static contextType = MatrixClientContext;
397405
public context!: React.ContextType<typeof MatrixClientContext>;
@@ -402,6 +410,7 @@ export default class RoomList extends React.PureComponent<IProps, IState> {
402410
this.state = {
403411
sublists: {},
404412
suggestedRooms: SpaceStore.instance.suggestedRooms,
413+
feature_favourite_messages: SettingsStore.getValue("feature_favourite_messages"),
405414
};
406415
}
407416

@@ -410,12 +419,17 @@ export default class RoomList extends React.PureComponent<IProps, IState> {
410419
this.roomStoreToken = RoomViewStore.instance.addListener(this.onRoomViewStoreUpdate);
411420
SpaceStore.instance.on(UPDATE_SUGGESTED_ROOMS, this.updateSuggestedRooms);
412421
RoomListStore.instance.on(LISTS_UPDATE_EVENT, this.updateLists);
422+
this.favouriteMessageWatcher =
423+
SettingsStore.watchSetting("feature_favourite_messages", null, (...[,,, value]) => {
424+
this.setState({ feature_favourite_messages: value });
425+
});
413426
this.updateLists(); // trigger the first update
414427
}
415428

416429
public componentWillUnmount() {
417430
SpaceStore.instance.off(UPDATE_SUGGESTED_ROOMS, this.updateSuggestedRooms);
418431
RoomListStore.instance.off(LISTS_UPDATE_EVENT, this.updateLists);
432+
SettingsStore.unwatchSetting(this.favouriteMessageWatcher);
419433
defaultDispatcher.unregister(this.dispatcherRef);
420434
if (this.roomStoreToken) this.roomStoreToken.remove();
421435
}
@@ -545,6 +559,28 @@ export default class RoomList extends React.PureComponent<IProps, IState> {
545559
);
546560
});
547561
}
562+
private renderFavoriteMessagesList(): ReactComponentElement<typeof ExtraTile>[] {
563+
const avatar = (
564+
<RoomAvatar
565+
oobData={{
566+
name: "Favourites",
567+
}}
568+
width={32}
569+
height={32}
570+
resizeMethod="crop"
571+
/>);
572+
573+
return [
574+
<ExtraTile
575+
isMinimized={this.props.isMinimized}
576+
isSelected={false}
577+
displayName="Favourite Messages"
578+
avatar={avatar}
579+
onClick={() => ""}
580+
key="favMessagesTile_key"
581+
/>,
582+
];
583+
}
548584

549585
private renderSublists(): React.ReactElement[] {
550586
// show a skeleton UI if the user is in no rooms and they are not filtering and have no suggested rooms
@@ -558,6 +594,12 @@ export default class RoomList extends React.PureComponent<IProps, IState> {
558594
extraTiles = this.renderSuggestedRooms();
559595
}
560596

597+
if (this.state.feature_favourite_messages && orderedTagId === DefaultTagID.SavedItems) {
598+
extraTiles = this.renderFavoriteMessagesList();
599+
} else {
600+
extraTiles = null;
601+
}
602+
561603
const aesthetics = TAG_AESTHETICS[orderedTagId];
562604
if (!aesthetics) throw new Error(`Tag ${orderedTagId} does not have aesthetics`);
563605

@@ -582,7 +624,6 @@ export default class RoomList extends React.PureComponent<IProps, IState> {
582624
) {
583625
forceExpanded = true;
584626
}
585-
586627
// The cost of mounting/unmounting this component offsets the cost
587628
// of keeping it in the DOM and hiding it when it is not required
588629
return <RoomSublist

src/components/views/rooms/RoomSublist.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,7 @@ export default class RoomSublist extends React.Component<IProps, IState> {
527527
}
528528

529529
private renderMenu(): React.ReactElement {
530-
if (this.props.tagId === DefaultTagID.Suggested) return null; // not sortable
530+
if (this.props.tagId === DefaultTagID.Suggested || this.props.tagId === DefaultTagID.SavedItems) return null; // not sortable
531531

532532
let contextMenu = null;
533533
if (this.state.contextMenuPosition) {

src/i18n/strings/en_EN.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1803,6 +1803,7 @@
18031803
"Explore public rooms": "Explore public rooms",
18041804
"Add room": "Add room",
18051805
"Invites": "Invites",
1806+
"Saved Items": "Saved Items",
18061807
"Low priority": "Low priority",
18071808
"System Alerts": "System Alerts",
18081809
"Historical": "Historical",

src/stores/room-list/models.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,13 @@ export enum DefaultTagID {
2323
DM = "im.vector.fake.direct",
2424
ServerNotice = "m.server_notice",
2525
Suggested = "im.vector.fake.suggested",
26+
SavedItems = "im.vector.fake.saved_items",
2627
}
2728

2829
export const OrderedDefaultTagIDs = [
2930
DefaultTagID.Invite,
3031
DefaultTagID.Favourite,
32+
DefaultTagID.SavedItems,
3133
DefaultTagID.DM,
3234
DefaultTagID.Untagged,
3335
DefaultTagID.LowPriority,

0 commit comments

Comments
 (0)