diff --git a/src/app/components/participant/_dialogs/user-bonus-token/user-bonus-token.component.ts b/src/app/components/participant/_dialogs/user-bonus-token/user-bonus-token.component.ts index 90f6484704241e08466268a07cf1332436b3227e..ff2d6cc32fec68ded6e4db5906650be5f99cf310 100644 --- a/src/app/components/participant/_dialogs/user-bonus-token/user-bonus-token.component.ts +++ b/src/app/components/participant/_dialogs/user-bonus-token/user-bonus-token.component.ts @@ -9,6 +9,8 @@ import { Router } from '@angular/router'; import { TranslateService } from '@ngx-translate/core'; import { NotificationService } from '../../../../services/util/notification.service'; import { ExplanationDialogComponent } from '../../../shared/_dialogs/explanation-dialog/explanation-dialog.component'; +import { ModeratorService } from '../../../../services/http/moderator.service'; +import { map, switchMap } from 'rxjs/operators'; export class MinRoom { name: string; @@ -36,6 +38,7 @@ export class UserBonusTokenComponent implements OnInit { private bonusTokenService: BonusTokenService, private roomService: RoomService, private dialogRef: MatDialogRef<UserBonusTokenComponent>, + private moderatorService: ModeratorService, protected router: Router, private translationService: TranslateService, private dialog: MatDialog, @@ -43,6 +46,10 @@ export class UserBonusTokenComponent implements OnInit { ) { } + private static escapeForEmail(text: string): string { + return encodeURIComponent(text.replace(/(\r\n)|\n/gm, '\r\n')); + } + ngOnInit() { this.bonusTokenService.getTokensByUserId(this.userId).subscribe(list => { list.sort((a, b) => (a.token > b.token) ? 1 : -1); @@ -68,13 +75,7 @@ export class UserBonusTokenComponent implements OnInit { } getTokensByRoom(shortId: string): string { - let tokens = ''; - for (const bt of this.bonusTokensMixin) { - if (bt.roomShortId === shortId) { - tokens += bt.token + '%0D%0A%0D%0A'; - } - } - return tokens; + return this.bonusTokensMixin.filter(bt => bt.roomShortId === shortId).map(bt => bt.token).join('\n\n'); } openHelp() { @@ -92,16 +93,26 @@ export class UserBonusTokenComponent implements OnInit { openMail() { if (this.currentRoom) { - const sessionName = this.currentRoom.name; - const sessionId = this.currentRoom.id; - const translationList = ['user-bonus-token.mail-subject', 'user-bonus-token.mail-body-1', 'user-bonus-token.mail-body-2', - 'user-bonus-token.mail-body-3', 'user-bonus-token.mail-body-4']; - let mailText: string; - this.translationService.get(translationList).subscribe(msgs => { - mailText = 'mailto:?subject=' + msgs[translationList[0]] + sessionName + '%C2%AB&body=' + msgs[translationList[1]] + sessionName - + msgs[translationList[2]] + sessionId + msgs[translationList[3]] + this.getTokensByRoom(sessionId) + msgs[translationList[4]]; - window.location.href = mailText; - }); + this.roomService.getRoomByShortId(this.currentRoom.id) + .pipe( + switchMap((room) => this.moderatorService.get(room.id) + .pipe( + switchMap((moderators) => { + const moderatorIds = moderators.map((moderator) => moderator.accountId); + const userIds = [room.ownerId, ...moderatorIds]; + return this.moderatorService.getUserData(userIds) + .pipe( + map((users) => { + users.sort((a, b) => userIds.indexOf(a.id) - userIds.indexOf(b.id)); + return users.map((user) => (user as any).email as string).filter(e => e); + }) + ); + }) + )) + ) + .subscribe(ids => { + this.send(ids[0] || '', ids.slice(1)); + }); } else { this.translationService.get('user-bonus-token.please-choose').subscribe(msg => { this.notificationService.show(msg); @@ -109,10 +120,32 @@ export class UserBonusTokenComponent implements OnInit { } } - /** - * Returns a lambda which closes the dialog on call. - */ buildDeclineActionCallback(): () => void { return () => this.dialogRef.close(); } + + private send(ownerEmail: string, moderatorEmails: string[]) { + const sessionName = this.currentRoom.name; + const sessionId = this.currentRoom.id; + const translationList = ['user-bonus-token.mail-subject', 'user-bonus-token.mail-body']; + const escapedModeratorEmails = moderatorEmails.reduce((acc, value) => { + if (acc.length > 0) { + return acc + ',' + UserBonusTokenComponent.escapeForEmail(value); + } else { + return UserBonusTokenComponent.escapeForEmail(value); + } + }, ''); + let mailText: string; + this.translationService.get(translationList, { + sessionName, + sessionId, + tokens: this.getTokensByRoom(sessionId) + }).subscribe(msgs => { + mailText = 'mailto:' + UserBonusTokenComponent.escapeForEmail(ownerEmail) + '?' + + 'subject=' + UserBonusTokenComponent.escapeForEmail(msgs[translationList[0]]) + '&' + + (escapedModeratorEmails.length > 0 ? 'cc=' + escapedModeratorEmails + '&' : '') + + 'body=' + UserBonusTokenComponent.escapeForEmail(msgs[translationList[1]]); + window.location.href = mailText; + }); + } } diff --git a/src/assets/i18n/home/de.json b/src/assets/i18n/home/de.json index dc4263b916b7fdcd69bd195bce28acf32451d72f..418c32c985d267b9f984c7c638ada31c87c0373c 100644 --- a/src/assets/i18n/home/de.json +++ b/src/assets/i18n/home/de.json @@ -354,11 +354,8 @@ "header": "Sterne für Bonuspunkte einlösen", "no-bonus": "Du hast noch keinen Stern für eine gute Frage erhalten.", "redeem-tokens": "Sterne per Mail einlösen", - "mail-subject": "Bitte%20um%20Einl%C3%B6sung%20meiner%20Tokens%20aus%20der%20%C2%BBfrag.jetzt%C2%AB-Sitzung%20%C2%BB", - "mail-body-1": "Hallo%2C%0D%0A%0D%0Aich%20habe%20heute%20in%20der%20%C2%BBfrag.jetzt%C2%AB-Sitzung%20%C2%BB", - "mail-body-2": "%C2%AB%20mit%20dem%20Raum-Code%20%C2%BB", - "mail-body-3": "%C2%AB%20die%20folgenden%20Tokens%20erhalten%3A%0D%0A%0D%0A", - "mail-body-4": "%0D%0A%0D%0AIch%20bitte%20um%20die%20Einl%C3%B6sung%20in%20Bonuspunkte.%0D%0A%0D%0ADanke%20f%C3%BCr%20%C2%BBfrag.jetzt%C2%AB!%0D%0A%0D%0A---", + "mail-subject": "Bitte um Einlösung meiner Tokens aus der »frag.jetzt«-Sitzung »{{sessionName}}«", + "mail-body": "Hallo,\n\nich habe heute in der »frag.jetzt«-Sitzung »{{sessionName}}« mit dem Raum-Code »{{sessionId}}« die folgenden Tokens erhalten:\n\n{{tokens}}\n\n\nIch bitte um die Einlösung in Bonuspunkte.\n\nDanke für »frag.jetzt«!\n\n---", "choose-session": "Wähle eine Sitzung aus", "please-choose": "Bitte wähle zuerst eine Sitzung aus!" }, diff --git a/src/assets/i18n/home/en.json b/src/assets/i18n/home/en.json index 1fd5379958abbf9ededf5a1cc331084e3506353a..71d8b52de92ac2d6d21c1d7dbfdd8478df9c7e70 100644 --- a/src/assets/i18n/home/en.json +++ b/src/assets/i18n/home/en.json @@ -356,11 +356,8 @@ "header": "Redeem stars for bonus", "no-bonus": "You haven't received a bonus star for a good question yet.", "redeem-tokens": "Redeem stars by mail", - "mail-subject": "Request%20to%20redeem%20my%20tokens%20from%20the%20%C2%BBfrag.jetzt%C2%AB-session%20%C2%BB", - "mail-body-1": "Hello%2C%0D%0A%0D%0Ai%20have%20received%20the%20following%20tokens%20today%20in%20the%20%C2%BBfrag.jetzt%C2%AB-session%20%C2%BB", - "mail-body-2": "%C2%AB%20with%20the%20session%20code%20%C2%BB", - "mail-body-3": "%C2%AB%3A%0D%0A%0D%0A", - "mail-body-4": "%0D%0A%0D%0AI%20ask%20for%20the%20redemption%20in%20bonus%20points.%0D%0A%0D%0AThanks%20for%20%C2%BBfrag.jetzt%C2%AB!%0D%0A%0D%0A---", + "mail-subject": "Request to redeem my tokens from the »frag.jetzt«-session »{{sessionName}}«", + "mail-body": "Hello,\n\nI have received the following tokens today in the »frag.jetzt«-session »{{sessionName}}« with the session code »{{sessionId}}«:\n\n{{tokens}}\n\n\nI ask for the redemption in bonus points.\n\nThanks for »frag.jetzt«!\n\n---", "choose-session": "Choose a session", "please-choose": "Please select a session first!" }, diff --git a/src/assets/i18n/participant/de.json b/src/assets/i18n/participant/de.json index 09cd99c732af9f3700dc2d8ad66e4e89d210fd86..77b687cb526ad48ad343d3f6073335e931d02916 100644 --- a/src/assets/i18n/participant/de.json +++ b/src/assets/i18n/participant/de.json @@ -462,11 +462,8 @@ "header": "Sterne für Bonuspunkte einlösen", "no-bonus": "Du hast noch keinen Stern für eine gute Frage erhalten.", "redeem-tokens": "Sterne per Mail einlösen", - "mail-subject": "Bitte%20um%20Einl%C3%B6sung%20meiner%20Tokens%20aus%20der%20%C2%BBfrag.jetzt%C2%AB-Sitzung%20%C2%BB", - "mail-body-1": "Hallo%2C%0D%0A%0D%0Aich%20habe%20heute%20in%20der%20%C2%BBfrag.jetzt%C2%AB-Sitzung%20%C2%BB", - "mail-body-2": "%C2%AB%20mit%20dem%20Raum-Code%20%C2%BB", - "mail-body-3": "%C2%AB%20die%20folgenden%20Tokens%20erhalten%3A%0D%0A%0D%0A", - "mail-body-4": "%0D%0A%0D%0AIch%20bitte%20um%20die%20Einl%C3%B6sung%20in%20Bonuspunkte.%0D%0A%0D%0ADanke%20f%C3%BCr%20%C2%BBfrag.jetzt%C2%AB!%0D%0A%0D%0A---", + "mail-subject": "Bitte um Einlösung meiner Tokens aus der »frag.jetzt«-Sitzung »{{sessionName}}«", + "mail-body": "Hallo,\n\nich habe heute in der »frag.jetzt«-Sitzung »{{sessionName}}« mit dem Raum-Code »{{sessionId}}« die folgenden Tokens erhalten:\n\n{{tokens}}\n\n\nIch bitte um die Einlösung in Bonuspunkte.\n\nDanke für »frag.jetzt«!\n\n---", "choose-session": "Wähle eine Sitzung aus", "please-choose": "Bitte wähle zuerst eine Sitzung aus!" }, diff --git a/src/assets/i18n/participant/en.json b/src/assets/i18n/participant/en.json index 33d895bd490c1e24bd8d8d9d4d84bdc79be6e5c7..e6e856110575d24dfa7ccb9154462a2338767567 100644 --- a/src/assets/i18n/participant/en.json +++ b/src/assets/i18n/participant/en.json @@ -468,11 +468,8 @@ "header": "Redeem stars for bonus", "no-bonus": "You haven't received a bonus star for a good question yet.", "redeem-tokens": "Redeem stars by mail", - "mail-subject": "Request%20to%20redeem%20my%20tokens%20from%20the%20%C2%BBfrag.jetzt%C2%AB-session%20%C2%BB", - "mail-body-1": "Hello%2C%0D%0A%0D%0Ai%20have%20received%20the%20following%20tokens%20today%20in%20the%20%C2%BBfrag.jetzt%C2%AB-session%20%C2%BB", - "mail-body-2": "%C2%AB%20with%20the%20session%20code%20%C2%BB", - "mail-body-3": "%C2%AB%3A%0D%0A%0D%0A", - "mail-body-4": "%0D%0A%0D%0AI%20ask%20for%20the%20redemption%20in%20bonus%20points.%0D%0A%0D%0AThanks%20for%20%C2%BBfrag.jetzt%C2%AB!%0D%0A%0D%0A---", + "mail-subject": "Request to redeem my tokens from the »frag.jetzt«-session »{{sessionName}}«", + "mail-body": "Hello,\n\nI have received the following tokens today in the »frag.jetzt«-session »{{sessionName}}« with the session code »{{sessionId}}«:\n\n{{tokens}}\n\n\nI ask for the redemption in bonus points.\n\nThanks for »frag.jetzt«!\n\n---", "choose-session": "Choose a session", "please-choose": "Please select a session first!" },