Skip to content

Commit

Permalink
Merge branch 'develop' into dbudzins/replace-depcheck
Browse files Browse the repository at this point in the history
  • Loading branch information
dbudzins authored Mar 18, 2024
2 parents 9456b3d + d37905d commit 5701067
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 19 deletions.
12 changes: 9 additions & 3 deletions docs/features/user-watchlists.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,16 @@ Example data format
}
```

### Max 48 items
### Max amount of items

Cleeng customer `externalData` attribute has maxsize of 5000 symbols.
#### JWP

The length of one stringified object of History equals to 52 symbols, one Favorites object equals to 22 symbols. Taking into account only History objects, we get 5000 / 52 = ~96, so 48 for Favorites and 48 for History. We also leave some extra space for possible further updates.
For JWP the limit is 48 items for Favorites and 48 for Watch History.

#### Cleeng

Cleeng customer `externalData` attribute has maxsize of 4000 symbols.

The length of one stringified object of History equals to 41 symbols, one Favorites object equals to 22 symbols. Taking into account only History objects, we get 4000 / 41 = ~97.56, so 48 for Favorites and 48 for Watch History. We also leave some extra space for possible further updates.

We rotate the oldest continue watching object to the first item position after its progress property gets a new value.
6 changes: 3 additions & 3 deletions packages/common/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@ export const VideoProgressMinMax = {

export const PLAYLIST_LIMIT = 25;

// The externalData attribute of Cleeng can contain max 5000 characters
export const MAX_WATCHLIST_ITEMS_COUNT = 48;

export const ADYEN_TEST_CLIENT_KEY = 'test_I4OFGUUCEVB5TI222AS3N2Y2LY6PJM3K';

export const ADYEN_LIVE_CLIENT_KEY = 'live_BQDOFBYTGZB3XKF62GBYSLPUJ4YW2TPL';
Expand Down Expand Up @@ -62,6 +59,8 @@ export const STALE_TIME = 60 * 1000 * 20;

export const CARD_ASPECT_RATIOS = ['1:1', '2:1', '2:3', '4:3', '5:3', '16:9', '9:13', '9:16'] as const;

export const MAX_WATCHLIST_ITEMS_COUNT = 48; // Default value

export const DEFAULT_FEATURES = {
canUpdateEmail: false,
canSupportEmptyFullName: false,
Expand All @@ -73,6 +72,7 @@ export const DEFAULT_FEATURES = {
canShowReceipts: false,
hasSocialURLs: false,
hasNotifications: false,
watchListSizeLimit: MAX_WATCHLIST_ITEMS_COUNT,
};

export const simultaneousLoginWarningKey = 'simultaneous_logins';
Expand Down
2 changes: 1 addition & 1 deletion packages/common/src/controllers/FavoritesController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export default class FavoritesController {
}

// If we exceed the max available number of favorites, we show a warning
if (this.favoritesService.hasReachedFavoritesLimit(favorites)) {
if (favorites.length > this.favoritesService.getMaxFavoritesCount()) {
setWarning(i18next.t('video:favorites_warning', { maxCount: this.favoritesService.getMaxFavoritesCount() }));
return;
}
Expand Down
9 changes: 2 additions & 7 deletions packages/common/src/services/FavoriteService.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { inject, injectable } from 'inversify';
import { object, array, string } from 'yup';

import { MAX_WATCHLIST_ITEMS_COUNT } from '../constants';
import type { Favorite, SerializedFavorite } from '../../types/favorite';
import type { PlaylistItem } from '../../types/playlist';
import type { Customer } from '../../types/account';
import { getNamedModule } from '../modules/container';
import { INTEGRATION_TYPE } from '../modules/types';
import { logDev } from '../utils/common';
import { MAX_WATCHLIST_ITEMS_COUNT } from '../constants';

import ApiService from './ApiService';
import StorageService from './StorageService';
Expand All @@ -21,7 +21,6 @@ const schema = array(

@injectable()
export default class FavoriteService {
private MAX_FAVORITES_COUNT = 48;
private PERSIST_KEY_FAVORITES = 'favorites';

private readonly apiService;
Expand Down Expand Up @@ -89,11 +88,7 @@ export default class FavoriteService {
};

getMaxFavoritesCount = () => {
return this.MAX_FAVORITES_COUNT;
};

hasReachedFavoritesLimit = (favorites: Favorite[]) => {
return favorites?.length >= MAX_WATCHLIST_ITEMS_COUNT;
return this.accountService?.features?.watchListSizeLimit || MAX_WATCHLIST_ITEMS_COUNT;
};

createFavorite = (item: PlaylistItem): Favorite => {
Expand Down
9 changes: 6 additions & 3 deletions packages/common/src/services/WatchHistoryService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import type { Customer } from '../../types/account';
import { getNamedModule } from '../modules/container';
import { INTEGRATION_TYPE } from '../modules/types';
import { logDev } from '../utils/common';
import { MAX_WATCHLIST_ITEMS_COUNT } from '../constants';

import ApiService from './ApiService';
import StorageService from './StorageService';
Expand All @@ -22,7 +23,6 @@ const schema = array(
@injectable()
export default class WatchHistoryService {
private PERSIST_KEY_WATCH_HISTORY = 'history';
private MAX_WATCH_HISTORY_COUNT = 48;

private readonly apiService;
private readonly storageService;
Expand Down Expand Up @@ -145,6 +145,10 @@ export default class WatchHistoryService {
} as WatchHistoryItem;
};

getMaxWatchHistoryCount = () => {
return this.accountService?.features?.watchListSizeLimit || MAX_WATCHLIST_ITEMS_COUNT;
};

/**
* If we already have an element with continue watching state, we:
* 1. Update the progress
Expand All @@ -163,8 +167,7 @@ export default class WatchHistoryService {
});

updatedHistory.unshift(watchHistoryItem);

updatedHistory.splice(this.MAX_WATCH_HISTORY_COUNT);
updatedHistory.splice(this.getMaxWatchHistoryCount());

return updatedHistory;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export type AccountServiceFeatures = {
readonly canShowReceipts: boolean;
readonly hasSocialURLs: boolean;
readonly hasNotifications: boolean;
readonly watchListSizeLimit: number;
};

export default abstract class AccountService {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,11 @@ export default class CleengAccountService extends AccountService {
canExportAccountData: false,
canDeleteAccount: false,
canUpdatePaymentMethod: true,
canShowReceipts: true,
canShowReceipts: false,
hasSocialURLs: false,
hasNotifications: false,
// The 'externalData' attribute of Cleeng can contain max 4000 characters
watchListSizeLimit: 48,
});

this.cleengService = cleengService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ export default class JWPAccountService extends AccountService {
canDeleteAccount: true,
hasNotifications: true,
hasSocialURLs: true,
// Limit of media_ids length passed to the /apps/watchlists endpoint
watchListSizeLimit: 48,
});

this.storageService = storageService;
Expand Down
2 changes: 1 addition & 1 deletion packages/hooks-react/src/useWatchHistoryListener.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export const useWatchHistoryListener = (player: jwplayer.JWPlayer | undefined, i
// live streams have a negative duration, we ignore these for now
if (event.duration < 0) return;

const progress = event.position / event.duration;
const progress = Number((event.position / event.duration).toFixed(5));

if (!isNaN(progress) && isFinite(progress)) {
queuedWatchProgress.current = {
Expand Down

0 comments on commit 5701067

Please sign in to comment.