diff --git a/proxy.conf.json b/proxy.conf.json index cc2d66deb1cf1ef603ad77379c773850c9956bcd..57be7f5127431ed71fdc432bd35b348a91ca1866 100644 --- a/proxy.conf.json +++ b/proxy.conf.json @@ -1,38 +1,6 @@ { - "/api/comment": { - "target": "http://localhost:8088", - "secure": false, - "pathRewrite": { - "^/api": "" - }, - "logLevel": "debug" - }, - "/api/vote": { - "target": "http://localhost:8088", - "secure": false, - "pathRewrite": { - "^/api": "" - }, - "logLevel": "debug" - }, - "/api/bonustoken": { - "target": "http://localhost:8088", - "secure": false, - "pathRewrite": { - "^/api": "" - }, - "logLevel": "debug" - }, - "/api/settings": { - "target": "http://localhost:8088", - "secure": false, - "pathRewrite": { - "^/api": "" - }, - "logLevel": "debug" - }, "/api/ws/websocket": { - "target": "ws://localhost:8099", + "target": "ws://localhost:8080", "secure": false, "pathRewrite": { "^/api": "" @@ -41,7 +9,7 @@ "logLevel": "debug" }, "/api": { - "target": "http://localhost:8080", + "target": "http://localhost:8888", "secure": false, "pathRewrite": { "^/api": "" diff --git a/src/app/app.module.ts b/src/app/app.module.ts index 552bb915312bc3dfb9df4d891350e5dba562b0bc..729eddf51e7f5ba9ee1b3f256952c1cbfe5ce4dd 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -38,7 +38,6 @@ import { TranslateHttpLoader } from '@ngx-translate/http-loader'; import { DemoVideoComponent } from './components/home/_dialogs/demo-video/demo-video.component'; import { HomeCreatorPageComponent } from './components/home/home-creator-page/home-creator-page.component'; import { HomeParticipantPageComponent } from './components/home/home-participant-page/home-participant-page.component'; -import { CommentSettingsService } from './services/http/comment-settings.service'; import { BonusTokenService } from './services/http/bonus-token.service'; import { CustomIconService } from './services/util/custom-icon.service'; import { ModeratorModule } from './components/moderator/moderator.module'; @@ -156,7 +155,6 @@ export function initializeApp(appConfig: AppConfig) { UserService, VoteService, ModeratorService, - CommentSettingsService, BonusTokenService, CustomIconService, WsConnectorService, diff --git a/src/app/components/creator/_dialogs/comment-settings/comment-settings.component.ts b/src/app/components/creator/_dialogs/comment-settings/comment-settings.component.ts index 7387d324c87175137b039fb9b8dd25dfb86e31c7..2834c7441bf9cc6300ba5edf46a8e4916a18a238 100644 --- a/src/app/components/creator/_dialogs/comment-settings/comment-settings.component.ts +++ b/src/app/components/creator/_dialogs/comment-settings/comment-settings.component.ts @@ -7,7 +7,6 @@ import { RoomService } from '../../../../services/http/room.service'; import { Router } from '@angular/router'; import { CommentService } from '../../../../services/http/comment.service'; import { BonusTokenService } from '../../../../services/http/bonus-token.service'; -import { CommentSettingsService } from '../../../../services/http/comment-settings.service'; import { DeleteCommentsComponent } from '../delete-comments/delete-comments.component'; import { Room } from '../../../../models/room'; import { CommentBonusTokenMixin } from '../../../../models/comment-bonus-token-mixin'; @@ -40,36 +39,19 @@ export class CommentSettingsComponent implements OnInit { protected roomService: RoomService, public router: Router, public commentService: CommentService, - public commentSettingsService: CommentSettingsService, private bonusTokenService: BonusTokenService, @Inject(MAT_DIALOG_DATA) public data: any ) { } ngOnInit() { - if (this.editRoom.extensions && this.editRoom.extensions['comments']) { - const commentExtension = this.editRoom.extensions['comments']; - if (commentExtension.enableThreshold !== null) { - if (commentExtension.commentThreshold) { - this.commentThreshold = commentExtension.commentThreshold; - } else { - this.commentThreshold = -100; - } - this.settingThreshold = commentExtension.enableThreshold; - } - - if (commentExtension.enableTags !== null) { - this.tagsEnabled = commentExtension.enableTags; - this.tags = commentExtension.tags; - } - - if (this.editRoom.extensions['comments'].enableModeration !== null) { - this.enableCommentModeration = this.editRoom.extensions['comments'].enableModeration; - } + if (this.editRoom.threshold !== null) { + this.commentThreshold = this.editRoom.threshold; + this.settingThreshold = true; } - this.commentSettingsService.get(this.roomId).subscribe(settings => { - this.directSend = settings.directSend; - }); + this.tags = []; + this.enableCommentModeration = this.editRoom.moderated; + this.directSend = this.editRoom.directSend; } onSliderChange(event: any) { @@ -117,9 +99,14 @@ export class CommentSettingsComponent implements OnInit { commentSettings.roomId = this.roomId; commentSettings.directSend = this.directSend; const settingsReturn = new CommentSettingsDialog(); + + this.editRoom.directSend = this.directSend; + this.editRoom.threshold = this.commentThreshold; + this.editRoom.moderated = this.enableCommentModeration; + // If moderation isn't enabled, the direct send is of no interest and shouldn't be updated to avoid confusion about missing comments if ((this.enableCommentModeration && !this.directSend) || this.directSend) { - this.commentSettingsService.update(commentSettings).subscribe( x => { + this.roomService.updateRoom(this.editRoom).subscribe(x => { }); settingsReturn.directSend = this.directSend; } diff --git a/src/app/components/creator/_dialogs/moderators/moderators.component.ts b/src/app/components/creator/_dialogs/moderators/moderators.component.ts index 61fe8968fe5473bf44a97545ce701bfd7bf72c4c..e05f47d6e225ebf464149fbfe105f67f40aa928b 100644 --- a/src/app/components/creator/_dialogs/moderators/moderators.component.ts +++ b/src/app/components/creator/_dialogs/moderators/moderators.component.ts @@ -41,12 +41,12 @@ export class ModeratorsComponent implements OnInit { getModerators() { this.moderatorService.get(this.roomId).subscribe(list => { this.moderators = list; - this.moderators.forEach((user, i) => { - this.userIds[i] = user.userId; + this.moderators.forEach((user: any, i) => { + this.userIds[i] = user.accountId; }); this.moderatorService.getUserData(this.userIds).subscribe(users => { - users.forEach((user, i) => { - this.moderators[i].loginId = user.loginId; + users.forEach((user: any, i) => { + this.moderators[i].loginId = user.email; }); }); }); @@ -61,8 +61,8 @@ export class ModeratorsComponent implements OnInit { return; } this.moderatorService.add(this.roomId, list[0].id).subscribe(); - this.moderatorService.addToHistory(this.roomId, list[0].id); - this.moderators.push(new Moderator(list[0].id, loginId)); + // this.moderatorService.addToHistory(this.roomId, list[0].id); + this.moderators.push(new Moderator(list[0].id, this.roomId, loginId)); this.translationService.get('room-page.moderator-added').subscribe(msg => { this.notificationService.show(msg); }); @@ -77,7 +77,7 @@ export class ModeratorsComponent implements OnInit { dialogRef.afterClosed() .subscribe(result => { if (result === 'delete') { - this.removeModerator(moderator.userId, this.moderators.indexOf(moderator)); + this.removeModerator(moderator.accountId, this.moderators.indexOf(moderator)); } }); } diff --git a/src/app/components/creator/room-creator-page/room-creator-page.component.ts b/src/app/components/creator/room-creator-page/room-creator-page.component.ts index 269dd0ed3a858c7cf777b883768248f94d0c35cc..3887a5ac9b8e79fc49279febf44167a9d1f3c098 100644 --- a/src/app/components/creator/room-creator-page/room-creator-page.component.ts +++ b/src/app/components/creator/room-creator-page/room-creator-page.component.ts @@ -123,7 +123,8 @@ export class RoomCreatorPageComponent extends RoomPageComponent implements OnIni } updateCommentSettings(settings: CommentSettingsDialog) { - const commentExtension: TSMap<string, any> = new TSMap(); + // ToDo: FIX + /*const commentExtension: TSMap<string, any> = new TSMap(); commentExtension.set('enableThreshold', settings.enableThreshold); commentExtension.set('commentThreshold', settings.threshold); commentExtension.set('enableModeration', settings.enableModeration); @@ -140,13 +141,14 @@ export class RoomCreatorPageComponent extends RoomPageComponent implements OnIni this.moderationEnabled = settings.enableModeration; localStorage.setItem('moderationEnabled', String(this.moderationEnabled)); - this.updRoom.extensions['comments'] = commentExtension; + this.updRoom.extensions['comments'] = commentExtension;*/ } resetThreshold(): void { - if (this.room.extensions && this.room.extensions['comments']) { + // ToDo: FIX + /*if (this.room.extensions && this.room.extensions['comments']) { delete this.room.extensions['comments']; - } + }*/ } saveChanges() { @@ -222,8 +224,9 @@ export class RoomCreatorPageComponent extends RoomPageComponent implements OnIni } showTagsDialog(): void { - this.updRoom = JSON.parse(JSON.stringify(this.room)); - const dialogRef = this.dialog.open(TagsComponent, { + // ToDo: FIX + // this.updRoom = JSON.parse(JSON.stringify(this.room)); + /*const dialogRef = this.dialog.open(TagsComponent, { width: '400px' }); let tagExtension; @@ -239,7 +242,7 @@ export class RoomCreatorPageComponent extends RoomPageComponent implements OnIni this.updRoom.extensions['tags'] = result; this.saveChanges(); } - }); + });*/ } copyShortId(): void { diff --git a/src/app/components/moderator/moderator-comment-list/moderator-comment-list.component.ts b/src/app/components/moderator/moderator-comment-list/moderator-comment-list.component.ts index dc1d397bd40abd2c6bc3a8dbce65acc658f12b9a..78b51440c88d27a508b226aba662777164b7dca8 100644 --- a/src/app/components/moderator/moderator-comment-list/moderator-comment-list.component.ts +++ b/src/app/components/moderator/moderator-comment-list/moderator-comment-list.component.ts @@ -121,8 +121,8 @@ export class ModeratorCommentListComponent implements OnInit { getComments(): void { this.isLoading = false; let commentThreshold = -10; - if (this.room && this.room.extensions && this.room.extensions['comments']) { - commentThreshold = this.room.extensions['comments'].commentThreshold; + if (this.room.threshold !== null) { + commentThreshold = this.room.threshold; if (this.hideCommentsList) { this.filteredComments = this.filteredComments.filter(x => x.score >= commentThreshold); } else { diff --git a/src/app/components/moderator/room-moderator-page/room-moderator-page.component.ts b/src/app/components/moderator/room-moderator-page/room-moderator-page.component.ts index 89bde2ce3a88eac86a61a6dff2f784bc1c547fbd..1d7549a61152ce9b648fda6307280b2d793b7869 100644 --- a/src/app/components/moderator/room-moderator-page/room-moderator-page.component.ts +++ b/src/app/components/moderator/room-moderator-page/room-moderator-page.component.ts @@ -47,11 +47,9 @@ export class RoomModeratorPageComponent extends RoomPageComponent implements OnI this.roomService.getRoomByShortId(id).subscribe(room => { this.room = room; this.isLoading = false; - if (this.room.extensions && this.room.extensions['comments']) { - if (this.room.extensions['comments'].enableModeration !== null) { - this.moderationEnabled = this.room.extensions['comments'].enableModeration; - this.viewModuleCount = this.viewModuleCount + 1; - } + this.moderationEnabled = this.room.moderated; + if (this.moderationEnabled) { + this.viewModuleCount = this.viewModuleCount + 1; } this.commentService.countByRoomId(this.room.id, true).subscribe(commentCounter => { this.commentCounter = commentCounter; diff --git a/src/app/components/shared/_dialogs/room-create/room-create.component.ts b/src/app/components/shared/_dialogs/room-create/room-create.component.ts index 87cf7af389c2b682c107efad0af0d8bbb264be9d..61cf58b1a07c903ae226fbdc955dfb546262ee6a 100644 --- a/src/app/components/shared/_dialogs/room-create/room-create.component.ts +++ b/src/app/components/shared/_dialogs/room-create/room-create.component.ts @@ -61,10 +61,6 @@ export class RoomCreateComponent implements OnInit { return; } const newRoom = new Room(); - const commentExtension: TSMap<string, any> = new TSMap(); - newRoom.extensions = new TSMap(); - commentExtension.set('enableModeration', true); - newRoom.extensions.set('comments', commentExtension); newRoom.name = longRoomName; newRoom.abbreviation = '00000000'; newRoom.description = ''; diff --git a/src/app/components/shared/comment-answer/comment-answer.component.ts b/src/app/components/shared/comment-answer/comment-answer.component.ts index 6cd3763a68c369c87e8c85bc98dcbea5b66ce984..536bfb9d238f0dacf6a2bb7bd9ac9dea554b5e8b 100644 --- a/src/app/components/shared/comment-answer/comment-answer.component.ts +++ b/src/app/components/shared/comment-answer/comment-answer.component.ts @@ -51,7 +51,7 @@ export class CommentAnswerComponent implements OnInit { saveAnswer() { this.edit = false; - this.wsCommentService.answer(this.comment, this.answer); + this.commentService.answer(this.comment, this.answer).subscribe(); this.translateService.get('comment-page.comment-answered').subscribe(msg => { this.notificationService.show(msg); }); @@ -71,7 +71,7 @@ export class CommentAnswerComponent implements OnInit { deleteAnswer() { this.answer = null; - this.wsCommentService.answer(this.comment, this.answer); + this.commentService.answer(this.comment, this.answer).subscribe(); this.translateService.get('comment-page.answer-deleted').subscribe(msg => { this.notificationService.show(msg); }); diff --git a/src/app/components/shared/comment-list/comment-list.component.ts b/src/app/components/shared/comment-list/comment-list.component.ts index 32e06496a13360b2894c6ff0f023b806888ab332..464c5cfed9d3ada2c5a5aec828208e28d334e7ba 100644 --- a/src/app/components/shared/comment-list/comment-list.component.ts +++ b/src/app/components/shared/comment-list/comment-list.component.ts @@ -106,18 +106,13 @@ export class CommentListComponent implements OnInit, OnDestroy { } }); this.route.params.subscribe(params => { + this.shortId = params['shortId']; this.authenticationService.guestLogin(UserRole.PARTICIPANT).subscribe(r => { this.roomService.getRoomByShortId(this.shortId).subscribe(room => { this.room = room; - if (this.room && this.room.extensions && this.room.extensions['comments']) { - if (this.room.extensions['comments'].enableModeration !== null) { - this.moderationEnabled = this.room.extensions['comments'].enableModeration; - localStorage.setItem('moderationEnabled', JSON.stringify(this.moderationEnabled)); - } - if (this.room.extensions['comments'].directSend !== null) { - this.directSend = this.room.extensions['comments'].directSend; - } - } + this.moderationEnabled = this.room.moderated; + this.directSend = this.room.directSend; + localStorage.setItem('moderationEnabled', JSON.stringify(this.moderationEnabled)); if (!this.authenticationService.hasAccess(this.shortId, UserRole.PARTICIPANT)) { this.roomService.addToHistory(this.room.id); this.authenticationService.setAccess(this.shortId, UserRole.PARTICIPANT); @@ -193,17 +188,15 @@ export class CommentListComponent implements OnInit, OnDestroy { } getComments(): void { - if (this.room && this.room.extensions && this.room.extensions['comments']) { - if (this.room.extensions['comments'].enableThreshold) { - this.thresholdEnabled = true; - } else { - this.thresholdEnabled = false; - } + if (this.room.threshold) { + this.thresholdEnabled = true; + } else { + this.thresholdEnabled = false; } this.isLoading = false; let commentThreshold; if (this.thresholdEnabled) { - commentThreshold = this.room.extensions['comments'].commentThreshold; + commentThreshold = this.room.threshold; if (this.hideCommentsList) { this.filteredComments = this.filteredComments.filter(x => x.score >= commentThreshold); } else { @@ -311,9 +304,11 @@ export class CommentListComponent implements OnInit, OnDestroy { dialogRef.componentInstance.user = this.user; dialogRef.componentInstance.roomId = this.roomId; let tags; - if (this.room.extensions && this.room.extensions['tags'] && this.room.extensions['tags'].tags) { + tags = []; + // ToDo: FIX + /*if (this.room.extensions && this.room.extensions['tags'] && this.room.extensions['tags'].tags) { tags = this.room.extensions['tags'].tags; - } + }*/ dialogRef.componentInstance.tags = tags; dialogRef.afterClosed() .subscribe(result => { @@ -345,7 +340,7 @@ export class CommentListComponent implements OnInit, OnDestroy { }); } } - this.wsCommentService.add(comment); + this.commentService.addComment(comment).subscribe(); this.notificationService.show(message); } diff --git a/src/app/components/shared/comment/comment.component.ts b/src/app/components/shared/comment/comment.component.ts index 2f58d20cd6fbfbb71a51a8c9dc601e851c57bfff..0309560a163b0dcfe15768c2889b8d2783b07f93 100644 --- a/src/app/components/shared/comment/comment.component.ts +++ b/src/app/components/shared/comment/comment.component.ts @@ -127,7 +127,7 @@ export class CommentComponent implements OnInit, AfterViewInit { } setRead(comment: Comment): void { - this.comment = this.wsCommentService.toggleRead(comment); + this.commentService.toggleRead(comment).subscribe(c => this.comment = c); } markCorrect(comment: Comment, type: CorrectWrong): void { @@ -136,21 +136,21 @@ export class CommentComponent implements OnInit, AfterViewInit { } else { comment.correct = type; } - this.comment = this.wsCommentService.markCorrect(comment); + this.commentService.markCorrect(comment).subscribe(c => this.comment = c); } setFavorite(comment: Comment): void { - this.comment = this.wsCommentService.toggleFavorite(comment); + this.commentService.toggleFavorite(comment).subscribe(c => this.comment = c); } voteUp(comment: Comment): void { const userId = this.authenticationService.getUser().id; if (this.hasVoted !== 1) { - this.wsCommentService.voteUp(comment, userId); + this.commentService.voteUp(comment, userId).subscribe(); this.hasVoted = 1; this.currentVote = '1'; } else { - this.wsCommentService.resetVote(comment, userId); + this.commentService.resetVote(comment, userId).subscribe(); this.hasVoted = 0; this.currentVote = '0'; } @@ -160,11 +160,11 @@ export class CommentComponent implements OnInit, AfterViewInit { voteDown(comment: Comment): void { const userId = this.authenticationService.getUser().id; if (this.hasVoted !== -1) { - this.wsCommentService.voteDown(comment, userId); + this.commentService.voteDown(comment, userId).subscribe(); this.hasVoted = -1; this.currentVote = '-1'; } else { - this.wsCommentService.resetVote(comment, userId); + this.commentService.resetVote(comment, userId).subscribe(); this.hasVoted = 0; this.currentVote = '0'; } @@ -207,7 +207,7 @@ export class CommentComponent implements OnInit, AfterViewInit { } setAck(comment: Comment): void { - this.comment = this.wsCommentService.toggleAck(comment); + this.commentService.toggleAck(comment).subscribe(c => this.comment = c); } goToFullScreen(element: Element): void { @@ -220,7 +220,7 @@ export class CommentComponent implements OnInit, AfterViewInit { openPresentDialog(comment: Comment): void { if (this.isCreator === true) { - this.wsCommentService.highlight(comment); + this.commentService.highlight(comment).subscribe(); if (!comment.read) { this.setRead(comment); } @@ -238,7 +238,7 @@ export class CommentComponent implements OnInit, AfterViewInit { dialogRef.componentInstance.body = comment.body; dialogRef.afterClosed() .subscribe(result => { - this.wsCommentService.lowlight(comment); + this.commentService.lowlight(comment).subscribe(); this.exitFullScreen(); }); diff --git a/src/app/components/shared/questionwall/question-wall/question-wall.component.ts b/src/app/components/shared/questionwall/question-wall/question-wall.component.ts index 37d8468380d502f712ac6abd534f82d4fb192402..dc49394d7545cf705f2622058e87c195d8954ff4 100644 --- a/src/app/components/shared/questionwall/question-wall/question-wall.component.ts +++ b/src/app/components/shared/questionwall/question-wall/question-wall.component.ts @@ -84,7 +84,9 @@ export class QuestionWallComponent implements OnInit, AfterViewInit, OnDestroy { }); this.roomService.getRoom(this.roomId).subscribe(e => { this.room = e; - this.tags = e.extensions['tags']['tags']; + // ToDo: Fix + // this.tags = e.extensions['tags']['tags']; + this.tags = []; }); this.wsCommentService.getCommentStream(this.roomId).subscribe(e => { this.commentService.getComment(JSON.parse(e.body).payload.id).subscribe(comment => { @@ -219,11 +221,11 @@ export class QuestionWallComponent implements OnInit, AfterViewInit, OnDestroy { } likeComment(comment: QuestionWallComment) { - this.wsCommentService.voteUp(comment.comment, this.authenticationService.getUser().id); + this.commentService.voteUp(comment.comment, this.authenticationService.getUser().id).subscribe(); } dislikeComment(comment: QuestionWallComment) { - this.wsCommentService.voteDown(comment.comment, this.authenticationService.getUser().id); + this.commentService.voteDown(comment.comment, this.authenticationService.getUser().id).subscribe(); } sortScore(reverse?: boolean) { diff --git a/src/app/components/shared/room-join/room-join.component.ts b/src/app/components/shared/room-join/room-join.component.ts index 7462c240f0ae8ddf3aced4014db9888b1fd4194b..79445154c06da0bfcf86ed6a97a3961420a848d6 100644 --- a/src/app/components/shared/room-join/room-join.component.ts +++ b/src/app/components/shared/room-join/room-join.component.ts @@ -84,7 +84,13 @@ export class RoomJoinComponent implements OnInit { joinRoom(id: string): void { if (!this.sessionCodeFormControl.hasError('required') && !this.sessionCodeFormControl.hasError('minlength')) { - this.getRoom(id); + if (!this.user) { + this.authenticationService.guestLogin(UserRole.CREATOR).subscribe(() => { + this.getRoom(id); + }); + } else { + this.getRoom(id); + } } } @@ -104,7 +110,7 @@ export class RoomJoinComponent implements OnInit { this.moderatorService.get(this.room.id).subscribe((moderators: Moderator[]) => { let isModerator = false; for (const m of moderators) { - if (m.userId === this.user.id) { + if (m.accountId === this.user.id) { this.authenticationService.setAccess(this.room.shortId, UserRole.EXECUTIVE_MODERATOR); this.router.navigate([`/moderator/room/${this.room.shortId}/comments`]); isModerator = true; diff --git a/src/app/components/shared/room-list/room-list.component.ts b/src/app/components/shared/room-list/room-list.component.ts index bfde2baa8a750f49219c4bd1aa8a18713c6ccbb0..d958998532dad4fe12b0a5188e53b6549537abdd 100644 --- a/src/app/components/shared/room-list/room-list.component.ts +++ b/src/app/components/shared/room-list/room-list.component.ts @@ -84,7 +84,7 @@ export class RoomListComponent implements OnInit, OnDestroy { roomWithRole.role = UserRole.PARTICIPANT; this.moderatorService.get(room.id).subscribe((moderators: Moderator[]) => { for (const m of moderators) { - if (m.userId === this.user.id) { + if (m.accountId === this.user.id) { this.authenticationService.setAccess(room.shortId, UserRole.EXECUTIVE_MODERATOR); roomWithRole.role = UserRole.EXECUTIVE_MODERATOR; } diff --git a/src/app/components/shared/room-page/room-page.component.ts b/src/app/components/shared/room-page/room-page.component.ts index 8a6919705cf462a86261d1d83eb19efe185b3d79..4b28b1ffce14007bc67f0ecce02a2b405ec8a2bd 100644 --- a/src/app/components/shared/room-page/room-page.component.ts +++ b/src/app/components/shared/room-page/room-page.component.ts @@ -54,12 +54,7 @@ export class RoomPageComponent implements OnInit, OnDestroy { this.roomService.getRoomByShortId(id).subscribe(room => { this.room = room; this.isLoading = false; - if (this.room.extensions && this.room.extensions['comments']) { - if (this.room.extensions['comments'].enableModeration !== null) { - this.moderationEnabled = this.room.extensions['comments'].enableModeration; - // ToDo: make room data cache that's available for components that manages data flow and put that there - } - } + this.moderationEnabled = this.room.moderated; localStorage.setItem('moderationEnabled', String(this.moderationEnabled)); this.commentService.countByRoomId(this.room.id, true) .subscribe(commentCounter => { diff --git a/src/app/models/moderator.ts b/src/app/models/moderator.ts index ff213d9c32779347734e2462dc521c23b5c50ff0..8fadb52c110ea3c31e2878c0610b3e8b7cff6e15 100644 --- a/src/app/models/moderator.ts +++ b/src/app/models/moderator.ts @@ -2,17 +2,20 @@ import { ModeratorRole } from './moderator-roles.enum'; import { UserRole } from './user-roles.enum'; export class Moderator { - userId: string; + accountId: string; + roomId: string; loginId: string; - roles: UserRole[]; + role: UserRole; constructor( - userId: string = '', + accountId: string = '', + roomId: string = '', loginId: string = '', - roles: UserRole[] = [] + role: UserRole = UserRole.PARTICIPANT ) { - this.userId = userId; + this.accountId = accountId; + this.roomId = roomId; this.loginId = loginId; - this.roles = roles; + this.role = role; } } diff --git a/src/app/models/room.ts b/src/app/models/room.ts index fb1c4f9a2e8e8df3e19b55f664f48bcd3a739250..d345d0b6441ade5e1a04f74aa47bde5283ffd11c 100644 --- a/src/app/models/room.ts +++ b/src/app/models/room.ts @@ -9,7 +9,9 @@ export class Room { name: string; description: string; closed: boolean; - extensions: TSMap<string, TSMap<string, any>>; + moderated: boolean; + directSend: boolean; + threshold: number; constructor( ownerId: string = '', @@ -18,7 +20,9 @@ export class Room { name: string = '', description: string = '', closed: boolean = false, - extensions: TSMap<string, TSMap<string, any>> = new TSMap() + moderated: boolean = true, + directSend: boolean = true, + threshold: number = null, ) { this.id = '', this.ownerId = ownerId; @@ -27,6 +31,8 @@ export class Room { this.name = name, this.description = description; this.closed = closed; - this.extensions = extensions; + this.moderated = moderated; + this.directSend = directSend; + this.threshold = threshold; } } diff --git a/src/app/services/http/authentication.service.ts b/src/app/services/http/authentication.service.ts index ee30c5632dc9168edbbe7fe60848bb0b7e718fb2..ede7f4e5748115daf5530f8d467af72cdddf3506 100644 --- a/src/app/services/http/authentication.service.ts +++ b/src/app/services/http/authentication.service.ts @@ -105,10 +105,10 @@ export class AuthenticationService extends BaseHttpService { ).subscribe(nu => { if (nu) { this.setUser(new User( - nu.userId, - nu.loginId, + nu.credentials, + nu.name, nu.authProvider, - nu.token, + nu.details, user.role, wasGuest)); } else { @@ -149,7 +149,7 @@ export class AuthenticationService extends BaseHttpService { resetPassword(email: string): Observable<boolean> { const connectionUrl: string = - this.apiUrl.v2 + + this.apiUrl.base + this.apiUrl.user + '/' + email + @@ -169,14 +169,15 @@ export class AuthenticationService extends BaseHttpService { setNewPassword(email: string, key: string, password: string): Observable<boolean> { const connectionUrl: string = - this.apiUrl.v2 + + this.apiUrl.base + this.apiUrl.user + '/' + email + - this.apiUrl.resetPassword + - `?key=${key}&password=${password}`; + this.apiUrl.resetPassword; return this.http.post(connectionUrl, { + key: key, + password: password }, this.httpOptions).pipe( catchError(err => { return of(false); @@ -223,15 +224,15 @@ export class AuthenticationService extends BaseHttpService { } private checkLogin(clientAuthentication: Observable<ClientAuthentication>, userRole: UserRole, isGuest: boolean): Observable<string> { - return clientAuthentication.pipe(map(result => { + return clientAuthentication.pipe(map((result: any) => { if (result) { // ToDo: Fix this madness. isGuest = result.authProvider === 'ARSNOVA_GUEST' ? true : false; this.setUser(new User( - result.userId, - result.loginId, + result.credentials, + result.name, result.authProvider, - result.token, + result.details, userRole, isGuest)); this.dataStoreService.set('loggedin', 'true'); @@ -241,7 +242,7 @@ export class AuthenticationService extends BaseHttpService { } }), catchError((e) => { // check if user needs activation - if (e.error.errorType === 'DisabledException') { + if (e.error.status === 403) { return of('activation'); } return of('false'); diff --git a/src/app/services/http/bonus-token.service.ts b/src/app/services/http/bonus-token.service.ts index f83b15f1d66c49256518fc33ef0beb8b63661ff1..bb69e961d72ab90eac447030f08c81023e0f2eae 100644 --- a/src/app/services/http/bonus-token.service.ts +++ b/src/app/services/http/bonus-token.service.ts @@ -38,7 +38,7 @@ export class BonusTokenService extends BaseHttpService { const connectionUrl = `${this.apiUrl.base + this.apiUrl.bonustoken + this.apiUrl.find}`; return this.http.post<BonusToken[]>(connectionUrl, { properties: { - userId: userId + accountId: userId } }).pipe( tap(() => ''), @@ -48,7 +48,7 @@ export class BonusTokenService extends BaseHttpService { deleteToken(roomId: string, commentId: string, userId: string) { const connectionUrl = `${this.apiUrl.base + this.apiUrl.bonustoken + this.apiUrl.delete}` - + `?roomid=${roomId}&commentid=${commentId}&userid=${userId}`; + + `?roomid=${roomId}&commentid=${commentId}&accountId=${userId}`; return this.http.delete<BonusToken>(connectionUrl, httpOptions).pipe( tap(_ => ''), catchError(this.handleError<BonusToken>('deleteToken')) diff --git a/src/app/services/http/comment-settings.service.ts b/src/app/services/http/comment-settings.service.ts deleted file mode 100644 index 400a08f0affd370d1d843f40d434b4b5c76d8ccf..0000000000000000000000000000000000000000 --- a/src/app/services/http/comment-settings.service.ts +++ /dev/null @@ -1,50 +0,0 @@ -import { Injectable } from '@angular/core'; -import { HttpClient, HttpHeaders } from '@angular/common/http'; -import { Observable } from 'rxjs'; -import { CommentSettings } from '../../models/comment-settings'; -import { catchError, tap } from 'rxjs/operators'; -import { BaseHttpService } from './base-http.service'; - -const httpOptions = { - headers: new HttpHeaders({ 'Content-Type': 'application/json' }) -}; - -@Injectable() -export class CommentSettingsService extends BaseHttpService { - private apiUrl = { - base: '/api', - settings: '/settings', - }; - - constructor(private http: HttpClient) { - super(); - } - - get(id: string): Observable<CommentSettings> { - const connectionUrl = `${this.apiUrl.base}${this.apiUrl.settings}/${id}`; - return this.http.get<CommentSettings>(connectionUrl, httpOptions).pipe( - tap(_ => ''), - catchError(this.handleError<CommentSettings>('addComment')) - ); - } - - add(settings: CommentSettings): Observable<CommentSettings> { - const connectionUrl = this.apiUrl.base + this.apiUrl.settings + '/'; - return this.http.post<CommentSettings>( - connectionUrl, - settings, - httpOptions - ).pipe( - tap(_ => ''), - catchError(this.handleError<CommentSettings>('addCommentSettings')) - ); - } - - update(settings: CommentSettings): Observable<CommentSettings> { - const connectionUrl = this.apiUrl.base + this.apiUrl.settings + '/' + settings.roomId; - return this.http.put(connectionUrl, settings, httpOptions).pipe( - tap(_ => ''), - catchError(this.handleError<any>('updateCommentSettings')) - ); - } -} diff --git a/src/app/services/http/comment.service.ts b/src/app/services/http/comment.service.ts index 1208e34c88fac917aea768450bad3fb972421912..a3ed74dcfc46f416e42fa6cb82bb4ade5cea074f 100644 --- a/src/app/services/http/comment.service.ts +++ b/src/app/services/http/comment.service.ts @@ -4,6 +4,8 @@ import { Observable } from 'rxjs'; import { Comment } from '../../models/comment'; import { catchError, tap, map } from 'rxjs/operators'; import { BaseHttpService } from './base-http.service'; +import { TSMap } from 'typescript-map'; +import { Vote } from '../../models/vote'; const httpOptions = { headers: new HttpHeaders({ 'Content-Type': 'application/json' }) @@ -15,13 +17,50 @@ export class CommentService extends BaseHttpService { base: '/api', comment: '/comment', find: '/find', - count: '/count' + count: '/count', + vote: '/vote' }; constructor(private http: HttpClient) { super(); } + + answer(comment: Comment, answer: string): Observable<Comment> { + comment.answer = answer; + const changes = new TSMap<string, any>(); + changes.set('answer', comment.answer); + return this.patchComment(comment, changes); + } + + toggleRead(comment: Comment): Observable<Comment> { + comment.read = !comment.read; + const changes = new TSMap<string, any>(); + changes.set('read', comment.read); + return this.patchComment(comment, changes); + } + + toggleFavorite(comment: Comment): Observable<Comment> { + comment.favorite = !comment.favorite; + const changes = new TSMap<string, any>(); + changes.set('favorite', comment.favorite); + return this.patchComment(comment, changes); + } + + markCorrect(comment: Comment): Observable<Comment> { + const changes = new TSMap<string, any>(); + changes.set('correct', comment.correct); + return this.patchComment(comment, changes); + } + + toggleAck(comment: Comment): Observable<Comment> { + comment.ack = !comment.ack; + const changes = new TSMap<string, any>(); + changes.set('ack', comment.ack); + return this.patchComment(comment, changes); + } + + getComment(commentId: string): Observable<Comment> { const connectionUrl = `${this.apiUrl.base}${this.apiUrl.comment}/${commentId}`; return this.http.get<Comment>(connectionUrl, httpOptions).pipe( @@ -101,6 +140,30 @@ export class CommentService extends BaseHttpService { ); } + patchComment(comment: Comment, changes: TSMap<string, any>) { + const connectionUrl = this.apiUrl.base + this.apiUrl.comment + '/' + comment.id; + return this.http.patch(connectionUrl, changes, httpOptions).pipe( + tap(_ => ''), + catchError(this.handleError<any>('patchComment')) + ); + } + + highlight(comment: Comment) { + const connectionUrl = this.apiUrl.base + this.apiUrl.comment + '/' + comment.id + '/highlight'; + return this.http.patch(connectionUrl, httpOptions).pipe( + tap(_ => ''), + catchError(this.handleError<any>('highlightComment')) + ); + } + + lowlight(comment: Comment) { + const connectionUrl = this.apiUrl.base + this.apiUrl.comment + '/' + comment.id + '/lowlight'; + return this.http.patch(connectionUrl, httpOptions).pipe( + tap(_ => ''), + catchError(this.handleError<any>('lowlightComment')) + ); + } + deleteCommentsByRoomId(roomId: string): Observable<Comment> { const connectionUrl = `${this.apiUrl.base + this.apiUrl.comment}/byRoom?roomId=${roomId}`; return this.http.delete<Comment>(connectionUrl, httpOptions).pipe( @@ -120,6 +183,35 @@ export class CommentService extends BaseHttpService { ); } + + voteUp(comment: Comment, userId: string): Observable<Vote> { + const vote = { accountId: userId, commentId: comment.id, vote: 1 }; + const connectionUrl = this.apiUrl.base + this.apiUrl.vote + '/'; + return this.http.post<Vote>(connectionUrl, vote, httpOptions).pipe( + tap(_ => ''), + catchError(this.handleError<Vote>('voteUp')) + ); + } + + voteDown(comment: Comment, userId: string): Observable<Vote> { + const vote = { accountId: userId, commentId: comment.id, vote: -1 }; + const connectionUrl = this.apiUrl.base + this.apiUrl.vote + '/'; + return this.http.post<Vote>(connectionUrl, vote, httpOptions).pipe( + tap(_ => ''), + catchError(this.handleError<Vote>('voteUp')) + ); + } + + resetVote(comment: Comment, userId: string): Observable<Vote> { + const vote = { accountId: userId, commentId: comment.id, vote: 0 }; + const connectionUrl = this.apiUrl.base + this.apiUrl.vote + '/'; + return this.http.post<Vote>(connectionUrl, vote, httpOptions).pipe( + tap(_ => ''), + catchError(this.handleError<Vote>('voteUp')) + ); + } + + parseUserNumber(comment: Comment): Comment { comment.userNumber = this.hashCode(comment.creatorId); return comment; diff --git a/src/app/services/http/moderator.service.ts b/src/app/services/http/moderator.service.ts index 3243c4bea9f686d56785704992667e4b933afbba..8162ebea566daa43878709fed2585fd9773ab27e 100644 --- a/src/app/services/http/moderator.service.ts +++ b/src/app/services/http/moderator.service.ts @@ -41,8 +41,8 @@ export class ModeratorService extends BaseHttpService { ); } - delete(roomId: string, userId: string) { - const url = `${this.apiUrl.base + this.apiUrl.room}/${roomId + this.apiUrl.moderator}/${userId}`; + delete(roomId: string, accountId: string) { + const url = `${this.apiUrl.base + this.apiUrl.room}/${roomId + this.apiUrl.moderator}/${accountId}`; return this.http.delete(url, httpOptions).pipe( tap(_ => ''), catchError(this.handleError<any>('deleteModerator')) @@ -52,7 +52,7 @@ export class ModeratorService extends BaseHttpService { getUserId(loginId: string): Observable<User[]> { const url = `${this.apiUrl.base + this.apiUrl.user + this.apiUrl.find}`; return this.http.post<User[]>(url, { - properties: { loginId: loginId }, + properties: { email: loginId }, externalFilters: {} }).pipe( tap(() => ''), diff --git a/src/app/services/http/room.service.ts b/src/app/services/http/room.service.ts index 52d6e8032046084a34543b3304e1588fb54e7df1..3aff3f4c6641d0810298b342d6b2b6f1da1df620 100644 --- a/src/app/services/http/room.service.ts +++ b/src/app/services/http/room.service.ts @@ -79,7 +79,6 @@ export class RoomService extends BaseHttpService { getRoom(id: string): Observable<Room> { const connectionUrl = `${ this.apiUrl.base + this.apiUrl.rooms }/${ id }`; return this.http.get<Room>(connectionUrl).pipe( - map(room => this.parseExtensions(room)), tap(room => this.setRoomId(room)), catchError(this.handleError<Room>(`getRoom keyword=${ id }`)) ); @@ -88,7 +87,6 @@ export class RoomService extends BaseHttpService { getRoomByShortId(shortId: string): Observable<Room> { const connectionUrl = `${ this.apiUrl.base + this.apiUrl.rooms }/~${ shortId }`; return this.http.get<Room>(connectionUrl).pipe( - map(room => this.parseExtensions(room)), tap(room => this.setRoomId(room)), catchError(this.handleError<Room>(`getRoom shortId=${ shortId }`)) ); @@ -123,15 +121,6 @@ export class RoomService extends BaseHttpService { ); } - parseExtensions(room: Room): Room { - if (room.extensions) { - let extensions: TSMap<string, TSMap<string, any>> = new TSMap(); - extensions = room.extensions; - room.extensions = extensions; - } - return room; - } - setRoomId(room: Room): void { localStorage.setItem('roomId', room.id); } diff --git a/src/app/services/http/user.service.ts b/src/app/services/http/user.service.ts index 5f170436788e301b1a68fcb70085300f8094f984..afc3d86e020f8d02b68d2150b7cb168e1ab98480 100644 --- a/src/app/services/http/user.service.ts +++ b/src/app/services/http/user.service.ts @@ -53,7 +53,7 @@ export class UserService extends BaseHttpService { getIdByLoginId(loginId: string): Observable<User[]> { const url = `${this.apiUrl.base + this.apiUrl.user + this.apiUrl.find}`; return this.http.post<User[]>(url, { - properties: { loginId: loginId }, + properties: { email: loginId }, externalFilters: {} }).pipe( tap(() => ''), diff --git a/src/app/services/http/vote.service.ts b/src/app/services/http/vote.service.ts index fc136de1e7fe085dd62d55abcd5508e47d1b94b0..cd5417094709eb6e49d32c53928e807d4f08c2e2 100644 --- a/src/app/services/http/vote.service.ts +++ b/src/app/services/http/vote.service.ts @@ -27,7 +27,7 @@ export class VoteService extends BaseHttpService { const connectionUrl = `${this.apiUrl.base + this.apiUrl.vote + this.apiUrl.find}`; return this.http.post<Vote[]>(connectionUrl, { properties: { - userId: userId + accountId: userId }, externalFilters: { roomId: roomId diff --git a/src/app/services/websockets/ws-comment-service.service.ts b/src/app/services/websockets/ws-comment-service.service.ts index c53b1c26127e3e3d864ecc4a914641f0388070cd..e08ea411be3c0c81fe8090501000f401df2724ab 100644 --- a/src/app/services/websockets/ws-comment-service.service.ts +++ b/src/app/services/websockets/ws-comment-service.service.ts @@ -19,80 +19,6 @@ export class WsCommentServiceService { constructor(private wsConnector: WsConnectorService) { } - add(comment: Comment): void { - const message = new CreateComment(comment.roomId, comment.creatorId, comment.body, comment.tag); - this.wsConnector.send(`/queue/comment.command.create`, JSON.stringify(message)); - } - - answer(comment: Comment, answer: string): Comment { - comment.answer = answer; - const changes = new TSMap<string, any>(); - changes.set('answer', comment.answer); - this.patchComment(comment, changes); - return comment; - } - - toggleRead(comment: Comment): Comment { - comment.read = !comment.read; - const changes = new TSMap<string, any>(); - changes.set('read', comment.read); - this.patchComment(comment, changes); - return comment; - } - - toggleFavorite(comment: Comment): Comment { - comment.favorite = !comment.favorite; - const changes = new TSMap<string, any>(); - changes.set('favorite', comment.favorite); - this.patchComment(comment, changes); - return comment; - } - - markCorrect(comment: Comment): Comment { - const changes = new TSMap<string, any>(); - changes.set('correct', comment.correct); - this.patchComment(comment, changes); - return comment; - } - - toggleAck(comment: Comment): Comment { - comment.ack = !comment.ack; - const changes = new TSMap<string, any>(); - changes.set('ack', comment.ack); - this.patchComment(comment, changes); - return comment; - } - - voteUp(comment: Comment, userId: string): void { - const message = new UpVote(userId, comment.id); - this.wsConnector.send(`/queue/vote.command.upvote`, JSON.stringify(message)); - } - - voteDown(comment: Comment, userId: string): void { - const message = new DownVote(userId, comment.id); - this.wsConnector.send(`/queue/vote.command.downvote`, JSON.stringify(message)); - } - - resetVote(comment: Comment, userId: string): void { - const message = new ResetVote(userId, comment.id); - this.wsConnector.send(`/queue/vote.command.resetvote`, JSON.stringify(message)); - } - - private patchComment(comment: Comment, changes: TSMap<string, any>): void { - const message = new PatchComment(comment.id, changes); - this.wsConnector.send(`/queue/comment.command.patch`, JSON.stringify(message)); - } - - highlight(comment: Comment) { - const message = new HighlightComment(comment.id, true); - this.wsConnector.send(`/queue/comment.command.highlight`, JSON.stringify(message)); - } - - lowlight(comment: Comment) { - const message = new HighlightComment(comment.id, false); - this.wsConnector.send(`/queue/comment.command.highlight`, JSON.stringify(message)); - } - getCommentStream(roomId: string): Observable<IMessage> { return this.wsConnector.getWatcher(`/topic/${roomId}.comment.stream`); }