Refactor
This commit is contained in:
parent
9103797de4
commit
76f8e02fb9
6 changed files with 12 additions and 15 deletions
|
@ -23,8 +23,7 @@ export const CHAT_READ_REQUEST = 'CHAT_READ_REQUEST';
|
||||||
export const CHAT_READ_SUCCESS = 'CHAT_READ_SUCCESS';
|
export const CHAT_READ_SUCCESS = 'CHAT_READ_SUCCESS';
|
||||||
export const CHAT_READ_FAIL = 'CHAT_READ_FAIL';
|
export const CHAT_READ_FAIL = 'CHAT_READ_FAIL';
|
||||||
|
|
||||||
export const STREAMING_CHAT_UPDATE = 'STREAMING_CHAT_UPDATE';
|
export const CHAT_NOTIFICATION = 'CHAT_NOTIFICATION';
|
||||||
export const CHATS_UPDATE_NOOP = 'CHATS_UPDATE_NOOP';
|
|
||||||
|
|
||||||
export function fetchChats() {
|
export function fetchChats() {
|
||||||
return (dispatch, getState) => {
|
return (dispatch, getState) => {
|
||||||
|
@ -154,21 +153,19 @@ export function markChatRead(chatId, lastReadId) {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function updateChatsQueue(chat) {
|
export function chatsNotification(chat) {
|
||||||
return (dispatch, getState) => {
|
return (dispatch, getState) => {
|
||||||
const playSound = getSettings(getState()).getIn(['chats', 'sound']);
|
const playSound = getSettings(getState()).getIn(['chats', 'sound']);
|
||||||
// const flashWindow = getSettings(getState()).getIn(['chats', 'flash']);
|
// const flashWindow = getSettings(getState()).getIn(['chats', 'flash']); // implement when developing chat window flashing notification
|
||||||
|
|
||||||
if (playSound) {
|
if (playSound) {
|
||||||
if (chat.last_message &&
|
if (chat.last_message &&
|
||||||
chat.last_message.account_id !== getState().get('me')) {
|
chat.last_message.account_id !== getState().get('me')) {
|
||||||
dispatch({
|
dispatch({
|
||||||
type: CHATS_UPDATE_NOOP,
|
type: CHAT_NOTIFICATION,
|
||||||
meta: { sound: 'chat' },
|
meta: { sound: 'chat' },
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
dispatch({ type: STREAMING_CHAT_UPDATE, chat: chat, me: getState().get('me') });
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
@ -7,13 +7,13 @@ import {
|
||||||
processTimelineUpdate,
|
processTimelineUpdate,
|
||||||
} from './timelines';
|
} from './timelines';
|
||||||
import { updateNotificationsQueue, expandNotifications } from './notifications';
|
import { updateNotificationsQueue, expandNotifications } from './notifications';
|
||||||
import { updateChatsQueue } from './chats';
|
import { chatsNotification } from './chats';
|
||||||
import { updateConversations } from './conversations';
|
import { updateConversations } from './conversations';
|
||||||
import { fetchFilters } from './filters';
|
import { fetchFilters } from './filters';
|
||||||
import { getSettings } from 'soapbox/actions/settings';
|
import { getSettings } from 'soapbox/actions/settings';
|
||||||
import messages from 'soapbox/locales/messages';
|
import messages from 'soapbox/locales/messages';
|
||||||
|
|
||||||
// export const STREAMING_CHAT_UPDATE = 'STREAMING_CHAT_UPDATE';
|
export const STREAMING_CHAT_UPDATE = 'STREAMING_CHAT_UPDATE';
|
||||||
|
|
||||||
const validLocale = locale => Object.keys(messages).includes(locale);
|
const validLocale = locale => Object.keys(messages).includes(locale);
|
||||||
|
|
||||||
|
@ -56,8 +56,8 @@ export function connectTimelineStream(timelineId, path, pollingRefresh = null, a
|
||||||
dispatch(fetchFilters());
|
dispatch(fetchFilters());
|
||||||
break;
|
break;
|
||||||
case 'pleroma:chat_update':
|
case 'pleroma:chat_update':
|
||||||
dispatch(updateChatsQueue(JSON.parse(data.payload)));
|
dispatch(chatsNotification(JSON.parse(data.payload)));
|
||||||
// dispatch({ type: STREAMING_CHAT_UPDATE, chat: JSON.parse(data.payload), me: getState().get('me') });
|
dispatch({ type: STREAMING_CHAT_UPDATE, chat: JSON.parse(data.payload), me: getState().get('me') });
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
@ -4,7 +4,7 @@ import {
|
||||||
ACCOUNT_FETCH_FAIL_FOR_USERNAME_LOOKUP,
|
ACCOUNT_FETCH_FAIL_FOR_USERNAME_LOOKUP,
|
||||||
} from '../actions/importer';
|
} from '../actions/importer';
|
||||||
import { CHATS_FETCH_SUCCESS, CHAT_FETCH_SUCCESS } from 'soapbox/actions/chats';
|
import { CHATS_FETCH_SUCCESS, CHAT_FETCH_SUCCESS } from 'soapbox/actions/chats';
|
||||||
import { STREAMING_CHAT_UPDATE } from 'soapbox/actions/chats';
|
import { STREAMING_CHAT_UPDATE } from 'soapbox/actions/streaming';
|
||||||
import { normalizeAccount as normalizeAccount2 } from 'soapbox/actions/importer/normalizer';
|
import { normalizeAccount as normalizeAccount2 } from 'soapbox/actions/importer/normalizer';
|
||||||
import { Map as ImmutableMap, fromJS } from 'immutable';
|
import { Map as ImmutableMap, fromJS } from 'immutable';
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@ import {
|
||||||
CHAT_MESSAGE_SEND_REQUEST,
|
CHAT_MESSAGE_SEND_REQUEST,
|
||||||
CHAT_MESSAGE_SEND_SUCCESS,
|
CHAT_MESSAGE_SEND_SUCCESS,
|
||||||
} from 'soapbox/actions/chats';
|
} from 'soapbox/actions/chats';
|
||||||
import { STREAMING_CHAT_UPDATE } from 'soapbox/actions/chats';
|
import { STREAMING_CHAT_UPDATE } from 'soapbox/actions/streaming';
|
||||||
import { Map as ImmutableMap, OrderedSet as ImmutableOrderedSet } from 'immutable';
|
import { Map as ImmutableMap, OrderedSet as ImmutableOrderedSet } from 'immutable';
|
||||||
|
|
||||||
const initialState = ImmutableMap();
|
const initialState = ImmutableMap();
|
||||||
|
|
|
@ -4,7 +4,7 @@ import {
|
||||||
CHAT_MESSAGE_SEND_REQUEST,
|
CHAT_MESSAGE_SEND_REQUEST,
|
||||||
CHAT_MESSAGE_SEND_SUCCESS,
|
CHAT_MESSAGE_SEND_SUCCESS,
|
||||||
} from 'soapbox/actions/chats';
|
} from 'soapbox/actions/chats';
|
||||||
import { STREAMING_CHAT_UPDATE } from 'soapbox/actions/chats';
|
import { STREAMING_CHAT_UPDATE } from 'soapbox/actions/streaming';
|
||||||
import { Map as ImmutableMap, fromJS } from 'immutable';
|
import { Map as ImmutableMap, fromJS } from 'immutable';
|
||||||
|
|
||||||
const initialState = ImmutableMap();
|
const initialState = ImmutableMap();
|
||||||
|
|
|
@ -4,7 +4,7 @@ import {
|
||||||
CHAT_READ_SUCCESS,
|
CHAT_READ_SUCCESS,
|
||||||
CHAT_READ_REQUEST,
|
CHAT_READ_REQUEST,
|
||||||
} from 'soapbox/actions/chats';
|
} from 'soapbox/actions/chats';
|
||||||
import { STREAMING_CHAT_UPDATE } from 'soapbox/actions/chats';
|
import { STREAMING_CHAT_UPDATE } from 'soapbox/actions/streaming';
|
||||||
import { normalizeChat } from 'soapbox/actions/importer/normalizer';
|
import { normalizeChat } from 'soapbox/actions/importer/normalizer';
|
||||||
import { Map as ImmutableMap, fromJS } from 'immutable';
|
import { Map as ImmutableMap, fromJS } from 'immutable';
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue