Added preference_changed web socket event

Этот коммит содержится в:
hmhealey
2015-12-07 18:13:14 -05:00
родитель b06f11fd63
Коммит 7d4a9ad376
6 изменённых файлов: 40 добавлений и 13 удалений

Просмотреть файл

@@ -95,9 +95,11 @@ func ShouldSendEvent(webCon *WebConn, msg *model.Message) bool {
return false return false
} }
} else { } else {
// Don't share a user's view events with other users // Don't share a user's view or preference events with other users
if msg.Action == model.ACTION_CHANNEL_VIEWED { if msg.Action == model.ACTION_CHANNEL_VIEWED {
return false return false
} else if msg.Action == model.ACTION_PREFERENCE_CHANGED {
return false
} }
// Only report events to a user who is the subject of the event, or is in the channel of the event // Only report events to a user who is the subject of the event, or is in the channel of the event

Просмотреть файл

@@ -9,14 +9,15 @@ import (
) )
const ( const (
ACTION_TYPING = "typing" ACTION_TYPING = "typing"
ACTION_POSTED = "posted" ACTION_POSTED = "posted"
ACTION_POST_EDITED = "post_edited" ACTION_POST_EDITED = "post_edited"
ACTION_POST_DELETED = "post_deleted" ACTION_POST_DELETED = "post_deleted"
ACTION_CHANNEL_VIEWED = "channel_viewed" ACTION_CHANNEL_VIEWED = "channel_viewed"
ACTION_NEW_USER = "new_user" ACTION_NEW_USER = "new_user"
ACTION_USER_ADDED = "user_added" ACTION_USER_ADDED = "user_added"
ACTION_USER_REMOVED = "user_removed" ACTION_USER_REMOVED = "user_removed"
ACTION_PREFERENCE_CHANGED = "preference_changed"
) )
type Message struct { type Message struct {

Просмотреть файл

@@ -148,3 +148,10 @@ export function emitClearSuggestions(suggestionId) {
id: suggestionId id: suggestionId
}); });
} }
export function emitPreferenceChangedEvent(preference) {
AppDispatcher.handleServerAction({
type: Constants.ActionTypes.RECIEVED_PREFERENCE,
preference
});
}

Просмотреть файл

@@ -90,8 +90,8 @@ class PreferenceStoreClass extends EventEmitter {
return preference; return preference;
} }
emitChange(preferences) { emitChange() {
this.emit(CHANGE_EVENT, preferences); this.emit(CHANGE_EVENT);
} }
addChangeListener(callback) { addChangeListener(callback) {
@@ -106,6 +106,12 @@ class PreferenceStoreClass extends EventEmitter {
const action = payload.action; const action = payload.action;
switch (action.type) { switch (action.type) {
case ActionTypes.RECIEVED_PREFERENCE: {
const preference = action.preference;
this.setPreference(preference.category, preference.name, preference.value);
this.emitChange();
break;
}
case ActionTypes.RECIEVED_PREFERENCES: { case ActionTypes.RECIEVED_PREFERENCES: {
const preferences = this.getAllPreferences(); const preferences = this.getAllPreferences();
@@ -114,7 +120,7 @@ class PreferenceStoreClass extends EventEmitter {
} }
this.setAllPreferences(preferences); this.setAllPreferences(preferences);
this.emitChange(preferences); this.emitChange();
break; break;
} }
} }

Просмотреть файл

@@ -135,6 +135,10 @@ class SocketStoreClass extends EventEmitter {
handleChannelViewedEvent(msg); handleChannelViewedEvent(msg);
break; break;
case SocketEvents.PREFERENCE_CHANGED:
handlePreferenceChangedEvent(msg);
break;
default: default:
} }
} }
@@ -279,6 +283,11 @@ function handleChannelViewedEvent(msg) {
} }
} }
function handlePreferenceChangedEvent(msg) {
const preference = JSON.parse(msg.props.preference);
EventHelpers.emitPreferenceChangedEvent(preference);
}
var SocketStore = new SocketStoreClass(); var SocketStore = new SocketStoreClass();
/*SocketStore.dispatchToken = AppDispatcher.register((payload) => { /*SocketStore.dispatchToken = AppDispatcher.register((payload) => {

Просмотреть файл

@@ -35,6 +35,7 @@ export default {
RECIEVED_AUDITS: null, RECIEVED_AUDITS: null,
RECIEVED_TEAMS: null, RECIEVED_TEAMS: null,
RECIEVED_STATUSES: null, RECIEVED_STATUSES: null,
RECIEVED_PREFERENCE: null,
RECIEVED_PREFERENCES: null, RECIEVED_PREFERENCES: null,
RECIEVED_MSG: null, RECIEVED_MSG: null,
@@ -74,7 +75,8 @@ export default {
NEW_USER: 'new_user', NEW_USER: 'new_user',
USER_ADDED: 'user_added', USER_ADDED: 'user_added',
USER_REMOVED: 'user_removed', USER_REMOVED: 'user_removed',
TYPING: 'typing' TYPING: 'typing',
PREFERENCE_CHANGED: 'preference_changed'
}, },
//SPECIAL_MENTIONS: ['all', 'channel'], //SPECIAL_MENTIONS: ['all', 'channel'],