* Added type column to scheduled post and draft table * removed console log * fixed a test * fixes * Restored ununtended changes * Added BoR indicator in scheduled posts * used fixed padding * used Tag for BoR chip * test: add comprehensive tests for formatTime humanReadable parameter * test: add initial test file for burn on read label component * test: add comprehensive tests for BoRLabel component * test: update BoRLabel tests to use deep rendering and remove mocks * test: fix renderWithIntl import and usage in BoRLabel test * refactor: Update BoRLabel tests to use renderWithIntl and remove formatTime mock * refactor: simplify imports and remove renderWithIntl mock in test file * Updated tests * reset unintended changes * reset unintended changes * reset unintended changes * i18n fixes * fixed tests * Matched BOR tag size to post priority tag * Review fixes
34 lines
1.4 KiB
TypeScript
34 lines
1.4 KiB
TypeScript
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
// See LICENSE.txt for license information.
|
|
|
|
import {Post} from '@constants';
|
|
import {ensureNumber} from '@utils/types';
|
|
|
|
import type DraftModel from '@typings/database/models/servers/draft';
|
|
import type PostModel from '@typings/database/models/servers/post';
|
|
import type ScheduledPostModel from '@typings/database/models/servers/scheduled_post';
|
|
import type UserModel from '@typings/database/models/servers/user';
|
|
|
|
export function isBoRPost(post: PostModel | DraftModel | ScheduledPostModel | Post): boolean {
|
|
return Boolean(post.type && post.type === Post.POST_TYPES.BURN_ON_READ);
|
|
}
|
|
|
|
export function isUnrevealedBoRPost(post: Post | PostModel): boolean {
|
|
return isBoRPost(post) && Boolean(!post.metadata?.expire_at);
|
|
}
|
|
|
|
export function isOwnBoRPost(post: PostModel, currentUser?: UserModel): boolean {
|
|
return isBoRPost(post) && Boolean(currentUser && post.userId === currentUser.id);
|
|
}
|
|
|
|
function isBoRPostExpiredForMe(post: PostModel): boolean {
|
|
return Boolean(post.metadata?.expire_at) && post.metadata!.expire_at! < Date.now();
|
|
}
|
|
|
|
function isBorPostExpiredForAll(post: PostModel): boolean {
|
|
return Boolean(post.props?.expire_at) && ensureNumber(post.props!.expire_at!) < Date.now();
|
|
}
|
|
|
|
export function isExpiredBoRPost(post: PostModel): boolean {
|
|
return isBoRPost(post) && (isBorPostExpiredForAll(post) || isBoRPostExpiredForMe(post));
|
|
}
|