2018-01-31 10:55:39 +00:00
import { authWithHeaders } from '../../middlewares/auth' ;
let api = { } ;
// @TODO export this const, cannot export it from here because only routes are exported from controllers
2018-11-14 14:30:34 +00:00
const LAST _ANNOUNCEMENT _TITLE = 'UNIQUE USERNAMES ARE HERE!' ;
2018-01-31 10:55:39 +00:00
const worldDmg = { // @TODO
bailey : false ,
} ;
/ * *
* @ api { get } / api / v3 / news Get latest Bailey announcement
* @ apiName GetNews
* @ apiGroup News
*
*
* @ apiSuccess { Object } html Latest Bailey html
*
* /
api . getNews = {
method : 'GET' ,
url : '/news' ,
async handler ( req , res ) {
const baileyClass = worldDmg . bailey ? 'npc_bailey_broken' : 'npc_bailey' ;
res . status ( 200 ) . send ( {
html : `
< div class = "bailey" >
2018-08-30 18:56:36 +00:00
< div class = "media align-items-center" >
2018-09-11 20:38:12 +00:00
< div class = "mr-3 ${baileyClass}" > < / d i v >
2018-06-19 23:24:40 +00:00
< div class = "media-body" >
2018-09-11 20:38:12 +00:00
< h1 class = "align-self-center" > $ { res . t ( 'newStuff' ) } < / h 1 >
2018-11-14 14:30:34 +00:00
< h2 > 11 / 14 / 2018 - $ { LAST _ANNOUNCEMENT _TITLE } < / h 2 >
2018-08-30 18:56:36 +00:00
< / d i v >
< / d i v >
2018-09-11 20:38:12 +00:00
< hr / >
2018-11-14 14:30:34 +00:00
< p > Hello Habiticans ! We 're excited to announce the launch of our unique username system! We' ve made this change so it ’ s easier to find and invite your friends to Parties , Guilds , and Challenges , mention people in chat , and more . In the future we hope to use this functionality to introduce even more useful features , such as the option to receive notifications if you are mentioned in chat . < / p >
< p > You can check and change your current Username in < a href = '/user/settings/site' target = '_blank' > Settings < / a > . I f y o u ' v e j u s t c o n f i r m e d , c h e c k y o u r S t a b l e t o f i n d t h e V e t e r a n P e t y o u ' v e b e e n g i v e n a s a r e w a r d ! < / p >
< p > If you ’ d like to learn more about this change , this < a href = 'https://habitica.wikia.com/wiki/Player_Names' target = '_blank' > Wiki page < / a > h a s m o r e d e t a i l e d i n f o r m a t i o n . < / p >
< p > Thank you for being patient as we make these changes to improve Habitica ! < / p >
2018-11-08 18:43:50 +00:00
< div class = "small mb-3" > by Beffymaroo , SabreCat , Apollo , Piyo , viirus , Paglias , and TheHollidayInn < / d i v >
< div class = "promo_veteran_pets center-block" > < / d i v >
2018-01-31 10:55:39 +00:00
< / d i v >
` ,
} ) ;
} ,
} ;
/ * *
* @ api { post } / api / v3 / news / tell - me - later Get latest Bailey announcement in a second moment
* @ apiName TellMeLaterNews
* @ apiGroup News
*
*
* @ apiSuccess { Object } data An empty Object
*
* /
api . tellMeLaterNews = {
method : 'POST' ,
2018-09-21 13:12:20 +00:00
middlewares : [ authWithHeaders ( ) ] ,
2018-01-31 10:55:39 +00:00
url : '/news/tell-me-later' ,
async handler ( req , res ) {
const user = res . locals . user ;
user . flags . newStuff = false ;
const existingNotificationIndex = user . notifications . findIndex ( n => {
2018-02-04 12:28:05 +00:00
return n && n . type === 'NEW_STUFF' ;
2018-01-31 10:55:39 +00:00
} ) ;
if ( existingNotificationIndex !== - 1 ) user . notifications . splice ( existingNotificationIndex , 1 ) ;
user . addNotification ( 'NEW_STUFF' , { title : LAST _ANNOUNCEMENT _TITLE } , true ) ; // seen by default
await user . save ( ) ;
res . respond ( 200 , { } ) ;
} ,
} ;
2018-02-02 00:31:38 +00:00
module . exports = api ;