mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-12 06:25:51 +03:00
fa84808048
no issue Since `ember-moment@10.0` it's not been necessary to use the `ember-cli-moment-shim` package, with `moment` instead being usable directly via `ember-auto-import`. Getting rid of the shim package is necessary for compatibility with `embroider`, Ember's new build tooling. - dropped `ember-cli-moment-shim` dependency - added `moment-timezone` dependency and updated all imports to reflect the different package - worked around `ember-power-calendar` having `ember-cli-moment-shim` as a sub-dependency - added empty in-repo-addon `ember-power-calendar-moment` to avoid `ember-power-calendar` complaining about a missing package - added `ember-power-calendar-utils` in-repo-addon that is a copy of `ember-power-calendar-moment` but without the build-time renaming of the tree for better compatibility with embroider
92 lines
2.8 KiB
JavaScript
92 lines
2.8 KiB
JavaScript
import Service, {inject as service} from '@ember/service';
|
|
import fetch from 'fetch';
|
|
import moment from 'moment-timezone';
|
|
import {action, computed} from '@ember/object';
|
|
import {isEmpty} from '@ember/utils';
|
|
import {task} from 'ember-concurrency';
|
|
|
|
export default Service.extend({
|
|
session: service(),
|
|
|
|
entries: null,
|
|
changelogUrl: 'https://ghost.org/blog/',
|
|
isShowingModal: false,
|
|
|
|
_user: null,
|
|
|
|
init() {
|
|
this._super(...arguments);
|
|
this.entries = [];
|
|
},
|
|
|
|
whatsNewSettings: computed('_user.accessibility', function () {
|
|
let settingsJson = this.get('_user.accessibility') || '{}';
|
|
let settings = JSON.parse(settingsJson);
|
|
return settings.whatsNew;
|
|
}),
|
|
|
|
hasNew: computed('whatsNewSettings.lastSeenDate', 'entries.[]', function () {
|
|
if (isEmpty(this.entries)) {
|
|
return false;
|
|
}
|
|
|
|
let [latestEntry] = this.entries;
|
|
|
|
let lastSeenDate = this.get('whatsNewSettings.lastSeenDate') || '2019-01-01 00:00:00';
|
|
let lastSeenMoment = moment(lastSeenDate);
|
|
let latestDate = latestEntry.published_at;
|
|
let latestMoment = moment(latestDate || lastSeenDate);
|
|
return latestMoment.isAfter(lastSeenMoment);
|
|
}),
|
|
|
|
showModal: action(function () {
|
|
this.set('isShowingModal', true);
|
|
}),
|
|
|
|
closeModal: action(function () {
|
|
this.set('isShowingModal', false);
|
|
this.updateLastSeen.perform();
|
|
}),
|
|
|
|
fetchLatest: task(function* () {
|
|
try {
|
|
// we should already be logged in at this point so lets grab the user
|
|
// record and store it locally so that we don't have to deal with
|
|
// session.user being a promise and causing issues with CPs
|
|
let user = yield this.session.user;
|
|
this.set('_user', user);
|
|
|
|
let response = yield fetch('https://ghost.org/changelog.json');
|
|
if (!response.ok) {
|
|
// eslint-disable-next-line
|
|
return console.error('Failed to fetch changelog', {response});
|
|
}
|
|
|
|
let result = yield response.json();
|
|
this.set('entries', result.posts || []);
|
|
this.set('changelogUrl', result.changelogUrl);
|
|
} catch (e) {
|
|
console.error(e); // eslint-disable-line
|
|
}
|
|
}),
|
|
|
|
updateLastSeen: task(function* () {
|
|
let settingsJson = this._user.accessibility || '{}';
|
|
let settings = JSON.parse(settingsJson);
|
|
let [latestEntry] = this.entries;
|
|
|
|
if (!latestEntry) {
|
|
return;
|
|
}
|
|
|
|
if (!settings.whatsNew) {
|
|
settings.whatsNew = {};
|
|
}
|
|
|
|
settings.whatsNew.lastSeenDate = latestEntry.published_at;
|
|
|
|
this._user.set('accessibility', JSON.stringify(settings));
|
|
yield this._user.save();
|
|
})
|
|
});
|