Chat notifs: refactor actions
This commit is contained in:
parent
e60457dd01
commit
d77ee9fec2
3 changed files with 6 additions and 34 deletions
|
@ -23,14 +23,11 @@ export const CHAT_READ_REQUEST = 'CHAT_READ_REQUEST';
|
|||
export const CHAT_READ_SUCCESS = 'CHAT_READ_SUCCESS';
|
||||
export const CHAT_READ_FAIL = 'CHAT_READ_FAIL';
|
||||
|
||||
export const CHAT_NOTIFICATION = 'CHAT_NOTIFICATION';
|
||||
|
||||
export function fetchChats() {
|
||||
return (dispatch, getState) => {
|
||||
dispatch({ type: CHATS_FETCH_REQUEST });
|
||||
return api(getState).get('/api/v1/pleroma/chats').then(({ data }) => {
|
||||
dispatch({ type: CHATS_FETCH_SUCCESS, chats: data });
|
||||
chatsNotification(data);
|
||||
}).catch(error => {
|
||||
dispatch({ type: CHATS_FETCH_FAIL, error });
|
||||
});
|
||||
|
@ -153,20 +150,3 @@ export function markChatRead(chatId, lastReadId) {
|
|||
});
|
||||
};
|
||||
}
|
||||
|
||||
export function chatsNotification(chat) {
|
||||
return (dispatch, getState) => {
|
||||
const playSound = getSettings(getState()).getIn(['chats', 'sound']);
|
||||
// const flashWindow = getSettings(getState()).getIn(['chats', 'flash']); // implement when developing chat window flashing notification
|
||||
|
||||
if (playSound) {
|
||||
if (chat.last_message &&
|
||||
chat.last_message.account_id !== getState().get('me')) {
|
||||
dispatch({
|
||||
type: CHAT_NOTIFICATION,
|
||||
meta: { sound: 'chat' },
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
||||
|
|
|
@ -7,7 +7,6 @@ import {
|
|||
processTimelineUpdate,
|
||||
} from './timelines';
|
||||
import { updateNotificationsQueue, expandNotifications } from './notifications';
|
||||
import { chatsNotification } from './chats';
|
||||
import { updateConversations } from './conversations';
|
||||
import { fetchFilters } from './filters';
|
||||
import { getSettings } from 'soapbox/actions/settings';
|
||||
|
@ -56,8 +55,12 @@ export function connectTimelineStream(timelineId, path, pollingRefresh = null, a
|
|||
dispatch(fetchFilters());
|
||||
break;
|
||||
case 'pleroma:chat_update':
|
||||
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'),
|
||||
meta: getSettings(getState()).getIn(['chats', 'sound']) && { sound: 'chat' },
|
||||
});
|
||||
break;
|
||||
}
|
||||
},
|
||||
|
|
|
@ -123,17 +123,6 @@ class ChatBox extends ImmutablePureComponent {
|
|||
onSetInputRef(el);
|
||||
};
|
||||
|
||||
// componentDidUpdate(prevProps) {
|
||||
// const markReadConditions = [
|
||||
// () => this.props.chat !== undefined,
|
||||
// () => document.activeElement === this.inputElem,
|
||||
// () => this.props.chat.get('unread') > 0,
|
||||
// ];
|
||||
//
|
||||
// if (markReadConditions.every(c => c() === true))
|
||||
// this.markRead();
|
||||
// }
|
||||
|
||||
handleRemoveFile = (e) => {
|
||||
this.setState({ attachment: undefined, resetFileKey: fileKeyGen() });
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue