mirror of
https://github.com/discourse/discourse.git
synced 2025-09-06 10:50:21 +08:00
FIX: Use Ember.set to update the site settings via the Message Bus
This commit is contained in:
parent
f6bd114b5e
commit
ecaa751455
1 changed files with 14 additions and 24 deletions
|
@ -8,6 +8,7 @@ import {
|
||||||
export default {
|
export default {
|
||||||
name: 'subscribe-user-notifications',
|
name: 'subscribe-user-notifications',
|
||||||
after: 'message-bus',
|
after: 'message-bus',
|
||||||
|
|
||||||
initialize(container) {
|
initialize(container) {
|
||||||
const user = container.lookup('current-user:main'),
|
const user = container.lookup('current-user:main'),
|
||||||
site = container.lookup('site:main'),
|
site = container.lookup('site:main'),
|
||||||
|
@ -22,12 +23,11 @@ export default {
|
||||||
keyValueStore.remove('recent-notifications');
|
keyValueStore.remove('recent-notifications');
|
||||||
|
|
||||||
if (user) {
|
if (user) {
|
||||||
|
|
||||||
if (user.get('staff')) {
|
if (user.get('staff')) {
|
||||||
bus.subscribe('/flagged_counts', (data) => {
|
bus.subscribe('/flagged_counts', data => {
|
||||||
user.set('site_flagged_posts_count', data.total);
|
user.set('site_flagged_posts_count', data.total);
|
||||||
});
|
});
|
||||||
bus.subscribe('/queue_counts', (data) => {
|
bus.subscribe('/queue_counts', data => {
|
||||||
user.set('post_queue_new_count', data.post_queue_new_count);
|
user.set('post_queue_new_count', data.post_queue_new_count);
|
||||||
if (data.post_queue_new_count > 0) {
|
if (data.post_queue_new_count > 0) {
|
||||||
user.set('show_queued_posts', 1);
|
user.set('show_queued_posts', 1);
|
||||||
|
@ -35,7 +35,7 @@ export default {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
bus.subscribe(`/notification/${user.get('id')}`, function(data) {
|
bus.subscribe(`/notification/${user.get('id')}`, data => {
|
||||||
const oldUnread = user.get('unread_notifications');
|
const oldUnread = user.get('unread_notifications');
|
||||||
const oldPM = user.get('unread_private_messages');
|
const oldPM = user.get('unread_private_messages');
|
||||||
|
|
||||||
|
@ -50,27 +50,23 @@ export default {
|
||||||
const lastNotification = data.last_notification && data.last_notification.notification;
|
const lastNotification = data.last_notification && data.last_notification.notification;
|
||||||
|
|
||||||
if (stale && stale.hasResults && lastNotification) {
|
if (stale && stale.hasResults && lastNotification) {
|
||||||
|
|
||||||
const oldNotifications = stale.results.get('content');
|
const oldNotifications = stale.results.get('content');
|
||||||
const staleIndex = _.findIndex(oldNotifications, {id: lastNotification.id});
|
const staleIndex = _.findIndex(oldNotifications, {id: lastNotification.id});
|
||||||
|
|
||||||
if (staleIndex === -1) {
|
if (staleIndex === -1) {
|
||||||
// this gets a bit tricky, uread pms are bumped to front
|
// this gets a bit tricky, uread pms are bumped to front
|
||||||
var insertPosition = 0;
|
let insertPosition = 0;
|
||||||
if (lastNotification.notification_type !== 6) {
|
if (lastNotification.notification_type !== 6) {
|
||||||
insertPosition = _.findIndex(oldNotifications, function(n){
|
insertPosition = _.findIndex(oldNotifications, n => n.notification_type !== 6 || n.read);
|
||||||
return n.notification_type !== 6 || n.read;
|
|
||||||
});
|
|
||||||
insertPosition = insertPosition === -1 ? oldNotifications.length - 1 : insertPosition;
|
insertPosition = insertPosition === -1 ? oldNotifications.length - 1 : insertPosition;
|
||||||
}
|
}
|
||||||
|
|
||||||
oldNotifications.insertAt(insertPosition, Em.Object.create(lastNotification));
|
oldNotifications.insertAt(insertPosition, Em.Object.create(lastNotification));
|
||||||
}
|
}
|
||||||
|
|
||||||
for (var idx=0; idx < data.recent.length; idx++) {
|
for (let idx=0; idx < data.recent.length; idx++) {
|
||||||
var old;
|
let old;
|
||||||
while(old = oldNotifications[idx]) {
|
while(old = oldNotifications[idx]) {
|
||||||
var info = data.recent[idx];
|
const info = data.recent[idx];
|
||||||
|
|
||||||
if (old.get('id') !== info[0]) {
|
if (old.get('id') !== info[0]) {
|
||||||
oldNotifications.removeAt(idx);
|
oldNotifications.removeAt(idx);
|
||||||
|
@ -81,24 +77,18 @@ export default {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ( !old ) { break; }
|
if (!old) { break; }
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}, user.notification_channel_position);
|
}, user.notification_channel_position);
|
||||||
|
|
||||||
bus.subscribe("/categories", function(data) {
|
bus.subscribe("/categories", data => {
|
||||||
_.each(data.categories, function(c) {
|
_.each(data.categories, c => site.updateCategory(c));
|
||||||
site.updateCategory(c);
|
_.each(data.deleted_categories, id => site.removeCategory(id));
|
||||||
});
|
|
||||||
_.each(data.deleted_categories,function(id) {
|
|
||||||
site.removeCategory(id);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
bus.subscribe("/client_settings", function(data) {
|
bus.subscribe("/client_settings", data => Ember.set(siteSettings, data.name, data.value));
|
||||||
siteSettings[data.name] = data.value;
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!Ember.testing) {
|
if (!Ember.testing) {
|
||||||
if (!site.mobileView) {
|
if (!site.mobileView) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue