ActivityPub-federated video streaming platform using P2P directly in your web browser
Group channel activities
Chocobozzze5351a0eb09b
diff --git a/client/src/app/+my-library/+my-video-channels/edit/pages/video-channel-activities.component.html b/client/src/app/+my-library/+my-video-channels/edit/pages/video-channel-activities.component.htmlindex 771fa32ae3..a8da1f7311 100644--- a/client/src/app/+my-library/+my-video-channels/edit/pages/video-channel-activities.component.html+++ b/client/src/app/+my-library/+my-video-channels/edit/pages/video-channel-activities.component.html@@ -11,6 +11,8 @@<div class="activities" myInfiniteScroller (nearOfBottom)="onNearOfBottom()" [dataObservable]="onDataSubject.asObservable()">@for (activity of activities; track activity.id) {+ <my-date-group-label [date]="activity.createdAt" [store]="groupByDateStore"></my-date-group-label>+<div class="activity-container"><my-video-channel-activity [activity]="activity"></my-video-channel-activity></div>diff --git a/client/src/app/+my-library/+my-video-channels/edit/pages/video-channel-activities.component.scss b/client/src/app/+my-library/+my-video-channels/edit/pages/video-channel-activities.component.scssindex 761f3e53a7..bbb5641849 100644--- a/client/src/app/+my-library/+my-video-channels/edit/pages/video-channel-activities.component.scss+++ b/client/src/app/+my-library/+my-video-channels/edit/pages/video-channel-activities.component.scss@@ -11,3 +11,23 @@background-color: pvar(--bg-secondary-350);}}++my-date-group-label:not(.date-displayed) {+ display: none;+}++my-date-group-label.date-displayed {+ color: pvar(--fg-300);+ font-weight: $font-bold;+ display: block;++ @include padding-bottom(1.5rem);+ @include font-size(18px);++ &:not(:first-child) {+ border-top: 1px solid pvar(--bg-secondary-500);++ @include padding-top(1.5rem);+ @include margin-top(1.5rem);+ }+}diff --git a/client/src/app/+my-library/+my-video-channels/edit/pages/video-channel-activities.component.ts b/client/src/app/+my-library/+my-video-channels/edit/pages/video-channel-activities.component.tsindex 2cf012a121..5e454ef8da 100644--- a/client/src/app/+my-library/+my-video-channels/edit/pages/video-channel-activities.component.ts+++ b/client/src/app/+my-library/+my-video-channels/edit/pages/video-channel-activities.component.ts@@ -10,6 +10,7 @@ import { Subject, Subscription } from 'rxjs'import { VideoChannelEditControllerService } from '../video-channel-edit-controller.service'import { VideoChannelEdit } from '../video-channel-edit.model'import { VideoChannelActivityComponent } from './video-channel-activity.component'+import { DateGroupLabelComponent } from '@app/shared/shared-main/date/date-group-label.component'@Component({selector: 'my-video-channel-activities',@@ -21,7 +22,8 @@ import { VideoChannelActivityComponent } from './video-channel-activity.componenReactiveFormsModule,GlobalIconComponent,InfiniteScrollerDirective,- VideoChannelActivityComponent+ VideoChannelActivityComponent,+ DateGroupLabelComponent]})export class VideoChannelActivitiesComponent implements OnInit, OnDestroy {@@ -41,6 +43,8 @@ export class VideoChannelActivitiesComponent implements OnInit, OnDestroy {onDataSubject = new Subject<any[]>()+ groupByDateStore = new Set<number>()+private storeSub: SubscriptionngOnInit () {diff --git a/client/src/app/+my-library/+my-video-channels/edit/pages/video-channel-activity.component.html b/client/src/app/+my-library/+my-video-channels/edit/pages/video-channel-activity.component.htmlindex cd47ee86ed..76dc1541c9 100644--- a/client/src/app/+my-library/+my-video-channels/edit/pages/video-channel-activity.component.html+++ b/client/src/app/+my-library/+my-video-channels/edit/pages/video-channel-activity.component.html@@ -6,13 +6,13 @@@switch (a.targetType.id) {@case (1) { <!-- VideoChannelActivityTargetType.VIDEO) --><ng-container i18n>- <strong>{{ account }}</strong> published video <a [routerLink]="[ '/w', a.video.shortUUID ]">{{ a.video.name }}</a>+ <strong>{{ account }}</strong> created video <a [routerLink]="[ '/w', a.video.shortUUID ]">{{ a.video.name }}</a></ng-container>}@case (2) { <!-- VideoChannelActivityTargetType.PLAYLIST) --><ng-container i18n>- <strong>{{ account }}</strong> published playlist <a [routerLink]="[ '/my-library/video-playlists/', a.playlist.shortUUID ]">{{ a.playlist.name }}</a>+ <strong>{{ account }}</strong> created playlist <a [routerLink]="[ '/my-library/video-playlists/', a.playlist.shortUUID ]">{{ a.playlist.name }}</a></ng-container>}diff --git a/client/src/app/shared/shared-main/date/date-group-label.component.html b/client/src/app/shared/shared-main/date/date-group-label.component.htmlnew file mode 100644index 0000000000..2ec25ffc8e--- /dev/null+++ b/client/src/app/shared/shared-main/date/date-group-label.component.html@@ -0,0 +1,3 @@+@if (text) {+ {{ text }}+}diff --git a/client/src/app/shared/shared-main/date/date-group-label.component.ts b/client/src/app/shared/shared-main/date/date-group-label.component.tsnew file mode 100644index 0000000000..1a60532393--- /dev/null+++ b/client/src/app/shared/shared-main/date/date-group-label.component.ts@@ -0,0 +1,81 @@+import { ChangeDetectionStrategy, Component, HostBinding, input, OnInit } from '@angular/core'+import { isLastMonth, isLastWeek, isThisMonth, isToday, isYesterday } from '@peertube/peertube-core-utils'++export enum GroupDate {+ TODAY = 1,+ YESTERDAY = 2,+ THIS_WEEK = 3,+ THIS_MONTH = 4,+ LAST_MONTH = 5,+ OLDER = 6+}++export type GroupDateLabels = { [id in GroupDate]: string }++@Component({+ selector: 'my-date-group-label',+ templateUrl: 'date-group-label.component.html',+ changeDetection: ChangeDetectionStrategy.OnPush+})+export class DateGroupLabelComponent implements OnInit {+ store = input.required<Set<number>>()+ date = input.required<Date | string>()++ groupedDateLabels = input<GroupDateLabels>({+ [GroupDate.TODAY]: $localize`Today`,+ [GroupDate.YESTERDAY]: $localize`Yesterday`,+ [GroupDate.THIS_WEEK]: $localize`This week`,+ [GroupDate.THIS_MONTH]: $localize`This month`,+ [GroupDate.LAST_MONTH]: $localize`Last month`,+ [GroupDate.OLDER]: $localize`Older`+ })++ text: string++ @HostBinding('class.date-displayed')+ dateDisplayed = false++ ngOnInit (): void {+ const periods = [+ {+ value: GroupDate.TODAY,+ validator: (d: Date) => isToday(d)+ },+ {+ value: GroupDate.YESTERDAY,+ validator: (d: Date) => isYesterday(d)+ },+ {+ value: GroupDate.THIS_WEEK,+ validator: (d: Date) => isLastWeek(d)+ },+ {+ value: GroupDate.THIS_MONTH,+ validator: (d: Date) => isThisMonth(d)+ },+ {+ value: GroupDate.LAST_MONTH,+ validator: (d: Date) => isLastMonth(d)+ },+ {+ value: GroupDate.OLDER,+ validator: () => true+ }+ ]++ for (const period of periods) {+ if (period.validator(new Date(this.date()))) {+ if (this.store().has(period.value) === true) break++ // Only "Older" period, no need to display anything+ if (period.value === GroupDate.OLDER && this.store().size === 0) break++ this.store().add(period.value)+ this.text = this.groupedDateLabels()[period.value]+ this.dateDisplayed = true++ break+ }+ }+ }+}diff --git a/client/src/app/shared/shared-video-miniature/videos-list.component.html b/client/src/app/shared/shared-video-miniature/videos-list.component.htmlindex 8d274912a1..20329e7099 100644--- a/client/src/app/shared/shared-video-miniature/videos-list.component.html+++ b/client/src/app/shared/shared-video-miniature/videos-list.component.html@@ -21,7 +21,7 @@class="videos" [ngClass]="{ 'display-as-row': displayAsRow() }"><ng-container *ngIf="highlightedLives.length !== 0">- <h2 class="date-title">+ <h2 class="videos-section-title"><my-global-icon class="pt-icon me-1 top--1px" iconName="live"></my-global-icon><ng-container i18n>Lives</ng-container></h2>@@ -37,15 +37,17 @@</div></ng-container>- <h2 *ngIf="!groupByDate()" class="date-title">- <my-global-icon class="pt-icon me-1" iconName="videos"></my-global-icon> Videos+ <h2 class="date-title" [ngClass]="{ 'visually-hidden': groupByDate() }">+ <my-global-icon class="pt-icon me-1" iconName="videos"></my-global-icon>++ <ng-container i18n>Videos</ng-container></h2></ng-container><ng-container *ngFor="let video of videos; trackBy: videoById;">- <h2 class="date-title" *ngIf="getCurrentGroupedDateLabel(video)">- {{ getCurrentGroupedDateLabel(video) }}- </h2>+ @if (groupByDate()) {+ <my-date-group-label [date]="video.publishedAt" [store]="groupByDateStore" [groupedDateLabels]="groupedDateLabels"></my-date-group-label>+ }<div class="video-wrapper"><my-video-miniaturediff --git a/client/src/app/shared/shared-video-miniature/videos-list.component.scss b/client/src/app/shared/shared-video-miniature/videos-list.component.scssindex b1f25e9091..6676ae9a6d 100644--- a/client/src/app/shared/shared-video-miniature/videos-list.component.scss+++ b/client/src/app/shared/shared-video-miniature/videos-list.component.scss@@ -1,7 +1,7 @@-@use '_bootstrap-variables';-@use '_variables' as *;-@use '_mixins' as *;-@use '_miniature' as *;+@use "_bootstrap-variables";+@use "_variables" as *;+@use "_mixins" as *;+@use "_miniature" as *;// Cannot set margin top to videos-header because of the main header fixed position$margin-top: 2rem;@@ -21,7 +21,12 @@ $margin-top: 2rem;}}-.date-title {+my-date-group-label:not(.date-displayed) {+ display: none;+}++my-date-group-label.date-displayed,+.videos-section-title {font-weight: $font-semibold;margin-bottom: 20px;font-size: 1rem;@@ -30,7 +35,7 @@ $margin-top: 2rem;grid-column: 1 / -1;&:not(:first-child) {- margin-top: .5rem;+ margin-top: 0.5rem;padding-top: 20px;border-top: 1px solid $separator-border-color;}diff --git a/client/src/app/shared/shared-video-miniature/videos-list.component.ts b/client/src/app/shared/shared-video-miniature/videos-list.component.tsindex 6823a19e41..7b47727e6f 100644--- a/client/src/app/shared/shared-video-miniature/videos-list.component.ts+++ b/client/src/app/shared/shared-video-miniature/videos-list.component.ts@@ -13,7 +13,6 @@ import {updatePaginationOnDelete} from '@app/core'import { GlobalIconComponent, GlobalIconName } from '@app/shared/shared-icons/global-icon.component'-import { isLastMonth, isLastWeek, isThisMonth, isToday, isYesterday } from '@peertube/peertube-core-utils'import { ResultList, VideoSortField } from '@peertube/peertube-models'import { logger } from '@root-helpers/logger'import debug from 'debug'@@ -21,6 +20,7 @@ import { Observable, Subject, Subscription, forkJoin, fromEvent, of } from 'rxjsimport { concatMap, debounceTime, map, switchMap } from 'rxjs/operators'import { ButtonComponent } from '../shared-main/buttons/button.component'import { InfiniteScrollerDirective } from '../shared-main/common/infinite-scroller.directive'+import { DateGroupLabelComponent, GroupDate, GroupDateLabels } from '../shared-main/date/date-group-label.component'import { Syndication } from '../shared-main/feeds/syndication.model'import { Video } from '../shared-main/video/video.model'import { VideoFiltersHeaderComponent } from './video-filters-header.component'@@ -35,16 +35,6 @@ export type HeaderAction = {routerLink?: string}-enum GroupDate {- UNKNOWN = 0,- TODAY = 1,- YESTERDAY = 2,- THIS_WEEK = 3,- THIS_MONTH = 4,- LAST_MONTH = 5,- OLDER = 6-}-@Component({selector: 'my-videos-list',templateUrl: './videos-list.component.html',@@ -56,7 +46,8 @@ enum GroupDate {VideoFiltersHeaderComponent,InfiniteScrollerDirective,VideoMiniatureComponent,- GlobalIconComponent+ GlobalIconComponent,+ DateGroupLabelComponent]})export class VideosListComponent implements OnInit, OnDestroy {@@ -111,6 +102,16 @@ export class VideosListComponent implements OnInit, OnDestroy {}displayModerationBlock = true+ groupByDateStore = new Set<number>()+ groupedDateLabels: GroupDateLabels = {+ [GroupDate.TODAY]: $localize`Today's videos`,+ [GroupDate.YESTERDAY]: $localize`Yesterday's videos`,+ [GroupDate.THIS_WEEK]: $localize`This week's videos`,+ [GroupDate.THIS_MONTH]: $localize`This month's videos`,+ [GroupDate.LAST_MONTH]: $localize`Last month's videos`,+ [GroupDate.OLDER]: $localize`Older videos`+ }+private routeSub: Subscriptionprivate userSub: Subscriptionprivate resizeSub: Subscription@@ -121,17 +122,6 @@ export class VideosListComponent implements OnInit, OnDestroy {totalItems: null}- private groupedDateLabels: { [id in GroupDate]: string } = {- [GroupDate.UNKNOWN]: null,- [GroupDate.TODAY]: $localize`Today's videos`,- [GroupDate.YESTERDAY]: $localize`Yesterday's videos`,- [GroupDate.THIS_WEEK]: $localize`This week's videos`,- [GroupDate.THIS_MONTH]: $localize`This month's videos`,- [GroupDate.LAST_MONTH]: $localize`Last month's videos`,- [GroupDate.OLDER]: $localize`Older videos`- }- private groupedDates: { [id: number]: GroupDate } = {}-private lastQueryLength: numberprivate videoRequests = new Subject<{@@ -226,6 +216,7 @@ export class VideosListComponent implements OnInit, OnDestroy {this.hasDoneFirstQuery = falsethis.videos = []this.highlightedLives = []+ this.groupByDateStore.clear()if (this.highlightLives() && (!this.filters.live || this.filters.live === 'both')) {liveFilters = this.filters.clone()@@ -350,8 +341,6 @@ export class VideosListComponent implements OnInit, OnDestroy {this.videos = this.videos.concat(videos)- if (this.groupByDate()) this.buildGroupedDateLabels()-this.onVideosDataSubject.next(videos)this.videosLoaded.emit(this.videos)},@@ -364,65 +353,4 @@ export class VideosListComponent implements OnInit, OnDestroy {}})}-- // ----------------------------------------------------------------------------- private buildGroupedDateLabels () {- let currentGroupedDate: GroupDate = GroupDate.UNKNOWN-- const periods = [- {- value: GroupDate.TODAY,- validator: (d: Date) => isToday(d)- },- {- value: GroupDate.YESTERDAY,- validator: (d: Date) => isYesterday(d)- },- {- value: GroupDate.THIS_WEEK,- validator: (d: Date) => isLastWeek(d)- },- {- value: GroupDate.THIS_MONTH,- validator: (d: Date) => isThisMonth(d)- },- {- value: GroupDate.LAST_MONTH,- validator: (d: Date) => isLastMonth(d)- },- {- value: GroupDate.OLDER,- validator: () => true- }- ]-- let onlyOlderPeriod = true-- for (const video of this.videos) {- const publishedDate = video.publishedAt-- for (const period of periods) {- if (currentGroupedDate <= period.value && period.validator(publishedDate)) {- if (currentGroupedDate !== period.value) {- if (period.value !== GroupDate.OLDER) onlyOlderPeriod = false-- currentGroupedDate = period.value- this.groupedDates[video.id] = currentGroupedDate- }-- break- }- }- }-- // No need to group by date, there is only "Older" period available- if (onlyOlderPeriod) this.groupedDates = {}- }-- getCurrentGroupedDateLabel (video: Video) {- if (this.groupByDate() === false) return undefined-- return this.groupedDateLabels[this.groupedDates[video.id]]- }}diff --git a/client/src/sass/class-helpers/_titles.scss b/client/src/sass/class-helpers/_titles.scssindex 862001e224..3c9b3cf511 100644--- a/client/src/sass/class-helpers/_titles.scss+++ b/client/src/sass/class-helpers/_titles.scss@@ -7,6 +7,7 @@line-height: 1;@include font-size(2rem);+ @include rfs(2rem, margin-top);@include rfs(2rem, margin-bottom);my-global-icon {diff --git a/server/core/models/video/video-channel-activity.ts b/server/core/models/video/video-channel-activity.tsindex 8d88e30f4e..8c5d0a3a78 100644--- a/server/core/models/video/video-channel-activity.ts+++ b/server/core/models/video/video-channel-activity.ts@@ -12,7 +12,7 @@ import { VIDEO_CHANNEL_ACTIVITY_ACTIONS, VIDEO_CHANNEL_ACTIVITY_TARGETS } from 'import { MChannelId, MChannelSync, MUserAccountId, MVideo, MVideoImport, MVideoPlaylist } from '@server/types/models/index.js'import { MChannelActivityFormattable } from '@server/types/models/video/video-channel-activity.js'import { Op, Transaction } from 'sequelize'-import { AllowNull, BelongsTo, Column, CreatedAt, DataType, ForeignKey, Table } from 'sequelize-typescript'+import { AllowNull, BelongsTo, Column, CreatedAt, DataType, ForeignKey, Table, UpdatedAt } from 'sequelize-typescript'import { AccountModel } from '../account/account.js'import { ActorModel } from '../actor/actor.js'import { getSort, SequelizeModel } from '../shared/index.js'@@ -124,6 +124,9 @@ export class VideoChannelActivityModel extends SequelizeModel<VideoChannelActivi@CreatedAtdeclare createdAt: Date+ @UpdatedAt+ declare updatedAt: Date+@ForeignKey(() => VideoChannelModel)@Columndeclare videoChannelId: number