feat: container children reordering, correctly show continue watching

This commit is contained in:
Aleksi Lassila
2025-03-31 01:27:36 +03:00
parent 23fec9d8df
commit f58bf4f8f3
12 changed files with 155 additions and 144 deletions

View File

@@ -5,10 +5,11 @@ import { libraryProviders } from './library.providers';
import { LibraryService } from './library.service';
import { UsersModule } from 'src/users/users.module';
import { SourceProvidersModule } from 'src/source-providers/source-providers.module';
import { playStateProviders } from '../play-state/play-state.providers';
@Module({
imports: [UsersModule, MetadataModule, SourceProvidersModule],
providers: [...libraryProviders, LibraryService],
providers: [...libraryProviders, ...playStateProviders, LibraryService],
controllers: [LibraryController],
exports: [LibraryService],
})

View File

@@ -18,12 +18,15 @@ import {
} from './library.dto';
import { LibraryItem } from './library.entity';
import { USER_LIBRARY_REPOSITORY } from './library.providers';
import { USER_PLAY_STATE_REPOSITORY } from '../play-state/play-state.providers';
@Injectable()
export class LibraryService {
constructor(
@Inject(USER_LIBRARY_REPOSITORY)
private readonly libraryRepository: Repository<LibraryItem>,
@Inject(USER_PLAY_STATE_REPOSITORY)
private readonly playStateRepository: Repository<PlayState>,
private readonly metadataService: MetadataService,
private readonly mediaSourceService: MediaSourcesService,
) {
@@ -345,6 +348,23 @@ export class LibraryService {
tmdbId,
mediaType,
});
const lastPlayedAt = await this.playStateRepository
.find({
where: {
userId,
tmdbId,
},
})
.then((states) =>
states.map((s) => new Date(s.lastPlayedAt).getTime() || 0),
)
.then((dates) => Math.max(...dates));
if (lastPlayedAt) {
libraryItem.lastPlayedAt = new Date(lastPlayedAt);
}
await this.libraryRepository.save(libraryItem);
}
@@ -401,7 +421,7 @@ export class LibraryService {
mediaType: mediaType === 'movie' ? MediaType.Movie : MediaType.Series,
watched,
playStates,
lastPlayState: playStates?.[0],
lastPlayState: playStates ? playStates[playStates.length - 1] : undefined,
tmdbItem: {
id: movieMetadata?.tmdbMovie.id ?? seriesMetadata?.tmdbSeries.id,
poster_path: