diff --git a/app/soapbox/actions/chats.js b/app/soapbox/actions/chats.js index f89b97fdb..2ca996cfe 100644 --- a/app/soapbox/actions/chats.js +++ b/app/soapbox/actions/chats.js @@ -1,5 +1,6 @@ import api, { getLinks } from '../api'; import { getSettings, changeSetting } from 'soapbox/actions/settings'; +import { getFeatures } from 'soapbox/utils/features'; import { v4 as uuidv4 } from 'uuid'; import { Map as ImmutableMap } from 'immutable'; @@ -31,9 +32,17 @@ export const CHAT_MESSAGE_DELETE_REQUEST = 'CHAT_MESSAGE_DELETE_REQUEST'; export const CHAT_MESSAGE_DELETE_SUCCESS = 'CHAT_MESSAGE_DELETE_SUCCESS'; export const CHAT_MESSAGE_DELETE_FAIL = 'CHAT_MESSAGE_DELETE_FAIL'; -export function fetchChats() { - return (dispatch, getState) => { - dispatch({ type: CHATS_FETCH_REQUEST }); +export function fetchChatsV1() { + return (dispatch, getState) => + api(getState).get('/api/v1/pleroma/chats').then((response) => { + dispatch({ type: CHATS_FETCH_SUCCESS, chats: response.data }); + }).catch(error => { + dispatch({ type: CHATS_FETCH_FAIL, error }); + }); +} + +export function fetchChatsV2() { + return (dispatch, getState) => api(getState).get('/api/v2/pleroma/chats').then((response) => { let next = getLinks(response).refs.find(link => link.rel === 'next'); @@ -45,6 +54,20 @@ export function fetchChats() { }).catch(error => { dispatch({ type: CHATS_FETCH_FAIL, error }); }); +} + +export function fetchChats() { + return (dispatch, getState) => { + const state = getState(); + const instance = state.get('instance'); + const features = getFeatures(instance); + + dispatch({ type: CHATS_FETCH_REQUEST }); + if (features.chatsV2) { + dispatch(fetchChatsV2()); + } else { + dispatch(fetchChatsV1()); + } }; } diff --git a/app/soapbox/utils/features.js b/app/soapbox/utils/features.js index bcab0098b..c544e7db5 100644 --- a/app/soapbox/utils/features.js +++ b/app/soapbox/utils/features.js @@ -54,6 +54,7 @@ export const getFeatures = createSelector([ importMutes: v.software === PLEROMA && gte(v.version, '2.2.0'), emailList: features.includes('email_list'), chats: v.software === PLEROMA && gte(v.version, '2.1.0'), + chatsV2: v.software === PLEROMA && gte(v.version, '2.3.0'), scopes: v.software === PLEROMA ? 'read write follow push admin' : 'read write follow push', federating: federation.get('enabled', true), // Assume true unless explicitly false richText: v.software === PLEROMA,