mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-14 21:27:23 +01:00
Notifications v2 and Bailey API (#9716)
* Added initial bailey api
* wip
* implement new panel header
* Fixed lint
* add ability to mark notification as seen
* add notification count, remove top badge from user and add ability to mark multiple notifications as seen
* add support dismissall and mark all as read
* do not dismiss actionable notif
* mark as seen when menu is opened instead of closed
* implement ordering, list of actionable notifications
* add groups messages and fix badges count
* add notifications for received cards
* send card received notification to target not sender
* rename notificaion field
* fix integration tests
* mark cards notifications as read and update tests
* add mystery items notifications
* add unallocated stats points notifications
* fix linting
* simplify code
* refactoring and fixes
* fix dropdown opening
* start splitting notifications into their own component
* add notifications for inbox messages
* fix unit tests
* fix default buttons styles
* add initial bailey support
* add title and tests to new stuff notification
* add notification if a group task needs more work
* add tests and fixes for marking a task as needing more work
* make sure user._v is updated
* remove console.log
* notification: hover status and margins
* start styling notifications, add separate files and basic functionalities
* fix tests
* start adding mystery items notification
* wip card notification
* fix cards text
* initial implementation inbox messages
* initial implementation group messages
* disable inbox notifications until mobile is ready
* wip group chat messages
* finish mystery and card notifications
* add bailey notification and fix a lot of stuff
* start adding guilds and parties invitations
* misc invitation fixes
* fix lint issues
* remove old code and add key to notifications
* fix tests
* remove unused code
* add link for public guilds invite
* starts to implement needs work notification design and feature
* fixes to needs work, add group task approved notification
* finish needs work feature
* lots of fixes
* implement quest notification
* bailey fixes and static page
* routing fixes
* fixes # this.$store.dispatch(guilds:join, {groupId: group.id, type: party});
* read notifications on click
* chat notifications
* fix tests for chat notifications
* fix chat notification test
* fix tests
* fix tests (again)
* try awaiting
* remove only
* more sleep
* add bailey tests
* fix icons alignment
* fix issue with multiple points notifications
* remove merge code
* fix rejecting guild invitation
* make remove area bigger
* fix error with notifications and add migration
* fix migration
* fix typos
* add cleanup migration too
* notifications empty state, new counter color, fix marking messages as seen in guilds
* fixes
* add image and install correct packages
* fix mongoose version
* update bailey
* typo
* make sure chat is marked as read after other requests
This commit is contained in:
@@ -156,6 +156,19 @@ export default {
|
||||
let lastShownNotifications = [];
|
||||
let alreadyReadNotification = [];
|
||||
|
||||
// A list of notifications handled by this component,
|
||||
// NOTE: Those not listed here won't be handled at all!
|
||||
const handledNotifications = {};
|
||||
|
||||
[
|
||||
'GUILD_PROMPT', 'DROPS_ENABLED', 'REBIRTH_ENABLED', 'WON_CHALLENGE', 'STREAK_ACHIEVEMENT',
|
||||
'ULTIMATE_GEAR_ACHIEVEMENT', 'REBIRTH_ACHIEVEMENT', 'GUILD_JOINED_ACHIEVEMENT',
|
||||
'CHALLENGE_JOINED_ACHIEVEMENT', 'INVITED_FRIEND_ACHIEVEMENT', 'NEW_CONTRIBUTOR_LEVEL',
|
||||
'CRON', 'SCORED_TASK', 'LOGIN_INCENTIVE',
|
||||
].forEach(type => {
|
||||
handledNotifications[type] = true;
|
||||
});
|
||||
|
||||
return {
|
||||
yesterDailies: [],
|
||||
levelBeforeYesterdailies: 0,
|
||||
@@ -165,54 +178,31 @@ export default {
|
||||
alreadyReadNotification,
|
||||
isRunningYesterdailies: false,
|
||||
nextCron: null,
|
||||
handledNotifications,
|
||||
};
|
||||
},
|
||||
computed: {
|
||||
...mapState({user: 'user.data'}),
|
||||
// https://stackoverflow.com/questions/42133894/vue-js-how-to-properly-watch-for-nested-properties/42134176#42134176
|
||||
baileyShouldShow () {
|
||||
return this.user.flags.newStuff;
|
||||
},
|
||||
userHp () {
|
||||
return this.user.stats.hp;
|
||||
},
|
||||
userExp () {
|
||||
return this.user.stats.exp;
|
||||
},
|
||||
userGp () {
|
||||
return this.user.stats.gp;
|
||||
},
|
||||
userMp () {
|
||||
return this.user.stats.mp;
|
||||
},
|
||||
userLvl () {
|
||||
return this.user.stats.lvl;
|
||||
},
|
||||
...mapState({
|
||||
user: 'user.data',
|
||||
userHp: 'user.data.stats.hp',
|
||||
userExp: 'user.data.stats.exp',
|
||||
userGp: 'user.data.stats.gp',
|
||||
userMp: 'user.data.stats.mp',
|
||||
userLvl: 'user.data.stats.lvl',
|
||||
userNotifications: 'user.data.notifications',
|
||||
userAchievements: 'user.data.achievements', // @TODO: does this watch deeply?
|
||||
armoireEmpty: 'user.data.flags.armoireEmpty',
|
||||
questCompleted: 'user.data.party.quest.completed',
|
||||
}),
|
||||
userClassSelect () {
|
||||
return !this.user.flags.classSelected && this.user.stats.lvl >= 10;
|
||||
},
|
||||
userNotifications () {
|
||||
return this.user.notifications;
|
||||
},
|
||||
userAchievements () {
|
||||
// @TODO: does this watch deeply?
|
||||
return this.user.achievements;
|
||||
},
|
||||
armoireEmpty () {
|
||||
return this.user.flags.armoireEmpty;
|
||||
},
|
||||
questCompleted () {
|
||||
return this.user.party.quest.completed;
|
||||
},
|
||||
invitedToQuest () {
|
||||
return this.user.party.quest.RSVPNeeded && !this.user.party.quest.completed;
|
||||
},
|
||||
},
|
||||
watch: {
|
||||
baileyShouldShow () {
|
||||
if (this.user.needsCron) return;
|
||||
this.$root.$emit('bv::show::modal', 'new-stuff');
|
||||
},
|
||||
userHp (after, before) {
|
||||
if (after <= 0) {
|
||||
this.playSound('Death');
|
||||
@@ -419,9 +409,6 @@ export default {
|
||||
this.scheduleNextCron();
|
||||
this.handleUserNotifications(this.user.notifications);
|
||||
},
|
||||
transferGroupNotification (notification) {
|
||||
this.$store.state.groupNotifications.push(notification);
|
||||
},
|
||||
async handleUserNotifications (after) {
|
||||
if (this.$store.state.isRunningYesterdailies) return;
|
||||
|
||||
@@ -434,23 +421,21 @@ export default {
|
||||
let notificationsToRead = [];
|
||||
let scoreTaskNotification = [];
|
||||
|
||||
this.$store.state.groupNotifications = []; // Flush group notifictions
|
||||
|
||||
after.forEach((notification) => {
|
||||
// This notification type isn't implemented here
|
||||
if (!this.handledNotifications[notification.type]) return;
|
||||
|
||||
if (this.lastShownNotifications.indexOf(notification.id) !== -1) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Some notifications are not marked read here, so we need to fix this system
|
||||
// to handle notifications differently
|
||||
if (['GROUP_TASK_APPROVED', 'GROUP_TASK_APPROVAL'].indexOf(notification.type) === -1) {
|
||||
this.lastShownNotifications.push(notification.id);
|
||||
if (this.lastShownNotifications.length > 10) {
|
||||
this.lastShownNotifications.splice(0, 9);
|
||||
}
|
||||
this.lastShownNotifications.push(notification.id);
|
||||
if (this.lastShownNotifications.length > 10) {
|
||||
this.lastShownNotifications.splice(0, 9);
|
||||
}
|
||||
|
||||
let markAsRead = true;
|
||||
|
||||
// @TODO: Use factory function instead
|
||||
switch (notification.type) {
|
||||
case 'GUILD_PROMPT':
|
||||
@@ -507,14 +492,6 @@ export default {
|
||||
if (notification.data.mp) this.mp(notification.data.mp);
|
||||
}
|
||||
break;
|
||||
case 'GROUP_TASK_APPROVAL':
|
||||
this.transferGroupNotification(notification);
|
||||
markAsRead = false;
|
||||
break;
|
||||
case 'GROUP_TASK_APPROVED':
|
||||
this.transferGroupNotification(notification);
|
||||
markAsRead = false;
|
||||
break;
|
||||
case 'SCORED_TASK':
|
||||
// Search if it is a read notification
|
||||
for (let i = 0; i < this.alreadyReadNotification.length; i++) {
|
||||
@@ -538,16 +515,6 @@ export default {
|
||||
this.$root.$emit('bv::show::modal', 'login-incentives');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
if (notification.data.headerText && notification.data.bodyText) {
|
||||
// @TODO:
|
||||
// let modalScope = this.$new();
|
||||
// modalScope.data = notification.data;
|
||||
// this.openModal('generic', {scope: modalScope});
|
||||
} else {
|
||||
markAsRead = false; // If the notification is not implemented, skip it
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if (markAsRead) notificationsToRead.push(notification.id);
|
||||
@@ -561,6 +528,7 @@ export default {
|
||||
});
|
||||
}
|
||||
|
||||
// @TODO this code is never run because userReadNotifsPromise is never true
|
||||
if (userReadNotifsPromise) {
|
||||
userReadNotifsPromise.then(() => {
|
||||
// Only run this code for scoring approved tasks
|
||||
@@ -589,8 +557,6 @@ export default {
|
||||
});
|
||||
}
|
||||
|
||||
this.user.notifications = []; // reset the notifications
|
||||
|
||||
this.checkUserAchievements();
|
||||
},
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user