nsfw: boolean
account: Account
- private static createByString (account: string, serverHost: string) {
+ private static createByString (account: string, serverHost: string, apiURL: string) {
+ const thisHost = new URL(apiURL).host
+ if (serverHost.trim() === thisHost)
+ return account
return account + '@' + serverHost
}
this.dislikes = hash.dislikes
this.nsfw = hash.nsfw
- this.by = Video.createByString(hash.accountName, hash.serverHost)
+ this.by = Video.createByString(hash.accountName, hash.serverHost, absoluteAPIUrl)
}
isVideoNSFWForUser (user: User) {
@ViewChild('videoReportModal') videoReportModal: VideoReportComponent
otherVideos: Video[] = []
+ otherVideosDisplayed: Video[] = []
error = false
loading = false
this.videoService.getVideos({ currentPage: 1, itemsPerPage: 5 }, '-createdAt')
.subscribe(
data => this.otherVideos = data.videos,
-
- err => console.error(err)
+ err => console.error(err)
)
this.paramsSub = this.route.params.subscribe(routeParams => {
setLike () {
if (this.isUserLoggedIn() === false) return
- // Already liked this video
- if (this.userRating === 'like') return
-
- this.videoService.setVideoLike(this.video.id)
- .subscribe(
- () => {
- // Update the video like attribute
- this.updateVideoRating(this.userRating, 'like')
- this.userRating = 'like'
- },
-
- err => this.notificationsService.error('Error', err.message)
- )
+ if (this.userRating === 'like') {
+ // Already liked this video
+ this.setRating('none')
+ } else {
+ this.setRating('like')
+ }
}
setDislike () {
if (this.isUserLoggedIn() === false) return
- // Already disliked this video
- if (this.userRating === 'dislike') return
-
- this.videoService.setVideoDislike(this.video.id)
- .subscribe(
- () => {
- // Update the video dislike attribute
- this.updateVideoRating(this.userRating, 'dislike')
- this.userRating = 'dislike'
- },
-
- err => this.notificationsService.error('Error', err.message)
- )
+ if (this.userRating === 'dislike') {
+ // Already disliked this video
+ this.setRating('none')
+ } else {
+ this.setRating('dislike')
+ }
}
blacklistVideo (event: Event) {
private onVideoFetched (video: VideoDetails) {
this.video = video
+ if (this.otherVideos.length > 0) {
+ this.otherVideosDisplayed = this.otherVideos.filter(v => v.uuid !== this.video.uuid)
+ }
+
let observable
if (this.video.isVideoNSFWForUser(this.user)) {
observable = this.confirmService.confirm(
)
}
+ private setRating (nextRating) {
+ let method
+ switch (nextRating) {
+ case 'like':
+ method = this.videoService.setVideoLike
+ break
+ case 'dislike':
+ method = this.videoService.setVideoDislike
+ break
+ case 'none':
+ method = this.videoService.unsetVideoLike
+ break
+ }
+
+ method.call(this.videoService, this.video.id)
+ .subscribe(
+ () => {
+ // Update the video like attribute
+ this.updateVideoRating(this.userRating, nextRating)
+ this.userRating = nextRating
+ },
+ err => this.notificationsService.error('Error', err.message)
+ )
+ }
+
private updateVideoRating (oldRating: UserVideoRateType, newRating: VideoRateType) {
let likesToIncrement = 0
let dislikesToIncrement = 0