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 36d2a571404b6755f4191127e9ee76bdab868b60..d70d63185560555058b349c3210407d10f4cbfa9 100644 --- a/src/app/components/shared/comment-list/comment-list.component.ts +++ b/src/app/components/shared/comment-list/comment-list.component.ts @@ -196,6 +196,8 @@ export class CommentListComponent implements OnInit, OnDestroy { c.id = payload.id; c.timestamp = payload.timestamp; c.tag = payload.tag; + c.creatorId = payload.creatorId; + c.userNumber = this.commentService.hashCode(c.creatorId); this.announceNewComment(c.body); @@ -309,8 +311,6 @@ export class CommentListComponent implements OnInit, OnDestroy { } filterComments(type: string, compare?: any): void { - console.log(type); - console.log(compare); this.currentFilter = type; if (type === '') { this.filteredComments = this.comments; diff --git a/src/app/rx-stomp.config.ts b/src/app/rx-stomp.config.ts index c1ab0b4525b53e738e9f560f4d389a527bbc335e..f6bdce0eeeaabb5d3cbc1c80cfb646af7e32c570 100644 --- a/src/app/rx-stomp.config.ts +++ b/src/app/rx-stomp.config.ts @@ -3,8 +3,8 @@ import { environment } from './../environments/environment'; export const ARSRxStompConfig: RxStompConfig = { // Which server? - brokerURL: (window.location.protocol === 'http:' ) ? - `ws://${window.location.hostname}:/api/ws/websocket` : `wss://${window.location.hostname}/api/ws/websocket`, + brokerURL: ((window.location.protocol === 'http:') ? 'ws' : 'wss') + + `://${window.location.host}/api/ws/websocket`, connectHeaders: { login: 'guest', diff --git a/src/app/services/http/comment.service.ts b/src/app/services/http/comment.service.ts index bf5196cc9f83856f8e8f137b181b5fb88e0fbd73..1208e34c88fac917aea768450bad3fb972421912 100644 --- a/src/app/services/http/comment.service.ts +++ b/src/app/services/http/comment.service.ts @@ -2,7 +2,7 @@ import { Injectable } from '@angular/core'; import { HttpClient, HttpHeaders } from '@angular/common/http'; import { Observable } from 'rxjs'; import { Comment } from '../../models/comment'; -import { catchError, tap } from 'rxjs/operators'; +import { catchError, tap, map } from 'rxjs/operators'; import { BaseHttpService } from './base-http.service'; const httpOptions = { @@ -25,6 +25,7 @@ export class CommentService extends BaseHttpService { getComment(commentId: string): Observable<Comment> { const connectionUrl = `${this.apiUrl.base}${this.apiUrl.comment}/${commentId}`; return this.http.get<Comment>(connectionUrl, httpOptions).pipe( + map(comment => this.parseUserNumber(comment)), tap(_ => ''), catchError(this.handleError<Comment>('getComment')) ); @@ -33,7 +34,8 @@ export class CommentService extends BaseHttpService { addComment(comment: Comment): Observable<Comment> { const connectionUrl = this.apiUrl.base + this.apiUrl.comment + '/'; return this.http.post<Comment>(connectionUrl, - { roomId: comment.roomId, body: comment.body, + { + roomId: comment.roomId, body: comment.body, read: comment.read, creationTimestamp: comment.timestamp }, httpOptions).pipe( tap(_ => ''), @@ -55,6 +57,9 @@ export class CommentService extends BaseHttpService { properties: { roomId: roomId, ack: true }, externalFilters: {} }, httpOptions).pipe( + map(commentList => { + return commentList.map(comment => this.parseUserNumber(comment)); + }), tap(_ => ''), catchError(this.handleError<Comment[]>('getComments', [])) ); @@ -66,6 +71,9 @@ export class CommentService extends BaseHttpService { properties: { roomId: roomId, ack: false }, externalFilters: {} }, httpOptions).pipe( + map(commentList => { + return commentList.map(comment => this.parseUserNumber(comment)); + }), tap(_ => ''), catchError(this.handleError<Comment[]>('getComments', [])) ); @@ -77,6 +85,9 @@ export class CommentService extends BaseHttpService { properties: { roomId: roomId }, externalFilters: {} }, httpOptions).pipe( + map(commentList => { + return commentList.map(comment => this.parseUserNumber(comment)); + }), tap(_ => ''), catchError(this.handleError<Comment[]>('getComments', [])) ); @@ -108,4 +119,19 @@ export class CommentService extends BaseHttpService { catchError(this.handleError<number>('countByRoomId', 0)) ); } + + parseUserNumber(comment: Comment): Comment { + comment.userNumber = this.hashCode(comment.creatorId); + return comment; + } + + hashCode(s) { + let hash; + for (let i = 0, h = 0; i < s.length; i++) { + hash = Math.abs(Math.imul(31, hash) + s.charCodeAt(i) | 0); + } + const userNumberString = String(hash); + hash = +userNumberString.substring(userNumberString.length - 4, userNumberString.length); + return hash; + } } diff --git a/tslint.json b/tslint.json index 9991821561d39edf860990413dfcb3d5ccc16deb..1ea028f4bc6611bb799e9892982a31e7eb1d6795 100644 --- a/tslint.json +++ b/tslint.json @@ -47,7 +47,7 @@ } ], "no-arg": true, - "no-bitwise": true, + "no-bitwise": false, "no-console": [ true, "debug",