habitica/website/server/models/userNotification.js

144 lines
4.1 KiB
JavaScript
Raw Normal View History

Onboarding guide and initial achievements refactoring (#11536) * add achievements to user * add placeholder strings * add to achievements to common script * add onboarding achievements category * add notifications * more notifications * award achievements * wip notification panel * add achievements icons and copy * do not count onboarding tasks for the created task achievement * add notes * sprites, fixes and completion status and reward * add onboarding panel * add toggle * fix toggle size * fix tests * fix typo * add notification * start adding modal * fix remove button positionin, timeout, progress bar * modal + fixes * disable broken social links from level up modal * change toggle icon color on hover * add border bottom to onboarding guide panel * add collapse animation * expanded onboarding on first open * onboarding: flip toggle colors * onboarding: show progress bar all the time * onboarding: fix panel closing on click * onboarding modal: add close icon and fix padding * wip: add migration for existing users * fix titles in guide * fix achievements copy * do not award completed task achievement when direction is down * start implementing new achievements * start migrating client * remove social links from achievements modals * prevent skipping tutorial + fix achievement notification * sync fixes * start redesign achievement modal * misc fixes to achievements, polish generic achievement modal and hatched pet modal * add special badge for onboarding * fix badge condition * modals fixes * hatched pet modal: add close icon * fix badge typo * fix justin button * new scrolling behavior for dropdowns * fix strings capitalization * add common tests * add api unit tests * add date check * achievements modal polishing * typos * add toggle for achievements categories * typo * fix test * fix edit avatar modal cannot be closed * finish migration and correct launch date * fix migration * migration fixes * fix tests
2019-12-16 16:20:47 +00:00
import _ from 'lodash';
import mongoose from 'mongoose';
import { v4 as uuid } from 'uuid';
import validator from 'validator';
2019-10-08 14:57:10 +00:00
import baseModel from '../libs/baseModel';
const NOTIFICATION_TYPES = [
'DROPS_ENABLED', // unused
'REBIRTH_ENABLED',
'WON_CHALLENGE',
'STREAK_ACHIEVEMENT',
'ULTIMATE_GEAR_ACHIEVEMENT',
'REBIRTH_ACHIEVEMENT',
'NEW_CONTRIBUTOR_LEVEL',
'CRON',
'GROUP_TASK_APPROVAL',
'GROUP_TASK_APPROVED',
'GROUP_TASK_ASSIGNED',
'GROUP_TASK_CLAIMED',
2018-01-20 16:28:50 +00:00
'GROUP_TASK_NEEDS_WORK',
Login Incentives (#8230) * feat(incentives): login bennies WIP * feat(content): incentive prize content WIP * fix(content): placeholders pass tests * WIP(content): Bard instrument placeholder * feat(content): Incentives build * chore(sprites): compile and fix some strings * WIP(incentives): quests and backgrounds * fix(quests): correct buy/launch handling * [WIP] Incentives rewarding (#8226) * Added login incentive rewards * Updated incentive rewards * Added incentive modal and updated notification structure * Added analytics to sleeping * Added login incentives to user analytics * Fixed unit tests and ensured that prizes are incremented and not replaced * Updated style of daily login incentive modal * Added rewards modal * Added translations * Added loigin incentive ui elements to profile * Updated login incentives structure and abstracted to common.content * Added dynamic display for login incentives on profile * Added purple potion image * Updated daily login modal * Fixed progress calculation * Added bard gear * Updated login incentive rewards * Fixed styles and text * Added multiple read for notifications * Fixed lint issues * Fixed styles and added 50 limit * Updated quest keys * Added login incentives reward page * Fixed tests * Fixed linting and tests * Read named notifications route. Add image for backgrounds * Fixed style issues and added tranlsations to login incentive notification * Hided abiltiy to purchase incentive backgrounds and added message to detail how to unlock * Updated awarded message * Fixed text and updated progress counter to display better * Fixed purple potion reward text * Fixed check in backgrouns reward text * fix(quest): pass tests * Added display of multiple rewards * Updated modal styles * Fixed neagtive 50 issue * Remvoed total count from daily login incentives modal * Fixed magic paw display * fix(awards): give bunnies again * WIP(incentives): more progress on BG shop * fix(incentives): actually award backgrounds * fix(incentives): more BG fixy * fix(backgrounds): don't gem-buy checkin bgs * Added dust bunny notification * fix(incentives): don't redisplay bunny award * chore(news): Bailey and different promo sprite
2016-11-24 01:34:09 +00:00
'LOGIN_INCENTIVE',
'GROUP_INVITE_ACCEPTED',
Thehollidayinn/group plans part 2 (#8262) * Added all ui components back * Added group ui items back and initial group approval directive * Added approval list view with approving functionality * Added notification display for group approvals * Fixed linting issues * Removed expectation from beforeEach * Moved string to locale * Added per use group plan for stripe * Added tests for stripe group plan upgrade * Removed paypal option * Abstract sub blocks. Hit group sub block from user settings page. Added group subscriptin beneifts display * Fixed lint issue * Added pricing and adjusted styles * Moved text to translations * Added group email types * Fixed typo * Fixed group plan abstraction and other style issues * Fixed email unit test * Added type to group plan to filter our group plans * Removed dev protection from routes * Removed hard coding and fixed upgrade plan * Added error when group has subscription and tries to remove * Fixed payment unit tests * Added custom string and moved subscription check up in the logic * Added ability for old leader to delete subscription the created * Allowed old guild leader to edit their group subscription * Fixed linting and tests * Added group sub page to user sub settings * Added approval and group tasks requests back. Hid user group sub on profile * Added group tasks sync after adding to allow for editing * Fixed promise chain when resolving group * Added approvals to group promise chain * Ensured compelted group todos are not delted at cron * Updated copy and other minor styles * Added group field to tags and recolored group tag. * Added chat message when task is claimed * Preventing task scoring when approval is needed * Added approval requested indicator * Updated column with for tasks on group page * Added checklist sync on assign * Added sync for checklist items * Added checkilist sync when task is updated * Added checklist sync remove * Sanatized group tasks when updated * Fixed lint issues * Added instant scoring of approved task * Added task modal * Fixed editing of challenge and group tasks * Added cancel button * Added add new checklist option to update sync * Added remove for checklist * Added checklist update * Added difference check and sync for checklist if there is a diff * Fixed task syncing * Fixed linting issues * Fixed styles and karma tests * Fixed minor style issues * Fixed obj transfer on scope * Fixed broken tests * Added new benefits page * Updated group page styles * Updated benefits page style * Added translations * Prevented sync with empty trask list * Added task title to edit modal * Added new group plans page and upgrade redirect * Added group plans redirect to upgrade * Fixed party home page being hidden and home button click * Fixed dynamic changing of task status and grey popup * Fixed tag editing * Hid benifites information if group has subscription * Added quotes to task name * Fixed issue with assigning multiple users * Added new group plans ctrl * Hid menu from public guilds * Fixed task sync issue * Updated placeholder for assign field * Added correct cost to subscribe details * Hid create, edit, delete task options from non group leaders * Prevented some front end modifications to group tasks * Hid tags option from group original task * Added refresh for approvals and group tasks * Prepend new group tasks * Fix last checklist item sync * Fixed casing issue with tags * Added claimed by message on hover * Prevent user from deleting assigned task * Added single route for group plan sign up and payments * Abstracted stripe payments and added initial tests * Abstracted amazon and added initial tests * Fixed create group message * Update group id check and return group * Updated to use the new returned group * Fixed linting and promise issues * Fixed broken leave test after merge issue * Fixed undefined approval error and editing/deleting challenge tasks * Add pricing to group plans, removed confirmation, and fixed redirect after payment * Updated group plan cost text
2016-12-21 19:45:45 +00:00
'SCORED_TASK',
2017-01-07 10:47:19 +00:00
'BOSS_DAMAGE', // Not used currently but kept to avoid validation errors
'GIFT_ONE_GET_ONE',
'GUILD_PROMPT',
'GUILD_JOINED_ACHIEVEMENT',
'CHALLENGE_JOINED_ACHIEVEMENT',
'INVITED_FRIEND_ACHIEVEMENT',
2018-01-20 16:28:50 +00:00
'CARD_RECEIVED',
'NEW_MYSTERY_ITEMS',
'UNALLOCATED_STATS_POINTS',
'NEW_INBOX_MESSAGE',
'NEW_STUFF',
'NEW_CHAT_MESSAGE',
Add API Call to bulk score tasks (#11389) * Add new API call to complete multiple task scorings in one call * Improve API response * Improve saving process * Improve handling for multiple tasks scored at once * Handle challenge task errors better * Improve check for alias * Improve check for task scorings * Fix merge errors * make nodemon ignore content_cache * Fix completing group tasks * fix test * fix tests (again) * typo * WIP(a11y): task modal updates * fix(tasks): borders in modal * fix(tasks): circley locks * fix(task-modal): placeholders * WIP(task-modal): disabled states, hide empty options, +/- restyle * fix(task-modal): box shadows instead of borders, habit control pointer * fix(task-modal): button states? * fix(modal): tighten up layout, new spacing utils * fix(tasks): more stylin * fix(tasks): habit hovers * fix(css): checklist labels, a11y colors * fix(css): one more missed hover issue * fix(css): lock Challenges, label fixes * fix(css): scope input/textarea changes * fix(style): task tweakies * fix(style): more button fixage * WIP(component): start select list story * working example of a templated selectList * fix(style): more button corrections * fix(lint): EOL * fix(buttons): factor btn-secondary to better override Bootstrap * fix(styles): standardize more buttons * wip: difficulty select - style fixes * selectDifficulty works! :tada: - fix styles * change the dropdown-item sizes only for the selectList ones * selectTranslatedArray * changed many label margins * more correct dropdown style * fix(modals): button corrections * input-group styling + datetime picker without today button * Style/margins for "repeat every" - extract selectTag.vue * working tag-selection / update - cleanup * fix stories * fix svg color on create modal (purple) * fix task modal bottom padding * correct dropdown shadow * update dropdown-toggle caret size / color * fixed checklist style * sync checked state * selectTag padding * fix spacing between positive/negative streak inputs * toggle-checkbox + fix some spacings * disable repeat-on when its a groupTask * fix new checklist-item * fix toggle-checkbox style - fix difficulty style * fix checklist ui * add tags label , when there arent any tags selected * WORKING select-tag component :tada: * fix taglist story * show max 5 items in tag dropdown + "X more" label * fix datetime clear button * replace m-b-xs to mb-1 (bootstrap) - fix input-group-text style * fix styles of advanced settings * fix delete task styles * always show grippy on hover of the item * extract modal-text-input mixin + fix the borders/dropshadow * fix(spacing): revert most to Bootstrap * feat(checklists): make local copy of master checklist non-editable also aggressively update checklists because they weren't syncing?? * fix(checklists): handle add/remove options better * feat(teams): manager notes field * fix select/dropdown styles * input border + icon colors * delete task underline color * fix checklist "delete icon" vertical position * selectTag fixes - normal open/close toggle working again - remove icon color * fixing icons: Trash can - Delete Little X - Remove Big X - Close Block - Block * fix taglist margins / icon sizes * wip margin overview (in storybook) * fix routerlink * remove unused method * new selectTag style + add markdown inside tagList + scrollable tag selection * fix selectTag / selectList active border * fix difficulty select (svg default color) * fix input padding-left + fix reset habit streak fullwidth / padding + "repeat every" gray text (no border) * feat(teams): improved approval request > approve > reward flow * fix(tests): address failures * fix(lint): oops only * fix(tasks): short-circuit group related logic * fix(tasks): more short circuiting * fix(tasks): more lines, less lint * fix(tasks): how do i keep missing these * feat(teams): provide assigning user summary * fix(teams): don't attempt to record assiging user if not supplied * fix advanced-settings styling / margin * fix merge + hide advanced streak settings when none enabled * fix styles * set Roboto font for advanced settings * Add Challenge flag to the tag list * add tag with enter, when no other tag is found * fix styles + tag cancel button * refactor footer / margin * split repeat fields into option mt-3 groups * button all the things * fix(tasks): style updates * no hover state for non-editable tasks on team board * keep assign/claim footer on task after requesting approval * disable more fields on user copy of team task, and remove hover states for them * fix(tasks): functional revisions * "Claim Rewards" instead of "x" in task approved notif * Remove default transition supplied by Bootstrap, apply individually to some elements * Delete individual tasks and related notifications when master task deleted from team board * Manager notes now save when supplied at task initial creation * Can no longer dismiss rewards from approved task by hitting Dismiss All * fix(tasks): clean tasksOrder also adjust related test expectation * fix(tests): adjust integration expectations * fix(test): ratzen fratzen only * fix lint * fix tests * fix(teams): checklist, notes * handleSharedCompletion: handle error, make sure it is run after the user task has been saved * fix typo * correctly handle errors in handleSharedCompletion when approving a task * fix(teams): improve disabled states * handleSharedCompletion: do not increase completions by 1 manually to adjust for last approval not saved yet * revert changes to config.json.example * fix(teams): more style fixage * add unit tests for findMultipleByIdOrAlias * exclude api v4 route from apidocs * BREAKING(teams): return 202 instead of 401 for approval request * fix(teams): better taskboard sync also re-re-fix checklist borders * scoreTasks: validate body * fix tests, move string to api errors * fix(tests): update expectations for breaking change * start updating api docs, process tasks sequentially to avoid conflicts with user._tmp * do not crash entire bulk operation in case of errors * save task only if modified * fix lint * undo changes to error handling: either all tasks scoring are successfull or none * remove stale code * do not return user._tmp when bulk scoring, it would be the last version only * make sure user._tmp.leveledUp is not lost when bulk scoring * rewards tests * mixed tests * fix tests, allow scoring the same task multiple times * finish integration tests * fix api docs for the bulk score route * refactor(task-modal): lockable label component * wip loading spinner * refactor(teams): move task scoring to mixin * fix(teams): style corrections * fix(btn): fix padding to have height of 32px * implement loading spinner * remove console.log warnings * fix(tasks): spacing and wording corrections * fix(teams): don't bork manager notes * fix(teams): assignment fix and more approval flow revisions * WIP(teams): use tag dropdown control for assignment * finish merge - never throw an error when a group task requires approval (wip - needs tests) * fix taskModal merge * fix merge * fix(task modal): add newline * fix(column.vue): add newline at end of file * mvp yesterdaily modal * fix tests * fix api docs for bulk scoring group tasks * separate task scoring and _tmp handling * handle _tmp when bulk scoring * rya: close modal before calling cron API, prevents issues with modals * rya: fix conflicts with other modals * add sounds, support for group plans, analytics * use asyncResource for group plans * fix lint * streak bonus: add comment about missing in rya * move yesterdailyModal * fix issues with level up modals and rya * add comments for future use, fix level up modals not showing up at levels with a quest drop * handle errors in rya modal * bundle quest and crit notifications Co-authored-by: Phillip Thelen <phillip@habitica.com> Co-authored-by: Phillip Thelen <viirus@pherth.net> Co-authored-by: Sabe Jones <sabrecat@gmail.com> Co-authored-by: negue <eugen.bolz@gmail.com>
2020-08-21 09:46:56 +00:00
'LEVELED_UP', // Not in use
'FIRST_DROPS',
Onboarding guide and initial achievements refactoring (#11536) * add achievements to user * add placeholder strings * add to achievements to common script * add onboarding achievements category * add notifications * more notifications * award achievements * wip notification panel * add achievements icons and copy * do not count onboarding tasks for the created task achievement * add notes * sprites, fixes and completion status and reward * add onboarding panel * add toggle * fix toggle size * fix tests * fix typo * add notification * start adding modal * fix remove button positionin, timeout, progress bar * modal + fixes * disable broken social links from level up modal * change toggle icon color on hover * add border bottom to onboarding guide panel * add collapse animation * expanded onboarding on first open * onboarding: flip toggle colors * onboarding: show progress bar all the time * onboarding: fix panel closing on click * onboarding modal: add close icon and fix padding * wip: add migration for existing users * fix titles in guide * fix achievements copy * do not award completed task achievement when direction is down * start implementing new achievements * start migrating client * remove social links from achievements modals * prevent skipping tutorial + fix achievement notification * sync fixes * start redesign achievement modal * misc fixes to achievements, polish generic achievement modal and hatched pet modal * add special badge for onboarding * fix badge condition * modals fixes * hatched pet modal: add close icon * fix badge typo * fix justin button * new scrolling behavior for dropdowns * fix strings capitalization * add common tests * add api unit tests * add date check * achievements modal polishing * typos * add toggle for achievements categories * typo * fix test * fix edit avatar modal cannot be closed * finish migration and correct launch date * fix migration * migration fixes * fix tests
2019-12-16 16:20:47 +00:00
'ONBOARDING_COMPLETE',
'ACHIEVEMENT_ALL_YOUR_BASE',
'ACHIEVEMENT_BACK_TO_BASICS',
'ACHIEVEMENT_JUST_ADD_WATER',
2019-06-11 19:50:17 +00:00
'ACHIEVEMENT_LOST_MASTERCLASSER',
'ACHIEVEMENT_MIND_OVER_MATTER',
'ACHIEVEMENT_DUST_DEVIL',
'ACHIEVEMENT_ARID_AUTHORITY',
'ACHIEVEMENT_PARTY_UP',
'ACHIEVEMENT_PARTY_ON',
'ACHIEVEMENT_BEAST_MASTER',
'ACHIEVEMENT_MOUNT_MASTER',
'ACHIEVEMENT_TRIAD_BINGO',
2019-10-23 13:10:43 +00:00
'ACHIEVEMENT_MONSTER_MAGUS',
'ACHIEVEMENT_UNDEAD_UNDERTAKER',
2019-12-10 20:41:39 +00:00
'ACHIEVEMENT_PRIMED_FOR_PAINTING',
'ACHIEVEMENT_PEARLY_PRO',
'ACHIEVEMENT_TICKLED_PINK',
'ACHIEVEMENT_ROSY_OUTLOOK',
2020-03-17 14:11:41 +00:00
'ACHIEVEMENT_BUG_BONANZA',
'ACHIEVEMENT_BARE_NECESSITIES',
'ACHIEVEMENT_FRESHWATER_FRIENDS',
2020-08-18 20:13:06 +00:00
'ACHIEVEMENT_GOOD_AS_GOLD',
'ACHIEVEMENT_ALL_THAT_GLITTERS',
2020-10-19 20:38:12 +00:00
'ACHIEVEMENT_BONE_COLLECTOR',
'ACHIEVEMENT_SKELETON_CREW',
2020-11-24 23:53:15 +00:00
'ACHIEVEMENT_SEEING_RED',
'ACHIEVEMENT_RED_LETTER_DAY',
2021-02-16 23:00:39 +00:00
'ACHIEVEMENT_LEGENDARY_BESTIARY',
'ACHIEVEMENT_SEASONAL_SPECIALIST',
'ACHIEVEMENT_VIOLETS_ARE_BLUE',
'ACHIEVEMENT_WILD_BLUE_YONDER',
'ACHIEVEMENT_DOMESTICATED',
'ACHIEVEMENT_SHADY_CUSTOMER',
'ACHIEVEMENT_SHADE_OF_IT_ALL',
2022-01-28 22:14:50 +00:00
'ACHIEVEMENT_ZODIAC_ZOOKEEPER',
2022-03-08 17:43:38 +00:00
'ACHIEVEMENT_BIRDS_OF_A_FEATHER',
Onboarding guide and initial achievements refactoring (#11536) * add achievements to user * add placeholder strings * add to achievements to common script * add onboarding achievements category * add notifications * more notifications * award achievements * wip notification panel * add achievements icons and copy * do not count onboarding tasks for the created task achievement * add notes * sprites, fixes and completion status and reward * add onboarding panel * add toggle * fix toggle size * fix tests * fix typo * add notification * start adding modal * fix remove button positionin, timeout, progress bar * modal + fixes * disable broken social links from level up modal * change toggle icon color on hover * add border bottom to onboarding guide panel * add collapse animation * expanded onboarding on first open * onboarding: flip toggle colors * onboarding: show progress bar all the time * onboarding: fix panel closing on click * onboarding modal: add close icon and fix padding * wip: add migration for existing users * fix titles in guide * fix achievements copy * do not award completed task achievement when direction is down * start implementing new achievements * start migrating client * remove social links from achievements modals * prevent skipping tutorial + fix achievement notification * sync fixes * start redesign achievement modal * misc fixes to achievements, polish generic achievement modal and hatched pet modal * add special badge for onboarding * fix badge condition * modals fixes * hatched pet modal: add close icon * fix badge typo * fix justin button * new scrolling behavior for dropdowns * fix strings capitalization * add common tests * add api unit tests * add date check * achievements modal polishing * typos * add toggle for achievements categories * typo * fix test * fix edit avatar modal cannot be closed * finish migration and correct launch date * fix migration * migration fixes * fix tests
2019-12-16 16:20:47 +00:00
'ACHIEVEMENT', // generic achievement notification, details inside `notification.data`
Drop Cap Notification, Modal and A/B Test (#12651) * add drop cap notification * add drop cap notification * add dismissible notification * fix(notification): correct remove icon positioning * track events * add modal * add back files * fix links and add missing analytics * fix rounded borders and hide sub info for subscribers * a/b test * fix comparison * Translated using Weblate (Spanish) Currently translated at 98.2% (55 of 56 strings) Translation: Habitica/Messages Translate-URL: https://translate.habitica.com/projects/habitica/messages/es/ Translated using Weblate (Spanish) Currently translated at 99.4% (179 of 180 strings) Translation: Habitica/Settings Translate-URL: https://translate.habitica.com/projects/habitica/settings/es/ Merge branch 'origin/develop' into Weblate. Translated using Weblate (Spanish) Currently translated at 99.4% (175 of 176 strings) Translation: Habitica/Subscriber Translate-URL: https://translate.habitica.com/projects/habitica/subscriber/es/ Translated using Weblate (Spanish (Latin America)) Currently translated at 98.6% (359 of 364 strings) Translation: Habitica/Groups Translate-URL: https://translate.habitica.com/projects/habitica/groups/es_419/ Translated using Weblate (Spanish) Currently translated at 85.7% (151 of 176 strings) Translation: Habitica/Subscriber Translate-URL: https://translate.habitica.com/projects/habitica/subscriber/es/ Translated using Weblate (Spanish) Currently translated at 95.3% (538 of 564 strings) Translation: Habitica/Backgrounds Translate-URL: https://translate.habitica.com/projects/habitica/backgrounds/es/ Translated using Weblate (Spanish (Latin America)) Currently translated at 98.6% (359 of 364 strings) Translation: Habitica/Groups Translate-URL: https://translate.habitica.com/projects/habitica/groups/es_419/ Translated using Weblate (French) Currently translated at 100.0% (56 of 56 strings) Translation: Habitica/Messages Translate-URL: https://translate.habitica.com/projects/habitica/messages/fr/ Translated using Weblate (German) Currently translated at 100.0% (56 of 56 strings) Translation: Habitica/Messages Translate-URL: https://translate.habitica.com/projects/habitica/messages/de/ Translated using Weblate (French) Currently translated at 100.0% (718 of 718 strings) Translation: Habitica/Questscontent Translate-URL: https://translate.habitica.com/projects/habitica/questscontent/fr/ Translated using Weblate (German) Currently translated at 100.0% (718 of 718 strings) Translation: Habitica/Questscontent Translate-URL: https://translate.habitica.com/projects/habitica/questscontent/de/ Translated using Weblate (Czech) Currently translated at 100.0% (56 of 56 strings) Translation: Habitica/Spells Translate-URL: https://translate.habitica.com/projects/habitica/spells/cs/ Translated using Weblate (Japanese) Currently translated at 100.0% (175 of 175 strings) Translation: Habitica/Subscriber Translate-URL: https://translate.habitica.com/projects/habitica/subscriber/ja/ Translated using Weblate (Italian) Currently translated at 100.0% (56 of 56 strings) Translation: Habitica/Messages Translate-URL: https://translate.habitica.com/projects/habitica/messages/it/ Translated using Weblate (Italian) Currently translated at 100.0% (718 of 718 strings) Translation: Habitica/Questscontent Translate-URL: https://translate.habitica.com/projects/habitica/questscontent/it/ Translated using Weblate (Czech) Currently translated at 100.0% (180 of 180 strings) Translation: Habitica/Settings Translate-URL: https://translate.habitica.com/projects/habitica/settings/cs/ Translated using Weblate (Basque) Currently translated at 100.0% (2 of 2 strings) Translation: Habitica/Noscript Translate-URL: https://translate.habitica.com/projects/habitica/noscript/eu/ Translated using Weblate (Basque) Currently translated at 6.5% (8 of 123 strings) Translation: Habitica/Communityguidelines Translate-URL: https://translate.habitica.com/projects/habitica/communityguidelines/eu/ Translated using Weblate (Chinese (Simplified)) Currently translated at 100.0% (56 of 56 strings) Translation: Habitica/Messages Translate-URL: https://translate.habitica.com/projects/habitica/messages/zh_Hans/ Translated using Weblate (Japanese) Currently translated at 100.0% (56 of 56 strings) Translation: Habitica/Messages Translate-URL: https://translate.habitica.com/projects/habitica/messages/ja/ Translated using Weblate (Chinese (Simplified)) Currently translated at 100.0% (718 of 718 strings) Translation: Habitica/Questscontent Translate-URL: https://translate.habitica.com/projects/habitica/questscontent/zh_Hans/ Translated using Weblate (Portuguese (Brazil)) Currently translated at 100.0% (718 of 718 strings) Translation: Habitica/Questscontent Translate-URL: https://translate.habitica.com/projects/habitica/questscontent/pt_BR/ Translated using Weblate (Portuguese (Brazil)) Currently translated at 99.8% (717 of 718 strings) Translation: Habitica/Questscontent Translate-URL: https://translate.habitica.com/projects/habitica/questscontent/pt_BR/ * clarify a/b test values * add tests * refactor user dropdown * fix hover state * fix user dropdown * fix user menu hierarchy * restore i18n files to release version Co-authored-by: Melior <admin@habitica.com>
2020-10-16 17:50:54 +00:00
'DROP_CAP_REACHED',
];
2019-10-08 14:57:10 +00:00
const { Schema } = mongoose;
2019-10-08 14:57:10 +00:00
export const schema = new Schema({
id: {
$type: String,
default: uuid,
validate: [v => validator.isUUID(v), 'Invalid uuid for userNotification.'],
2020-03-01 12:30:22 +00:00
required: true,
},
type: {
$type: String,
2020-03-01 12:30:22 +00:00
required: true,
enum: NOTIFICATION_TYPES,
},
2019-10-08 14:57:10 +00:00
data: {
$type: Schema.Types.Mixed,
default: () => ({}),
},
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
2018-01-31 10:55:39 +00:00
// A field to mark the notification as seen without deleting it, optional use
seen: {
$type: Boolean,
// required: true,
default: () => false,
},
}, {
strict: true,
minimize: false, // So empty objects are returned
_id: false, // use id instead of _id,
typeKey: '$type', // So that we can use fields named `type`
});
2018-02-04 12:28:05 +00:00
/**
2020-03-01 19:06:24 +00:00
* Remove invalid data from an array of notifications.
* Fix for https://github.com/HabitRPG/habitica/issues/9923
* Called by user's post init hook (models/user/hooks.js)
2018-02-04 12:28:05 +00:00
*/
2020-03-01 19:06:24 +00:00
schema.statics.cleanupCorruptData = function cleanupCorruptNotificationsData (notifications) {
2018-02-04 13:04:41 +00:00
if (!notifications) return notifications;
2020-03-01 19:06:24 +00:00
let filteredNotifications = notifications.filter(notification => {
// Exclude notifications with a nullish value, no id or no type
if (!notification || !notification.id || !notification.type) return false;
2018-02-04 12:28:05 +00:00
return true;
});
2020-03-01 19:06:24 +00:00
// Remove duplicate NEW_CHAT_MESSAGES notifications
// can be caused by a race condition when adding a new notification of this type
// in group.sendChat if two messages are posted at the same time
filteredNotifications = _.uniqWith(filteredNotifications, (val, otherVal) => {
2020-03-01 19:06:24 +00:00
if (val.type === 'NEW_CHAT_MESSAGE' && val.type === otherVal.type) {
return val.data.group.id === otherVal.data.group.id;
}
return false;
});
2020-03-01 19:06:24 +00:00
return filteredNotifications;
2018-02-04 12:28:05 +00:00
};
schema.plugin(baseModel, {
noSet: ['_id', 'id'],
// timestamps: true, // Temporarily removed to debug a possible bug
_id: false, // use id instead of _id
});
2019-10-08 14:57:10 +00:00
export const model = mongoose.model('UserNotification', schema);