MCPcopy Index your code
hub / github.com/codecombat/codecombat / pollAchievements

Method pollAchievements

app/models/CocoModel.js:474–507  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

472 }
473
474 static pollAchievements () {
475 if (utils.isOzaria) { return } // Not needed until/unlesss we start using achievements in Ozaria
476 if (typeof application !== 'undefined' && application !== null ? application.testing : undefined) { return }
477
478 const CocoCollection = require('collections/CocoCollection')
479 const EarnedAchievement = require('models/EarnedAchievement')
480
481 class NewAchievementCollection extends CocoCollection {
482 static initClass () {
483 this.prototype.model = EarnedAchievement
484 }
485
486 initialize (me) {
487 if (me == null) {
488 ({
489 me,
490 } = require('core/auth'))
491 }
492 this.url = `/db/user/${me.id}/achievements?notified=false`
493 }
494 }
495 NewAchievementCollection.initClass()
496
497 const achievements = new NewAchievementCollection()
498 return achievements.fetch({
499 success (collection) {
500 if (!_.isEmpty(collection.models)) { return me.fetch(({ cache: false, success () { return Backbone.Mediator.publish('achievements:new', { earnedAchievements: collection }) } })) }
501 },
502 error () {
503 return console.error('Miserably failed to fetch unnotified achievements', arguments)
504 },
505 cache: false,
506 })
507 }
508
509 // - Internationalization
510

Callers 2

initializeFunction · 0.80
saveMethod · 0.80

Calls 2

initClassMethod · 0.45
fetchMethod · 0.45

Tested by

no test coverage detected