Commit 3b219444 authored by Curtis Adam's avatar Curtis Adam
Browse files

Merge branch 'notification_hotfixes' into 'staging'

Fix deadline returning the wrong date and display the hours

See merge request arsnova/cards!1071
parents 1fe9a3eb 60ca31ab
......@@ -11,7 +11,7 @@
"body": {
"title": "Erinnerung",
"greetings": "Hallo __user__,",
"message": "es ist an der Zeit, einen Blick auf deine Lernkarten zu werfen! Der Wiederholungs-Algorithmus hat berechnet, dass <strong>__cards__ Karten aus »__cardset__«</strong> zu lernen sind. Du hast noch bis <strong>__deadline__</strong> Zeit, um die Karten zu lernen."
"message": "es ist an der Zeit, einen Blick auf deine Lernkarten zu werfen! Der Wiederholungs-Algorithmus hat berechnet, dass <strong>__cards__ Karten aus »__cardset__«</strong> zu lernen sind. Du hast noch bis <strong>__deadline__ Uhr</strong> Zeit, um die Karten zu lernen."
}
},
"reminder": {
......@@ -23,7 +23,7 @@
"body": {
"title": "Erinnerung",
"greetings": "Hallo __user__,",
"message": "»__cardset__« benötigt deine Aufmerksamkeit: In Kürze setzt der Leitner-Algorithmus deine Lernstatistik zurück, wenn du dein Lernpensum nicht erfüllst. Du hast noch bis <strong>__deadline__</strong> Zeit, um die Karten zu lernen."
"message": "»__cardset__« benötigt deine Aufmerksamkeit: In Kürze setzt der Leitner-Algorithmus deine Lernstatistik zurück, wenn du dein Lernpensum nicht erfüllst. Du hast noch bis <strong>__deadline__ Uhr</strong> Zeit, um die Karten zu lernen."
}
},
"reset": {
......@@ -35,7 +35,7 @@
"body": {
"title": "Erinnerung",
"greetings": "Hallo __user__,",
"message": "es ist an der Zeit, einen Blick auf deine Lernkarten zu werfen! Der Wiederholungs-Algorithmus hat berechnet, dass <strong>__cards__ Karten aus »__cardset__«</strong> zu lernen sind. Du hast noch bis <strong>__deadline__</strong> Zeit, um die Karten zu lernen."
"message": "es ist an der Zeit, einen Blick auf deine Lernkarten zu werfen! Der Wiederholungs-Algorithmus hat berechnet, dass <strong>__cards__ Karten aus »__cardset__«</strong> zu lernen sind. Du hast noch bis <strong>__deadline__ Uhr</strong> Zeit, um die Karten zu lernen."
}
}
},
......@@ -47,9 +47,9 @@
}
},
"webPush": {
"new": "»__cardset__« __cards__ Karten bis __deadline__",
"reminder": "»__cardset__« __cards__ Karten bis __deadline__",
"reset": "»__cardset__« __cards__ Karten bis __deadline__"
"new": "»__cardset__« __cards__ Karten bis __deadline__ Uhr",
"reminder": "»__cardset__« __cards__ Karten bis __deadline__ Uhr",
"reset": "»__cardset__« __cards__ Karten bis __deadline__ Uhr"
},
"title": "Nachrichten",
"clearAll": "Leeren",
......
import {Leitner} from "../imports/api/subscriptions/leitner.js";
import {Meteor} from "meteor/meteor";
import {Bonus} from "../imports/util/bonus";
/**
* Class used for generating text of mail and web-push messages
......@@ -8,7 +10,7 @@ export class Notifications {
* @param {string} user_id - The id of the user
* @returns {string} - The name of the user
* */
getName (user_id) {
static getName (user_id) {
if (!Meteor.isServer) {
throw new Meteor.Error("not-authorized");
} else {
......@@ -20,13 +22,9 @@ export class Notifications {
/** Function returns the amount of cards that the user has to learn from the cardset
* @param {string} cardset_id - The id of the cardset from which to get the card count from
* @param {string} user_id - The id of the user
* @param {string} testUser - id of the test user if the function got called by a test notification
* @returns {number} - The amount of cards that the user has to learn from the cardset
* */
getActiveCardsCount (cardset_id, user_id, testUser = undefined) {
if (testUser !== undefined) {
user_id = testUser;
}
static getActiveCardsCount (cardset_id, user_id) {
if (!Meteor.isServer) {
throw new Meteor.Error("not-authorized");
} else {
......@@ -37,4 +35,20 @@ export class Notifications {
}).count();
}
}
static getDeadline (cardset, user_id) {
let stringFormat = "dddd, Do MMMM HH:mm";
let adjustedHours = {
hour: Meteor.settings.public.dailyCronjob.executeAtHour,
minute: 0
};
let active = Leitner.findOne({cardset_id: cardset._id, user_id: user_id, active: true});
let deadline = moment(active.currentDate).add(cardset.daysBeforeReset, 'days').set(adjustedHours);
let cardsetLearningEnd = moment(cardset.learningEnd).set(adjustedHours);
if (deadline > cardsetLearningEnd && Bonus.isInBonus(cardset._id, user_id)) {
return cardsetLearningEnd.locale("de").format(stringFormat);
} else {
return deadline.locale("de").format(stringFormat);
}
}
}
import {Meteor} from "meteor/meteor";
import {Email} from "meteor/email";
import {Bonus} from "../imports/util/bonus.js";
import {Leitner} from "../imports/api/subscriptions/leitner.js";
import {Notifications} from "./notifications.js";
import {AdminSettings} from "../imports/api/subscriptions/adminSettings.js";
import {Cardsets} from "../imports/api/subscriptions/cardsets.js";
......@@ -37,10 +35,9 @@ export class MailNotifier {
if (!Meteor.isServer) {
throw new Meteor.Error("not-authorized");
} else {
let notifier = new Notifications();
let firstName = getAuthorName(user_id, false, true);
let cards = notifier.getActiveCardsCount(cardset._id, user_id);
let deadline = moment(cardset.learningEnd).locale("de").format("dddd, Do MMMM");
let cards = Notifications.getActiveCardsCount(cardset._id, user_id);
let deadline = Notifications.getDeadline(cardset, user_id);
let subject;
let headerTitle;
......@@ -78,7 +75,7 @@ export class MailNotifier {
bodyMessage = TAPi18n.__('notifications.mail.leitner.new.body.message', {cardset: cardset.name, cards: cards, deadline: deadline}, ServerStyle.getServerLanguage());
headerColors = config.mailColors.header.leitner.new;
}
this.sendMail(this.getMail(user_id), subject, headerTitle, headerButton, bodyTitle, bodyGreetings, bodyMessage,cardset._id, headerColors);
this.sendMail(this.getMail(user_id), subject, headerTitle, headerButton, bodyTitle, bodyGreetings, bodyMessage, cardset._id, headerColors);
}
}
......
import {Meteor} from "meteor/meteor";
import {Notifications} from "./notifications.js";
import {Leitner} from "../imports/api/subscriptions/leitner.js";
import {AdminSettings} from "../imports/api/subscriptions/adminSettings.js";
import {Cardsets} from "../imports/api/subscriptions/cardsets.js";
import {ServerStyle} from "../imports/util/styles";
function getDateString(date) {
let dateFormat = "dddd";
return moment(date).locale(ServerStyle.getServerLanguage()).format(dateFormat);
}
/**
* Class used for generating the text of web-push notifications
*/
export class WebNotifier {
/** Function returns the deadline text-message depending on if the deadline goes beyond the cardsets learning-phase
* @param {Object} cardset - The cardset object for the deadline
* @param {string} user_id - The id of the user
* @param {string} testUser - id of the test user if the function got called by a test notification
* @returns {string} - The deadline text-message
* */
getDeadline (cardset, user_id, testUser = undefined) {
if (!Meteor.isServer) {
throw new Meteor.Error("not-authorized");
} else {
if (testUser !== undefined) {
user_id = testUser;
}
let active = Leitner.findOne({cardset_id: cardset._id, user_id: user_id, active: true});
let deadline = new Date();
if (active !== undefined) {
deadline = new Date(active.currentDate.getTime() + cardset.daysBeforeReset * 86400000);
}
if (deadline.getTime() > cardset.learningEnd.getTime()) {
return getDateString(cardset.learningEnd);
} else {
return getDateString(deadline);
}
}
}
/** Function creates and sends the Web-Push payload message
* @param {Object} cardset - The cardset from the active learning-phase
* @param {string} user_id - The id of the user
......@@ -51,17 +18,20 @@ export class WebNotifier {
if (!Meteor.isServer) {
throw new Meteor.Error("not-authorized");
} else {
let notifier = new Notifications();
let message;
let deadlineUser = user_id;
if (testUser !== undefined) {
deadlineUser = testUser;
}
switch (messageType) {
case 1:
message = TAPi18n.__('notifications.webPush.reminder', {cardset: cardset.name, cards: notifier.getActiveCardsCount(cardset._id, user_id, testUser), deadline: this.getDeadline(cardset, user_id, testUser)}, ServerStyle.getServerLanguage());
message = TAPi18n.__('notifications.webPush.reminder', {cardset: cardset.name, cards: Notifications.getActiveCardsCount(cardset._id, deadlineUser), deadline: Notifications.getDeadline(cardset, deadlineUser)}, ServerStyle.getServerLanguage());
break;
case 2:
message = TAPi18n.__('notifications.webPush.reset', {cardset: cardset.name, cards: notifier.getActiveCardsCount(cardset._id, user_id, testUser), deadline: this.getDeadline(cardset, user_id, testUser)}, ServerStyle.getServerLanguage());
message = TAPi18n.__('notifications.webPush.reset', {cardset: cardset.name, cards: Notifications.getActiveCardsCount(cardset._id, deadlineUser), deadline: Notifications.getDeadline(cardset, deadlineUser)}, ServerStyle.getServerLanguage());
break;
default:
message = TAPi18n.__('notifications.webPush.new', {cardset: cardset.name, cards: notifier.getActiveCardsCount(cardset._id, user_id, testUser), deadline: this.getDeadline(cardset, user_id, testUser)}, ServerStyle.getServerLanguage());
message = TAPi18n.__('notifications.webPush.new', {cardset: cardset.name, cards: Notifications.getActiveCardsCount(cardset._id, deadlineUser), deadline: Notifications.getDeadline(cardset, deadlineUser)}, ServerStyle.getServerLanguage());
}
Meteor.call("sendPushNotificationsToUser", user_id, message);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment