kopia lustrzana https://gitlab.com/soapbox-pub/soapbox
Chat notifs: refactor actions
rodzic
e60457dd01
commit
d77ee9fec2
|
@ -23,14 +23,11 @@ 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 CHAT_NOTIFICATION = 'CHAT_NOTIFICATION';
|
|
||||||
|
|
||||||
export function fetchChats() {
|
export function fetchChats() {
|
||||||
return (dispatch, getState) => {
|
return (dispatch, getState) => {
|
||||||
dispatch({ type: CHATS_FETCH_REQUEST });
|
dispatch({ type: CHATS_FETCH_REQUEST });
|
||||||
return api(getState).get('/api/v1/pleroma/chats').then(({ data }) => {
|
return api(getState).get('/api/v1/pleroma/chats').then(({ data }) => {
|
||||||
dispatch({ type: CHATS_FETCH_SUCCESS, chats: data });
|
dispatch({ type: CHATS_FETCH_SUCCESS, chats: data });
|
||||||
chatsNotification(data);
|
|
||||||
}).catch(error => {
|
}).catch(error => {
|
||||||
dispatch({ type: CHATS_FETCH_FAIL, 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,
|
processTimelineUpdate,
|
||||||
} from './timelines';
|
} from './timelines';
|
||||||
import { updateNotificationsQueue, expandNotifications } from './notifications';
|
import { updateNotificationsQueue, expandNotifications } from './notifications';
|
||||||
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';
|
||||||
|
@ -56,8 +55,12 @@ export function connectTimelineStream(timelineId, path, pollingRefresh = null, a
|
||||||
dispatch(fetchFilters());
|
dispatch(fetchFilters());
|
||||||
break;
|
break;
|
||||||
case 'pleroma:chat_update':
|
case 'pleroma:chat_update':
|
||||||
dispatch(chatsNotification(JSON.parse(data.payload)));
|
dispatch({
|
||||||
dispatch({ type: STREAMING_CHAT_UPDATE, chat: JSON.parse(data.payload), me: getState().get('me') });
|
type: STREAMING_CHAT_UPDATE,
|
||||||
|
chat: JSON.parse(data.payload),
|
||||||
|
me: getState().get('me'),
|
||||||
|
meta: getSettings(getState()).getIn(['chats', 'sound']) && { sound: 'chat' },
|
||||||
|
});
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
@ -123,17 +123,6 @@ class ChatBox extends ImmutablePureComponent {
|
||||||
onSetInputRef(el);
|
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) => {
|
handleRemoveFile = (e) => {
|
||||||
this.setState({ attachment: undefined, resetFileKey: fileKeyGen() });
|
this.setState({ attachment: undefined, resetFileKey: fileKeyGen() });
|
||||||
}
|
}
|
||||||
|
|
Ładowanie…
Reference in New Issue