mattermost-mobile/app/selectors/threads.ts
Anurag Shivarathri a81b56212e
MM-38784, MM-38409 New messages line in threads screen & Pull to refresh for global threads screen (#5690)
* New messages line in threads & Pull to refresh for global threads

* Updated snapshot

* Using postlist's RefreshControl component

* Updated threadlist snapshot

* Reverting snapshot

* Updated Snapshots

* Snapshots updated

* Added 'thread last viewed at' to handle new messages line correctly

* Lint fix

* Updated snapshots

* Reverted comparision check

* Remove unused code

* Batching actions

* Do not add new message line for self messages

Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
2021-10-07 15:14:34 +05:30

23 lines
1 KiB
TypeScript

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import {getThread} from '@mm-redux/selectors/entities/threads';
import type {GlobalState} from '@mm-redux/types/store';
import type {UserThread} from '@mm-redux/types/threads';
import type {$ID} from '@mm-redux/types/utilities';
export function getThreadLastViewedAt(state: GlobalState, threadId: $ID<UserThread>): number {
if (state.views.threads.lastViewedAt[threadId]) {
// timestamp - 1, to properly mark "new messages" in threads when manually unread as lastViewedAt is set to the post's created timestamp
return state.views.threads.lastViewedAt[threadId] - 1;
}
return getThread(state, threadId)?.last_viewed_at || 0;
}
export function getViewingGlobalThreads(state: GlobalState): boolean {
return state.views.threads.viewingGlobalThreads;
}
export function getViewingGlobalThreadsUnread(state: GlobalState): boolean {
return state.views.threads.viewingGlobalThreadsUnreads;
}