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

Show thread notification if thread timeline is closed #9495

Merged
merged 8 commits into from
Oct 25, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
9 changes: 8 additions & 1 deletion src/Notifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,14 @@ export const Notifier = {
if (actions?.notify) {
this._performCustomEventHandling(ev);

if (SdkContextClass.instance.roomViewStore.getRoomId() === room.roomId &&
const store = SdkContextClass.instance.roomViewStore;
const isViewingRoom = store.getRoomId() === room.roomId;
const threadId: string | undefined = ev.getThread()?.id;
const isViewingThread = store.getThreadId() === threadId;

const isViewingEventTimeline = (isViewingRoom && !threadId) || (threadId && isViewingThread);
germain-gg marked this conversation as resolved.
Show resolved Hide resolved

if (isViewingEventTimeline &&
UserActivity.sharedInstance().userActiveRecently() &&
!Modal.hasDialogs()
) {
Expand Down
10 changes: 10 additions & 0 deletions src/components/structures/ThreadView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ import Spinner from "../views/elements/Spinner";
import { ComposerInsertPayload, ComposerType } from "../../dispatcher/payloads/ComposerInsertPayload";
import Heading from '../views/typography/Heading';
import { SdkContextClass } from '../../contexts/SDKContext';
import { ThreadPayload } from '../../dispatcher/payloads/ThreadPayload';

interface IProps {
room: Room;
Expand Down Expand Up @@ -132,6 +133,11 @@ export default class ThreadView extends React.Component<IProps, IState> {
metricsTrigger: undefined, // room doesn't change
});
}

dis.dispatch<ThreadPayload>({
action: Action.ViewThread,
thread_id: null,
});
}

public componentDidUpdate(prevProps) {
Expand Down Expand Up @@ -225,6 +231,10 @@ export default class ThreadView extends React.Component<IProps, IState> {
};

private async postThreadUpdate(thread: Thread): Promise<void> {
dis.dispatch<ThreadPayload>({
action: Action.ViewThread,
thread_id: thread.id,
});
thread.emit(ThreadEvent.ViewThread);
await thread.fetchInitialEvents();
this.updateThreadRelation();
Expand Down
5 changes: 5 additions & 0 deletions src/dispatcher/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,11 @@ export enum Action {
*/
ViewRoom = "view_room",

/**
* Changes thread based on payload parameters. Should be used with ThreadPayload.
*/
ViewThread = "view_thread",

/**
* Changes room based on room list order and payload parameters. Should be used with ViewRoomDeltaPayload.
*/
Expand Down
26 changes: 26 additions & 0 deletions src/dispatcher/payloads/ThreadPayload.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
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.
*/

import { ActionPayload } from "../payloads";
import { Action } from "../actions";

/* eslint-disable camelcase */
export interface ThreadPayload extends Pick<ActionPayload, "action"> {
action: Action.ViewThread;

thread_id: string | null;
}
/* eslint-enable camelcase */
19 changes: 19 additions & 0 deletions src/stores/RoomViewStore.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ import { awaitRoomDownSync } from "../utils/RoomUpgrade";
import { UPDATE_EVENT } from "./AsyncStore";
import { SdkContextClass } from "../contexts/SDKContext";
import { CallStore } from "./CallStore";
import { ThreadPayload } from "../dispatcher/payloads/ThreadPayload";

const NUM_JOIN_RETRY = 5;

Expand All @@ -66,6 +67,10 @@ interface State {
* The ID of the room currently being viewed
*/
roomId: string | null;
/**
* The ID of the thread currently being viewed
*/
threadId: string | null;
/**
* The ID of the room being subscribed to (in Sliding Sync)
*/
Expand Down Expand Up @@ -109,6 +114,7 @@ const INITIAL_STATE: State = {
joining: false,
joinError: null,
roomId: null,
threadId: null,
subscribingRoomId: null,
initialEventId: null,
initialEventPixelOffset: null,
Expand Down Expand Up @@ -200,6 +206,9 @@ export class RoomViewStore extends EventEmitter {
case Action.ViewRoom:
this.viewRoom(payload);
break;
case Action.ViewThread:
this.viewThread(payload);
break;
// for these events blank out the roomId as we are no longer in the RoomView
case 'view_welcome_page':
case Action.ViewHomePage:
Expand Down Expand Up @@ -430,6 +439,12 @@ export class RoomViewStore extends EventEmitter {
}
}

private viewThread(payload: ThreadPayload): void {
this.setState({
threadId: payload.thread_id,
});
}

private viewRoomError(payload: ViewRoomErrorPayload): void {
this.setState({
roomId: payload.room_id,
Expand Down Expand Up @@ -550,6 +565,10 @@ export class RoomViewStore extends EventEmitter {
return this.state.roomId;
}

public getThreadId(): Optional<string> {
return this.state.threadId;
}

// The event to scroll to when the room is first viewed
public getInitialEventId(): Optional<string> {
return this.state.initialEventId;
Expand Down