diff --git a/app/gabsocial/actions/accounts.js b/app/gabsocial/actions/accounts.js index c02892c38..ec1d1cb6b 100644 --- a/app/gabsocial/actions/accounts.js +++ b/app/gabsocial/actions/accounts.js @@ -6,7 +6,6 @@ import { importFetchedAccounts, importErrorWhileFetchingAccountByUsername, } from './importer'; -import { me } from 'gabsocial/initial_state'; export const ACCOUNT_FETCH_REQUEST = 'ACCOUNT_FETCH_REQUEST'; export const ACCOUNT_FETCH_SUCCESS = 'ACCOUNT_FETCH_SUCCESS'; @@ -163,7 +162,7 @@ export function fetchAccountFail(id, error) { export function followAccount(id, reblogs = true) { return (dispatch, getState) => { - if (!me) return; + if (!getState().get('me')) return; const alreadyFollowing = getState().getIn(['relationships', id, 'following']); const locked = getState().getIn(['accounts', id, 'locked'], false); @@ -180,7 +179,7 @@ export function followAccount(id, reblogs = true) { export function unfollowAccount(id) { return (dispatch, getState) => { - if (!me) return; + if (!getState().get('me')) return; dispatch(unfollowAccountRequest(id)); @@ -246,7 +245,7 @@ export function unfollowAccountFail(error) { export function blockAccount(id) { return (dispatch, getState) => { - if (!me) return; + if (!getState().get('me')) return; dispatch(blockAccountRequest(id)); @@ -261,7 +260,7 @@ export function blockAccount(id) { export function unblockAccount(id) { return (dispatch, getState) => { - if (!me) return; + if (!getState().get('me')) return; dispatch(unblockAccountRequest(id)); @@ -319,7 +318,7 @@ export function unblockAccountFail(error) { export function muteAccount(id, notifications) { return (dispatch, getState) => { - if (!me) return; + if (!getState().get('me')) return; dispatch(muteAccountRequest(id)); @@ -334,7 +333,7 @@ export function muteAccount(id, notifications) { export function unmuteAccount(id) { return (dispatch, getState) => { - if (!me) return; + if (!getState().get('me')) return; dispatch(unmuteAccountRequest(id)); @@ -392,7 +391,7 @@ export function unmuteAccountFail(error) { export function fetchFollowers(id) { return (dispatch, getState) => { - if (!me) return; + if (!getState().get('me')) return; dispatch(fetchFollowersRequest(id)); @@ -434,7 +433,7 @@ export function fetchFollowersFail(id, error) { export function expandFollowers(id) { return (dispatch, getState) => { - if (!me) return; + if (!getState().get('me')) return; const url = getState().getIn(['user_lists', 'followers', id, 'next']); @@ -482,7 +481,7 @@ export function expandFollowersFail(id, error) { export function fetchFollowing(id) { return (dispatch, getState) => { - if (!me) return; + if (!getState().get('me')) return; dispatch(fetchFollowingRequest(id)); @@ -524,7 +523,7 @@ export function fetchFollowingFail(id, error) { export function expandFollowing(id) { return (dispatch, getState) => { - if (!me) return; + if (!getState().get('me')) return; const url = getState().getIn(['user_lists', 'following', id, 'next']); @@ -572,7 +571,7 @@ export function expandFollowingFail(id, error) { export function fetchRelationships(accountIds) { return (dispatch, getState) => { - if (!me) return; + if (!getState().get('me')) return; const loadedRelationships = getState().get('relationships'); const newAccountIds = accountIds.filter(id => loadedRelationships.get(id, null) === null); @@ -617,7 +616,7 @@ export function fetchRelationshipsFail(error) { export function fetchFollowRequests() { return (dispatch, getState) => { - if (!me) return; + if (!getState().get('me')) return; dispatch(fetchFollowRequestsRequest()); @@ -652,7 +651,7 @@ export function fetchFollowRequestsFail(error) { export function expandFollowRequests() { return (dispatch, getState) => { - if (!me) return; + if (!getState().get('me')) return; const url = getState().getIn(['user_lists', 'follow_requests', 'next']); @@ -693,7 +692,7 @@ export function expandFollowRequestsFail(error) { export function authorizeFollowRequest(id) { return (dispatch, getState) => { - if (!me) return; + if (!getState().get('me')) return; dispatch(authorizeFollowRequestRequest(id)); @@ -729,7 +728,7 @@ export function authorizeFollowRequestFail(id, error) { export function rejectFollowRequest(id) { return (dispatch, getState) => { - if (!me) return; + if (!getState().get('me')) return; dispatch(rejectFollowRequestRequest(id)); @@ -764,7 +763,7 @@ export function rejectFollowRequestFail(id, error) { export function pinAccount(id) { return (dispatch, getState) => { - if (!me) return; + if (!getState().get('me')) return; dispatch(pinAccountRequest(id)); @@ -778,7 +777,7 @@ export function pinAccount(id) { export function unpinAccount(id) { return (dispatch, getState) => { - if (!me) return; + if (!getState().get('me')) return; dispatch(unpinAccountRequest(id)); diff --git a/app/gabsocial/actions/blocks.js b/app/gabsocial/actions/blocks.js index 69db572a3..d891999bb 100644 --- a/app/gabsocial/actions/blocks.js +++ b/app/gabsocial/actions/blocks.js @@ -1,7 +1,6 @@ import api, { getLinks } from '../api'; import { fetchRelationships } from './accounts'; import { importFetchedAccounts } from './importer'; -import { me } from 'gabsocial/initial_state'; export const BLOCKS_FETCH_REQUEST = 'BLOCKS_FETCH_REQUEST'; export const BLOCKS_FETCH_SUCCESS = 'BLOCKS_FETCH_SUCCESS'; @@ -13,7 +12,7 @@ export const BLOCKS_EXPAND_FAIL = 'BLOCKS_EXPAND_FAIL'; export function fetchBlocks() { return (dispatch, getState) => { - if (!me) return; + if (!getState().get('me')) return; dispatch(fetchBlocksRequest()); @@ -49,8 +48,8 @@ export function fetchBlocksFail(error) { export function expandBlocks() { return (dispatch, getState) => { - if (!me) return; - + if (!getState().get('me')) return; + const url = getState().getIn(['user_lists', 'blocks', 'next']); if (url === null) { diff --git a/app/gabsocial/actions/compose.js b/app/gabsocial/actions/compose.js index 1c815c044..aaa5aebc9 100644 --- a/app/gabsocial/actions/compose.js +++ b/app/gabsocial/actions/compose.js @@ -11,7 +11,6 @@ import { showAlertForError } from './alerts'; import { showAlert } from './alerts'; import { defineMessages } from 'react-intl'; import { openModal, closeModal } from './modal'; -import { me } from 'gabsocial/initial_state'; let cancelFetchComposeSuggestionsAccounts; @@ -153,7 +152,7 @@ export function handleComposeSubmit(dispatch, getState, response, status) { export function submitCompose(routerHistory, group) { return function (dispatch, getState) { - if (!me) return; + if (!getState().get('me')) return; const status = getState().getIn(['compose', 'text'], ''); const media = getState().getIn(['compose', 'media_attachments']); @@ -211,7 +210,7 @@ export function submitComposeFail(error) { export function uploadCompose(files) { return function (dispatch, getState) { - if (!me) return; + if (!getState().get('me')) return; const uploadLimit = 4; const media = getState().getIn(['compose', 'media_attachments']); @@ -252,7 +251,7 @@ export function uploadCompose(files) { export function changeUploadCompose(id, params) { return (dispatch, getState) => { - if (!me) return; + if (!getState().get('me')) return; dispatch(changeUploadComposeRequest()); @@ -440,7 +439,7 @@ export function updateTagHistory(tags) { export function hydrateCompose() { return (dispatch, getState) => { - const me = getState().getIn(['meta', 'me']); + const me = getState().get('me'); const history = tagHistory.get(me); if (history !== null) { @@ -453,7 +452,7 @@ function insertIntoTagHistory(recognizedTags, text) { return (dispatch, getState) => { const state = getState(); const oldHistory = state.getIn(['compose', 'tagHistory']); - const me = state.getIn(['meta', 'me']); + const me = state.get('me'); const names = recognizedTags.map(tag => text.match(new RegExp(`#${tag.name}`, 'i'))[0].slice(1)); const intersectedOldHistory = oldHistory.filter(name => names.findIndex(newName => newName.toLowerCase() === name.toLowerCase()) === -1); diff --git a/app/gabsocial/actions/conversations.js b/app/gabsocial/actions/conversations.js index d69dcb08c..22b5ad526 100644 --- a/app/gabsocial/actions/conversations.js +++ b/app/gabsocial/actions/conversations.js @@ -4,7 +4,6 @@ import { importFetchedStatuses, importFetchedStatus, } from './importer'; -import { me } from 'gabsocial/initial_state'; export const CONVERSATIONS_MOUNT = 'CONVERSATIONS_MOUNT'; export const CONVERSATIONS_UNMOUNT = 'CONVERSATIONS_UNMOUNT'; @@ -25,7 +24,7 @@ export const unmountConversations = () => ({ }); export const markConversationRead = conversationId => (dispatch, getState) => { - if (!me) return; + if (!getState().get('me')) return; dispatch({ type: CONVERSATIONS_READ, @@ -36,8 +35,8 @@ export const markConversationRead = conversationId => (dispatch, getState) => { }; export const expandConversations = ({ maxId } = {}) => (dispatch, getState) => { - if (!me) return; - + if (!getState().get('me')) return; + dispatch(expandConversationsRequest()); const params = { max_id: maxId }; diff --git a/app/gabsocial/actions/domain_blocks.js b/app/gabsocial/actions/domain_blocks.js index e7aadb559..efd878661 100644 --- a/app/gabsocial/actions/domain_blocks.js +++ b/app/gabsocial/actions/domain_blocks.js @@ -1,5 +1,4 @@ import api, { getLinks } from '../api'; -import { me } from 'gabsocial/initial_state'; export const DOMAIN_BLOCK_REQUEST = 'DOMAIN_BLOCK_REQUEST'; export const DOMAIN_BLOCK_SUCCESS = 'DOMAIN_BLOCK_SUCCESS'; @@ -19,7 +18,7 @@ export const DOMAIN_BLOCKS_EXPAND_FAIL = 'DOMAIN_BLOCKS_EXPAND_FAIL'; export function blockDomain(domain) { return (dispatch, getState) => { - if (!me) return; + if (!getState().get('me')) return; dispatch(blockDomainRequest(domain)); @@ -58,7 +57,7 @@ export function blockDomainFail(domain, error) { export function unblockDomain(domain) { return (dispatch, getState) => { - if (!me) return; + if (!getState().get('me')) return; dispatch(unblockDomainRequest(domain)); @@ -97,7 +96,7 @@ export function unblockDomainFail(domain, error) { export function fetchDomainBlocks() { return (dispatch, getState) => { - if (!me) return; + if (!getState().get('me')) return; dispatch(fetchDomainBlocksRequest()); @@ -133,8 +132,8 @@ export function fetchDomainBlocksFail(error) { export function expandDomainBlocks() { return (dispatch, getState) => { - if (!me) return; - + if (!getState().get('me')) return; + const url = getState().getIn(['domain_lists', 'blocks', 'next']); if (!url) { diff --git a/app/gabsocial/actions/favourites.js b/app/gabsocial/actions/favourites.js index 849981e47..d5b774f12 100644 --- a/app/gabsocial/actions/favourites.js +++ b/app/gabsocial/actions/favourites.js @@ -1,6 +1,5 @@ import api, { getLinks } from '../api'; import { importFetchedStatuses } from './importer'; -import { me } from 'gabsocial/initial_state'; export const FAVOURITED_STATUSES_FETCH_REQUEST = 'FAVOURITED_STATUSES_FETCH_REQUEST'; export const FAVOURITED_STATUSES_FETCH_SUCCESS = 'FAVOURITED_STATUSES_FETCH_SUCCESS'; @@ -12,7 +11,7 @@ export const FAVOURITED_STATUSES_EXPAND_FAIL = 'FAVOURITED_STATUSES_EXPAND_FA export function fetchFavouritedStatuses() { return (dispatch, getState) => { - if (!me) return; + if (!getState().get('me')) return; if (getState().getIn(['status_lists', 'favourites', 'isLoading'])) { return; @@ -56,8 +55,8 @@ export function fetchFavouritedStatusesFail(error) { export function expandFavouritedStatuses() { return (dispatch, getState) => { - if (!me) return; - + if (!getState().get('me')) return; + const url = getState().getIn(['status_lists', 'favourites', 'next'], null); if (url === null || getState().getIn(['status_lists', 'favourites', 'isLoading'])) { diff --git a/app/gabsocial/actions/filters.js b/app/gabsocial/actions/filters.js index 0f8dd0eac..b8e3d27aa 100644 --- a/app/gabsocial/actions/filters.js +++ b/app/gabsocial/actions/filters.js @@ -1,12 +1,11 @@ import api from '../api'; -import { me } from 'gabsocial/initial_state'; export const FILTERS_FETCH_REQUEST = 'FILTERS_FETCH_REQUEST'; export const FILTERS_FETCH_SUCCESS = 'FILTERS_FETCH_SUCCESS'; export const FILTERS_FETCH_FAIL = 'FILTERS_FETCH_FAIL'; export const fetchFilters = () => (dispatch, getState) => { - if (!me) return; + if (!getState().get('me')) return; dispatch({ type: FILTERS_FETCH_REQUEST, diff --git a/app/gabsocial/actions/group_editor.js b/app/gabsocial/actions/group_editor.js index e464c1c6e..be4c481ff 100644 --- a/app/gabsocial/actions/group_editor.js +++ b/app/gabsocial/actions/group_editor.js @@ -1,5 +1,4 @@ import api from '../api'; -import { me } from 'gabsocial/initial_state'; export const GROUP_CREATE_REQUEST = 'GROUP_CREATE_REQUEST'; export const GROUP_CREATE_SUCCESS = 'GROUP_CREATE_SUCCESS'; @@ -28,7 +27,7 @@ export const submit = (routerHistory) => (dispatch, getState) => { export const create = (title, description, coverImage, routerHistory) => (dispatch, getState) => { - if (!me) return; + if (!getState().get('me')) return; dispatch(createRequest()); @@ -39,13 +38,13 @@ export const create = (title, description, coverImage, routerHistory) => (dispat if (coverImage !== null) { formData.append('cover_image', coverImage); } - + api(getState).post('/api/v1/groups', formData, { headers: { 'Content-Type': 'multipart/form-data' } }).then(({ data }) => { dispatch(createSuccess(data)); routerHistory.push(`/groups/${data.id}`); }).catch(err => dispatch(createFail(err))); }; - + export const createRequest = id => ({ type: GROUP_CREATE_REQUEST, @@ -63,7 +62,7 @@ export const createFail = error => ({ }); export const update = (groupId, title, description, coverImage, routerHistory) => (dispatch, getState) => { - if (!me) return; + if (!getState().get('me')) return; dispatch(updateRequest()); @@ -74,13 +73,13 @@ export const update = (groupId, title, description, coverImage, routerHistory) = if (coverImage !== null) { formData.append('cover_image', coverImage); } - + api(getState).put(`/api/v1/groups/${groupId}`, formData, { headers: { 'Content-Type': 'multipart/form-data' } }).then(({ data }) => { dispatch(updateSuccess(data)); routerHistory.push(`/groups/${data.id}`); }).catch(err => dispatch(updateFail(err))); }; - + export const updateRequest = id => ({ type: GROUP_UPDATE_REQUEST, @@ -110,4 +109,4 @@ export const reset = () => ({ export const setUp = (group) => ({ type: GROUP_EDITOR_SETUP, group, -}); \ No newline at end of file +}); diff --git a/app/gabsocial/actions/groups.js b/app/gabsocial/actions/groups.js index eac343718..bd35219b0 100644 --- a/app/gabsocial/actions/groups.js +++ b/app/gabsocial/actions/groups.js @@ -1,5 +1,4 @@ import api, { getLinks } from '../api'; -import { me } from 'gabsocial/initial_state'; import { importFetchedAccounts } from './importer'; import { fetchRelationships } from './accounts'; @@ -52,7 +51,7 @@ export const GROUP_REMOVE_STATUS_SUCCESS = 'GROUP_REMOVE_STATUS_SUCCESS'; export const GROUP_REMOVE_STATUS_FAIL = 'GROUP_REMOVE_STATUS_FAIL'; export const fetchGroup = id => (dispatch, getState) => { - if (!me) return; + if (!getState().get('me')) return; dispatch(fetchGroupRelationships([id])); @@ -85,7 +84,7 @@ export const fetchGroupFail = (id, error) => ({ export function fetchGroupRelationships(groupIds) { return (dispatch, getState) => { - if (!me) return; + if (!getState().get('me')) return; const loadedRelationships = getState().get('group_relationships'); const newGroupIds = groupIds.filter(id => loadedRelationships.get(id, null) === null); @@ -129,7 +128,7 @@ export function fetchGroupRelationshipsFail(error) { }; export const fetchGroups = (tab) => (dispatch, getState) => { - if (!me) return; + if (!getState().get('me')) return; dispatch(fetchGroupsRequest()); @@ -158,7 +157,7 @@ export const fetchGroupsFail = error => ({ export function joinGroup(id) { return (dispatch, getState) => { - if (!me) return; + if (!getState().get('me')) return; dispatch(joinGroupRequest(id)); @@ -172,8 +171,8 @@ export function joinGroup(id) { export function leaveGroup(id) { return (dispatch, getState) => { - if (!me) return; - + if (!getState().get('me')) return; + dispatch(leaveGroupRequest(id)); api(getState).delete(`/api/v1/groups/${id}/accounts`).then(response => { @@ -228,7 +227,7 @@ export function leaveGroupFail(error) { export function fetchMembers(id) { return (dispatch, getState) => { - if (!me) return; + if (!getState().get('me')) return; dispatch(fetchMembersRequest(id)); @@ -270,7 +269,7 @@ export function fetchMembersFail(id, error) { export function expandMembers(id) { return (dispatch, getState) => { - if (!me) return; + if (!getState().get('me')) return; const url = getState().getIn(['user_lists', 'groups', id, 'next']); @@ -318,7 +317,7 @@ export function expandMembersFail(id, error) { export function fetchRemovedAccounts(id) { return (dispatch, getState) => { - if (!me) return; + if (!getState().get('me')) return; dispatch(fetchRemovedAccountsRequest(id)); @@ -360,7 +359,7 @@ export function fetchRemovedAccountsFail(id, error) { export function expandRemovedAccounts(id) { return (dispatch, getState) => { - if (!me) return; + if (!getState().get('me')) return; const url = getState().getIn(['user_lists', 'groups_removed_accounts', id, 'next']); @@ -408,7 +407,7 @@ export function expandRemovedAccountsFail(id, error) { export function removeRemovedAccount(groupId, id) { return (dispatch, getState) => { - if (!me) return; + if (!getState().get('me')) return; dispatch(removeRemovedAccountRequest(groupId, id)); @@ -447,7 +446,7 @@ export function removeRemovedAccountFail(groupId, id, error) { export function createRemovedAccount(groupId, id) { return (dispatch, getState) => { - if (!me) return; + if (!getState().get('me')) return; dispatch(createRemovedAccountRequest(groupId, id)); @@ -486,7 +485,7 @@ export function createRemovedAccountFail(groupId, id, error) { export function groupRemoveStatus(groupId, id) { return (dispatch, getState) => { - if (!me) return; + if (!getState().get('me')) return; dispatch(groupRemoveStatusRequest(groupId, id)); @@ -521,4 +520,4 @@ export function groupRemoveStatusFail(groupId, id, error) { id, error, }; -}; \ No newline at end of file +}; diff --git a/app/gabsocial/actions/interactions.js b/app/gabsocial/actions/interactions.js index 542b96b57..b3099a785 100644 --- a/app/gabsocial/actions/interactions.js +++ b/app/gabsocial/actions/interactions.js @@ -1,6 +1,5 @@ import api from '../api'; import { importFetchedAccounts, importFetchedStatus } from './importer'; -import { me } from 'gabsocial/initial_state'; export const REBLOG_REQUEST = 'REBLOG_REQUEST'; export const REBLOG_SUCCESS = 'REBLOG_SUCCESS'; @@ -36,7 +35,7 @@ export const UNPIN_FAIL = 'UNPIN_FAIL'; export function reblog(status) { return function (dispatch, getState) { - if (!me) return; + if (!getState().get('me')) return; dispatch(reblogRequest(status)); @@ -53,7 +52,7 @@ export function reblog(status) { export function unreblog(status) { return (dispatch, getState) => { - if (!me) return; + if (!getState().get('me')) return; dispatch(unreblogRequest(status)); @@ -118,7 +117,7 @@ export function unreblogFail(status, error) { export function favourite(status) { return function (dispatch, getState) { - if (!me) return; + if (!getState().get('me')) return; dispatch(favouriteRequest(status)); @@ -133,7 +132,7 @@ export function favourite(status) { export function unfavourite(status) { return (dispatch, getState) => { - if (!me) return; + if (!getState().get('me')) return; dispatch(unfavouriteRequest(status)); @@ -198,7 +197,7 @@ export function unfavouriteFail(status, error) { export function fetchReblogs(id) { return (dispatch, getState) => { - if (!me) return; + if (!getState().get('me')) return; dispatch(fetchReblogsRequest(id)); @@ -235,7 +234,7 @@ export function fetchReblogsFail(id, error) { export function fetchFavourites(id) { return (dispatch, getState) => { - if (!me) return; + if (!getState().get('me')) return; dispatch(fetchFavouritesRequest(id)); @@ -272,7 +271,7 @@ export function fetchFavouritesFail(id, error) { export function pin(status) { return (dispatch, getState) => { - if (!me) return; + if (!getState().get('me')) return; dispatch(pinRequest(status)); @@ -312,8 +311,8 @@ export function pinFail(status, error) { export function unpin (status) { return (dispatch, getState) => { - if (!me) return; - + if (!getState().get('me')) return; + dispatch(unpinRequest(status)); api(getState).post(`/api/v1/statuses/${status.get('id')}/unpin`).then(response => { diff --git a/app/gabsocial/actions/lists.js b/app/gabsocial/actions/lists.js index 3461c6b33..d93ddc43c 100644 --- a/app/gabsocial/actions/lists.js +++ b/app/gabsocial/actions/lists.js @@ -1,7 +1,6 @@ import api from '../api'; import { importFetchedAccounts } from './importer'; import { showAlertForError } from './alerts'; -import { me } from 'gabsocial/initial_state' export const LIST_FETCH_REQUEST = 'LIST_FETCH_REQUEST'; export const LIST_FETCH_SUCCESS = 'LIST_FETCH_SUCCESS'; @@ -51,7 +50,7 @@ export const LIST_ADDER_LISTS_FETCH_SUCCESS = 'LIST_ADDER_LISTS_FETCH_SUCCESS'; export const LIST_ADDER_LISTS_FETCH_FAIL = 'LIST_ADDER_LISTS_FETCH_FAIL'; export const fetchList = id => (dispatch, getState) => { - if (!me) return; + if (!getState().get('me')) return; if (getState().getIn(['lists', id])) { return; @@ -81,7 +80,7 @@ export const fetchListFail = (id, error) => ({ }); export const fetchLists = () => (dispatch, getState) => { - if (!me) return; + if (!getState().get('me')) return; dispatch(fetchListsRequest()); @@ -130,7 +129,7 @@ export const changeListEditorTitle = value => ({ }); export const createList = (title, shouldReset) => (dispatch, getState) => { - if (!me) return; + if (!getState().get('me')) return; dispatch(createListRequest()); @@ -158,7 +157,7 @@ export const createListFail = error => ({ }); export const updateList = (id, title, shouldReset) => (dispatch, getState) => { - if (!me) return; + if (!getState().get('me')) return; dispatch(updateListRequest(id)); @@ -192,7 +191,7 @@ export const resetListEditor = () => ({ }); export const deleteList = id => (dispatch, getState) => { - if (!me) return; + if (!getState().get('me')) return; dispatch(deleteListRequest(id)); @@ -218,7 +217,7 @@ export const deleteListFail = (id, error) => ({ }); export const fetchListAccounts = listId => (dispatch, getState) => { - if (!me) return; + if (!getState().get('me')) return; dispatch(fetchListAccountsRequest(listId)); @@ -247,7 +246,7 @@ export const fetchListAccountsFail = (id, error) => ({ }); export const fetchListSuggestions = q => (dispatch, getState) => { - if (!me) return; + if (!getState().get('me')) return; const params = { q, @@ -282,7 +281,7 @@ export const addToListEditor = accountId => (dispatch, getState) => { }; export const addToList = (listId, accountId) => (dispatch, getState) => { - if (!me) return; + if (!getState().get('me')) return; dispatch(addToListRequest(listId, accountId)); @@ -315,7 +314,7 @@ export const removeFromListEditor = accountId => (dispatch, getState) => { }; export const removeFromList = (listId, accountId) => (dispatch, getState) => { - if (!me) return; + if (!getState().get('me')) return; dispatch(removeFromListRequest(listId, accountId)); @@ -357,7 +356,7 @@ export const setupListAdder = accountId => (dispatch, getState) => { }; export const fetchAccountLists = accountId => (dispatch, getState) => { - if (!me) return; + if (!getState().get('me')) return; dispatch(fetchAccountListsRequest(accountId)); diff --git a/app/gabsocial/actions/me.js b/app/gabsocial/actions/me.js new file mode 100644 index 000000000..0925fcf40 --- /dev/null +++ b/app/gabsocial/actions/me.js @@ -0,0 +1,39 @@ +import api from '../api'; +import { importFetchedAccount } from './importer'; + +export const ME_FETCH_REQUEST = 'ME_FETCH_REQUEST'; +export const ME_FETCH_SUCCESS = 'ME_FETCH_SUCCESS'; +export const ME_FETCH_FAIL = 'ME_FETCH_FAIL'; + +export function fetchMe() { + return (dispatch, getState) => { + dispatch(fetchMeRequest()); + api(getState).get(`/api/v1/accounts/verify_credentials`).then(response => { + dispatch(fetchMeSuccess(response.data)); + dispatch(importFetchedAccount(response.data)); + }).catch(error => { + dispatch(fetchMeFail(error)); + }); + }; +} + +export function fetchMeRequest() { + return { + type: ME_FETCH_REQUEST, + }; +} + +export function fetchMeSuccess(me) { + return { + type: ME_FETCH_SUCCESS, + me + }; +} + +export function fetchMeFail(error) { + return { + type: ME_FETCH_FAIL, + error, + skipAlert: true, + }; +}; diff --git a/app/gabsocial/actions/mutes.js b/app/gabsocial/actions/mutes.js index 4e2ae15d3..00d791197 100644 --- a/app/gabsocial/actions/mutes.js +++ b/app/gabsocial/actions/mutes.js @@ -2,7 +2,6 @@ import api, { getLinks } from '../api'; import { fetchRelationships } from './accounts'; import { importFetchedAccounts } from './importer'; import { openModal } from './modal'; -import { me } from 'gabsocial/initial_state'; export const MUTES_FETCH_REQUEST = 'MUTES_FETCH_REQUEST'; export const MUTES_FETCH_SUCCESS = 'MUTES_FETCH_SUCCESS'; @@ -17,7 +16,7 @@ export const MUTES_TOGGLE_HIDE_NOTIFICATIONS = 'MUTES_TOGGLE_HIDE_NOTIFICATIONS' export function fetchMutes() { return (dispatch, getState) => { - if (!me) return; + if (!getState().get('me')) return; dispatch(fetchMutesRequest()); @@ -53,8 +52,8 @@ export function fetchMutesFail(error) { export function expandMutes() { return (dispatch, getState) => { - if (!me) return; - + if (!getState().get('me')) return; + const url = getState().getIn(['user_lists', 'mutes', 'next']); if (url === null) { diff --git a/app/gabsocial/actions/notifications.js b/app/gabsocial/actions/notifications.js index 5d44ed224..2f4a234d1 100644 --- a/app/gabsocial/actions/notifications.js +++ b/app/gabsocial/actions/notifications.js @@ -13,7 +13,6 @@ import { defineMessages } from 'react-intl'; import { List as ImmutableList } from 'immutable'; import { unescapeHTML } from '../utils/html'; import { getFilters, regexFromFilters } from '../selectors'; -import { me } from 'gabsocial/initial_state'; export const NOTIFICATIONS_INITIALIZE = 'NOTIFICATIONS_INITIALIZE'; export const NOTIFICATIONS_UPDATE = 'NOTIFICATIONS_UPDATE'; @@ -158,7 +157,7 @@ const noOp = () => {}; export function expandNotifications({ maxId } = {}, done = noOp) { return (dispatch, getState) => { - if (!me) return; + if (!getState().get('me')) return; const activeFilter = getState().getIn(['settings', 'notifications', 'quickFilter', 'active']); const notifications = getState().get('notifications'); @@ -224,7 +223,7 @@ export function expandNotificationsFail(error, isLoadingMore) { export function clearNotifications() { return (dispatch, getState) => { - if (!me) return; + if (!getState().get('me')) return; dispatch({ type: NOTIFICATIONS_CLEAR, @@ -258,7 +257,7 @@ export function setFilter (filterType) { export function markReadNotifications() { return (dispatch, getState) => { - if (!me) return; + if (!getState().get('me')) return; const top_notification = parseInt(getState().getIn(['notifications', 'items', 0, 'id'])); const last_read = getState().getIn(['notifications', 'lastRead']); diff --git a/app/gabsocial/actions/pin_statuses.js b/app/gabsocial/actions/pin_statuses.js index 79a5d8140..0a4a320c1 100644 --- a/app/gabsocial/actions/pin_statuses.js +++ b/app/gabsocial/actions/pin_statuses.js @@ -1,6 +1,5 @@ import api from '../api'; import { importFetchedStatuses } from './importer'; -import { me } from 'gabsocial/initial_state'; export const PINNED_STATUSES_FETCH_REQUEST = 'PINNED_STATUSES_FETCH_REQUEST'; export const PINNED_STATUSES_FETCH_SUCCESS = 'PINNED_STATUSES_FETCH_SUCCESS'; @@ -8,6 +7,7 @@ export const PINNED_STATUSES_FETCH_FAIL = 'PINNED_STATUSES_FETCH_FAIL'; export function fetchPinnedStatuses() { return (dispatch, getState) => { + const me = getState().get('me'); if (!me) return; dispatch(fetchPinnedStatusesRequest()); diff --git a/app/gabsocial/actions/push_notifications/registerer.js b/app/gabsocial/actions/push_notifications/registerer.js index b0f42b6a2..875c9c187 100644 --- a/app/gabsocial/actions/push_notifications/registerer.js +++ b/app/gabsocial/actions/push_notifications/registerer.js @@ -2,7 +2,6 @@ import api from '../../api'; import { decode as decodeBase64 } from '../../utils/base64'; import { pushNotificationsSetting } from '../../settings'; import { setBrowserSupport, setSubscription, clearSubscription } from './setter'; -import { me } from '../../initial_state'; // Taken from https://www.npmjs.com/package/web-push const urlBase64ToUint8Array = (base64String) => { @@ -31,7 +30,7 @@ const subscribe = (registration) => const unsubscribe = ({ registration, subscription }) => subscription ? subscription.unsubscribe().then(() => registration) : registration; -const sendSubscriptionToBackend = (subscription) => { +const sendSubscriptionToBackend = (subscription, me) => { const params = { subscription }; if (me) { @@ -49,6 +48,7 @@ const supportsPushNotifications = ('serviceWorker' in navigator && 'PushManager' export function register () { return (dispatch, getState) => { + const me = getState().get('me'); dispatch(setBrowserSupport(supportsPushNotifications)); if (supportsPushNotifications) { @@ -73,13 +73,13 @@ export function register () { } else { // Something went wrong, try to subscribe again return unsubscribe({ registration, subscription }).then(subscribe).then( - subscription => sendSubscriptionToBackend(subscription)); + subscription => sendSubscriptionToBackend(subscription, me)); } } // No subscription, try to subscribe return subscribe(registration).then( - subscription => sendSubscriptionToBackend(subscription)); + subscription => sendSubscriptionToBackend(subscription, me)); }) .then(subscription => { // If we got a PushSubscription (and not a subscription object from the backend) @@ -121,6 +121,7 @@ export function saveSettings() { const subscription = state.get('subscription'); const alerts = state.get('alerts'); const data = { alerts }; + const me = getState().get('me'); api().put(`/api/web/push_subscriptions/${subscription.get('id')}`, { data, diff --git a/app/gabsocial/actions/settings.js b/app/gabsocial/actions/settings.js index 0ca8bc126..bfda2ddd1 100644 --- a/app/gabsocial/actions/settings.js +++ b/app/gabsocial/actions/settings.js @@ -1,7 +1,6 @@ import api from '../api'; import { debounce } from 'lodash'; import { showAlertForError } from './alerts'; -import { me } from 'gabsocial/initial_state'; export const SETTING_CHANGE = 'SETTING_CHANGE'; export const SETTING_SAVE = 'SETTING_SAVE'; @@ -19,7 +18,7 @@ export function changeSetting(path, value) { }; const debouncedSave = debounce((dispatch, getState) => { - if (!me) return; + if (!getState().get('me')) return; if (getState().getIn(['settings', 'saved'])) { return; diff --git a/app/gabsocial/actions/statuses.js b/app/gabsocial/actions/statuses.js index 69261f41b..d73e1724b 100644 --- a/app/gabsocial/actions/statuses.js +++ b/app/gabsocial/actions/statuses.js @@ -5,7 +5,6 @@ import { deleteFromTimelines } from './timelines'; import { importFetchedStatus, importFetchedStatuses, importAccount, importStatus } from './importer'; import { ensureComposeIsVisible } from './compose'; import { openModal, closeModal } from './modal'; -import { me } from 'gabsocial/initial_state'; export const STATUS_FETCH_REQUEST = 'STATUS_FETCH_REQUEST'; export const STATUS_FETCH_SUCCESS = 'STATUS_FETCH_SUCCESS'; @@ -143,7 +142,7 @@ export function redraft(status, raw_text) { export function deleteStatus(id, routerHistory, withRedraft = false) { return (dispatch, getState) => { - if (!me) return; + if (!getState().get('me')) return; let status = getState().getIn(['statuses', id]); @@ -236,7 +235,7 @@ export function fetchContextFail(id, error) { export function muteStatus(id) { return (dispatch, getState) => { - if (!me) return; + if (!getState().get('me')) return; dispatch(muteStatusRequest(id)); @@ -272,7 +271,7 @@ export function muteStatusFail(id, error) { export function unmuteStatus(id) { return (dispatch, getState) => { - if (!me) return; + if (!getState().get('me')) return; dispatch(unmuteStatusRequest(id)); diff --git a/app/gabsocial/actions/suggestions.js b/app/gabsocial/actions/suggestions.js index 5394fd81c..d84bb758f 100644 --- a/app/gabsocial/actions/suggestions.js +++ b/app/gabsocial/actions/suggestions.js @@ -1,6 +1,5 @@ import api from '../api'; import { importFetchedAccounts } from './importer'; -import { me } from 'gabsocial/initial_state'; export const SUGGESTIONS_FETCH_REQUEST = 'SUGGESTIONS_FETCH_REQUEST'; export const SUGGESTIONS_FETCH_SUCCESS = 'SUGGESTIONS_FETCH_SUCCESS'; @@ -44,7 +43,7 @@ export function fetchSuggestionsFail(error) { }; export const dismissSuggestion = accountId => (dispatch, getState) => { - if (!me) return; + if (!getState().get('me')) return; dispatch({ type: SUGGESTIONS_DISMISS, diff --git a/app/gabsocial/components/account.js b/app/gabsocial/components/account.js index 797e44ea1..0c686f711 100644 --- a/app/gabsocial/components/account.js +++ b/app/gabsocial/components/account.js @@ -1,4 +1,5 @@ import React, { Fragment } from 'react'; +import { connect } from 'react-redux'; import ImmutablePropTypes from 'react-immutable-proptypes'; import PropTypes from 'prop-types'; import { FormattedMessage } from 'react-intl'; @@ -8,7 +9,6 @@ import Permalink from './permalink'; import IconButton from './icon_button'; import { defineMessages, injectIntl } from 'react-intl'; import ImmutablePureComponent from 'react-immutable-pure-component'; -import { me } from '../initial_state'; const messages = defineMessages({ follow: { id: 'account.follow', defaultMessage: 'Follow' }, @@ -20,7 +20,14 @@ const messages = defineMessages({ unmute_notifications: { id: 'account.unmute_notifications', defaultMessage: 'Unmute notifications from @{name}' }, }); -export default @injectIntl +const mapStateToProps = state => { + return { + me: state.get('me'), + }; +}; + +export default @connect(mapStateToProps) +@injectIntl class Account extends ImmutablePureComponent { static propTypes = { @@ -61,7 +68,7 @@ class Account extends ImmutablePureComponent { } render () { - const { account, intl, hidden, onActionClick, actionIcon, actionTitle } = this.props; + const { account, intl, hidden, onActionClick, actionIcon, actionTitle, me } = this.props; if (!account) { return
; diff --git a/app/gabsocial/components/avatar.js b/app/gabsocial/components/avatar.js index 3e08c7fe7..07a74760b 100644 --- a/app/gabsocial/components/avatar.js +++ b/app/gabsocial/components/avatar.js @@ -34,6 +34,7 @@ export default class Avatar extends React.PureComponent { render () { const { account, size, animate, inline } = this.props; + if (!account) return null; const { hovering } = this.state; const src = account.get('avatar'); diff --git a/app/gabsocial/components/home_column_header.js b/app/gabsocial/components/home_column_header.js index fe080c9ee..595559f3a 100644 --- a/app/gabsocial/components/home_column_header.js +++ b/app/gabsocial/components/home_column_header.js @@ -8,7 +8,6 @@ import classNames from 'classnames'; import { FormattedMessage, injectIntl, defineMessages } from 'react-intl'; import { Link } from 'react-router-dom'; import Icon from 'gabsocial/components/icon'; -import { me } from 'gabsocial/initial_state'; import { fetchLists } from 'gabsocial/actions/lists'; import { createSelector } from 'reselect'; diff --git a/app/gabsocial/components/sidebar_menu.js b/app/gabsocial/components/sidebar_menu.js index 131a9e158..70637d312 100644 --- a/app/gabsocial/components/sidebar_menu.js +++ b/app/gabsocial/components/sidebar_menu.js @@ -12,7 +12,6 @@ import Icon from './icon'; import DisplayName from './display_name'; import { closeSidebar } from '../actions/sidebar'; import { shortNumberFormat } from '../utils/numbers'; -import { me, funding } from '../initial_state'; import { makeGetAccount } from '../selectors'; const messages = defineMessages({ @@ -34,6 +33,7 @@ const messages = defineMessages({ }) const mapStateToProps = state => { + const me = state.get('me'); const getAccount = makeGetAccount(); return { @@ -61,6 +61,7 @@ class SidebarMenu extends ImmutablePureComponent { render () { const { sidebarOpen, onClose, intl, account } = this.props; + if (!account) return null; const acct = account.get('acct'); const classes = classNames('sidebar-menu__root', { diff --git a/app/gabsocial/components/status_action_bar.js b/app/gabsocial/components/status_action_bar.js index 7a62091ab..28e8434d6 100644 --- a/app/gabsocial/components/status_action_bar.js +++ b/app/gabsocial/components/status_action_bar.js @@ -7,7 +7,7 @@ import IconButton from './icon_button'; import DropdownMenuContainer from '../containers/dropdown_menu_container'; import { defineMessages, injectIntl } from 'react-intl'; import ImmutablePureComponent from 'react-immutable-pure-component'; -import { me, isStaff } from '../initial_state'; +import { isStaff } from '../initial_state'; import { openModal } from '../actions/modal'; import { Link } from 'react-router-dom'; @@ -75,6 +75,7 @@ class StatusActionBar extends ImmutablePureComponent { ] handleReplyClick = () => { + const { me } = this.props; if (me) { this.props.onReply(this.props.status, this.context.router.history); } else { @@ -92,6 +93,7 @@ class StatusActionBar extends ImmutablePureComponent { } handleFavouriteClick = () => { + const { me } = this.props; if (me) { this.props.onFavourite(this.props.status); } else { @@ -100,6 +102,7 @@ class StatusActionBar extends ImmutablePureComponent { } handleReblogClick = e => { + const { me } = this.props; if (me) { this.props.onReblog(this.props.status, e); } else { @@ -183,7 +186,7 @@ class StatusActionBar extends ImmutablePureComponent { } _makeMenu = (publicStatus) => { - const { status, intl, withDismiss, withGroupAdmin } = this.props; + const { status, intl, withDismiss, withGroupAdmin, me } = this.props; const mutingConversation = status.get('muted'); let menu = []; @@ -297,6 +300,12 @@ class StatusActionBar extends ImmutablePureComponent { } } +const mapStateToProps = state => { + return { + me: state.get('me'), + }; +}; + const mapDispatchToProps = (dispatch) => ({ onOpenUnauthorizedModal() { dispatch(openModal('UNAUTHORIZED')); @@ -304,5 +313,5 @@ const mapDispatchToProps = (dispatch) => ({ }); export default injectIntl( - connect(null, mapDispatchToProps, null, { forwardRef: true } + connect(mapStateToProps, mapDispatchToProps, null, { forwardRef: true } )(StatusActionBar)) diff --git a/app/gabsocial/containers/gabsocial.js b/app/gabsocial/containers/gabsocial.js index ab99f0b80..424295956 100644 --- a/app/gabsocial/containers/gabsocial.js +++ b/app/gabsocial/containers/gabsocial.js @@ -15,10 +15,10 @@ import { connectUserStream } from '../actions/streaming'; import { IntlProvider, addLocaleData } from 'react-intl'; import { getLocale } from '../locales'; import initialState from '../initial_state'; -import { me } from '../initial_state'; import ErrorBoundary from '../components/error_boundary'; import { fetchInstance } from 'gabsocial/actions/instance'; import { fetchSoapboxConfig } from 'gabsocial/actions/soapbox'; +import { fetchMe } from 'gabsocial/actions/me'; const { localeData, messages } = getLocale(); addLocaleData(localeData); @@ -27,11 +27,13 @@ export const store = configureStore(); const hydrateAction = hydrateStore(initialState); store.dispatch(hydrateAction); +store.dispatch(fetchMe()); store.dispatch(fetchInstance()); store.dispatch(fetchSoapboxConfig()); store.dispatch(fetchCustomEmojis()); const mapStateToProps = (state) => { + const me = state.get('me'); const account = state.getIn(['accounts', me]); const showIntroduction = account ? state.getIn(['settings', 'introductionVersion'], 0) < INTRODUCTION_VERSION : false; diff --git a/app/gabsocial/features/account/components/header.js b/app/gabsocial/features/account/components/header.js index 16b731408..295fea5b0 100644 --- a/app/gabsocial/features/account/components/header.js +++ b/app/gabsocial/features/account/components/header.js @@ -1,12 +1,13 @@ 'use strict'; import React from 'react'; +import { connect } from 'react-redux'; import ImmutablePropTypes from 'react-immutable-proptypes'; import PropTypes from 'prop-types'; import { defineMessages, injectIntl, FormattedMessage } from 'react-intl'; import Button from 'gabsocial/components/button'; import ImmutablePureComponent from 'react-immutable-pure-component'; -import { autoPlayGif, me, isStaff } from 'gabsocial/initial_state'; +import { autoPlayGif, isStaff } from 'gabsocial/initial_state'; import classNames from 'classnames'; import Icon from 'gabsocial/components/icon'; import Avatar from 'gabsocial/components/avatar'; @@ -56,7 +57,14 @@ const dateFormatOptions = { minute: '2-digit', }; -export default @injectIntl +const mapStateToProps = state => { + return { + me: state.get('me'), + }; +}; + +export default @connect(mapStateToProps) +@injectIntl class Header extends ImmutablePureComponent { static propTypes = { @@ -100,7 +108,7 @@ class Header extends ImmutablePureComponent { }); makeMenu() { - const { account, intl, domain } = this.props; + const { account, intl, domain, me } = this.props; let menu = []; @@ -172,7 +180,7 @@ class Header extends ImmutablePureComponent { } makeInfo() { - const { account, intl } = this.props; + const { account, intl, me } = this.props; let info = []; @@ -194,7 +202,7 @@ class Header extends ImmutablePureComponent { }; getActionBtn() { - const { account, intl } = this.props; + const { account, intl, me } = this.props; let actionBtn = null; @@ -216,7 +224,7 @@ class Header extends ImmutablePureComponent { }; render () { - const { account, intl, domain, username } = this.props; + const { account, intl, domain, username, me } = this.props; const { isSmallScreen } = this.state; if (!account) { diff --git a/app/gabsocial/features/account_gallery/index.js b/app/gabsocial/features/account_gallery/index.js index fa88050b8..08993252d 100644 --- a/app/gabsocial/features/account_gallery/index.js +++ b/app/gabsocial/features/account_gallery/index.js @@ -17,9 +17,9 @@ import MissingIndicator from 'gabsocial/components/missing_indicator'; import { openModal } from 'gabsocial/actions/modal'; import { NavLink } from 'react-router-dom'; import { FormattedMessage } from 'react-intl'; -import { me } from 'gabsocial/initial_state'; const mapStateToProps = (state, { params: { username }, withReplies = false }) => { + const me = state.get('me'); const accounts = state.getIn(['accounts']); const accountFetchError = (state.getIn(['accounts', -1, 'username'], '').toLowerCase() == username.toLowerCase()); diff --git a/app/gabsocial/features/account_timeline/index.js b/app/gabsocial/features/account_timeline/index.js index 61896a569..ba05ec511 100644 --- a/app/gabsocial/features/account_timeline/index.js +++ b/app/gabsocial/features/account_timeline/index.js @@ -13,11 +13,11 @@ import { FormattedMessage } from 'react-intl'; import { fetchAccountIdentityProofs } from '../../actions/identity_proofs'; import MissingIndicator from 'gabsocial/components/missing_indicator'; import { NavLink } from 'react-router-dom'; -import { me } from 'gabsocial/initial_state'; const emptyList = ImmutableList(); const mapStateToProps = (state, { params: { username }, withReplies = false }) => { + const me = state.get('me'); const accounts = state.getIn(['accounts']); const accountFetchError = (state.getIn(['accounts', -1, 'username'], '').toLowerCase() == username.toLowerCase()); diff --git a/app/gabsocial/features/compose/containers/navigation_container.js b/app/gabsocial/features/compose/containers/navigation_container.js index eb9f3ea45..31a9b4285 100644 --- a/app/gabsocial/features/compose/containers/navigation_container.js +++ b/app/gabsocial/features/compose/containers/navigation_container.js @@ -1,8 +1,8 @@ import { connect } from 'react-redux'; import NavigationBar from '../components/navigation_bar'; -import { me } from '../../../initial_state'; const mapStateToProps = state => { + const me = state.get('me'); return { account: state.getIn(['accounts', me]), }; diff --git a/app/gabsocial/features/compose/containers/warning_container.js b/app/gabsocial/features/compose/containers/warning_container.js index 1f6d90fc8..ae0e3ef30 100644 --- a/app/gabsocial/features/compose/containers/warning_container.js +++ b/app/gabsocial/features/compose/containers/warning_container.js @@ -3,15 +3,17 @@ import { connect } from 'react-redux'; import Warning from '../components/warning'; import PropTypes from 'prop-types'; import { FormattedMessage } from 'react-intl'; -import { me } from '../../../initial_state'; const APPROX_HASHTAG_RE = /(?:^|[^\/\)\w])#(\w*[a-zA-Z·]\w*)/i; -const mapStateToProps = state => ({ - needsLockWarning: state.getIn(['compose', 'privacy']) === 'private' && !state.getIn(['accounts', me, 'locked']), - hashtagWarning: state.getIn(['compose', 'privacy']) !== 'public' && APPROX_HASHTAG_RE.test(state.getIn(['compose', 'text'])), - directMessageWarning: state.getIn(['compose', 'privacy']) === 'direct', -}); +const mapStateToProps = state => { + const me = state.get('me'); + return { + needsLockWarning: state.getIn(['compose', 'privacy']) === 'private' && !state.getIn(['accounts', me, 'locked']), + hashtagWarning: state.getIn(['compose', 'privacy']) !== 'public' && APPROX_HASHTAG_RE.test(state.getIn(['compose', 'text'])), + directMessageWarning: state.getIn(['compose', 'privacy']) === 'direct', + } +}; const WarningWrapper = ({ needsLockWarning, hashtagWarning, directMessageWarning }) => { if (needsLockWarning) { diff --git a/app/gabsocial/features/followers/index.js b/app/gabsocial/features/followers/index.js index 57b20ffeb..9b04cf001 100644 --- a/app/gabsocial/features/followers/index.js +++ b/app/gabsocial/features/followers/index.js @@ -16,9 +16,9 @@ import AccountContainer from '../../containers/account_container'; import Column from '../ui/components/column'; import ScrollableList from '../../components/scrollable_list'; import MissingIndicator from 'gabsocial/components/missing_indicator'; -import { me } from 'gabsocial/initial_state'; const mapStateToProps = (state, { params: { username }, withReplies = false }) => { + const me = state.get('me'); const accounts = state.getIn(['accounts']); const accountFetchError = (state.getIn(['accounts', -1, 'username'], '').toLowerCase() == username.toLowerCase()); diff --git a/app/gabsocial/features/following/index.js b/app/gabsocial/features/following/index.js index 16681535a..cf8aa4c3d 100644 --- a/app/gabsocial/features/following/index.js +++ b/app/gabsocial/features/following/index.js @@ -17,9 +17,9 @@ import Column from '../ui/components/column'; import HeaderContainer from '../account_timeline/containers/header_container'; import ScrollableList from '../../components/scrollable_list'; import MissingIndicator from 'gabsocial/components/missing_indicator'; -import { me } from 'gabsocial/initial_state'; const mapStateToProps = (state, { params: { username }, withReplies = false }) => { + const me = state.get('me'); const accounts = state.getIn(['accounts']); const accountFetchError = (state.getIn(['accounts', -1, 'username'], '').toLowerCase() == username.toLowerCase()); diff --git a/app/gabsocial/features/getting_started/index.js b/app/gabsocial/features/getting_started/index.js index e34cb317b..acfbee4ba 100644 --- a/app/gabsocial/features/getting_started/index.js +++ b/app/gabsocial/features/getting_started/index.js @@ -7,7 +7,7 @@ import { connect } from 'react-redux'; import PropTypes from 'prop-types'; import ImmutablePropTypes from 'react-immutable-proptypes'; import ImmutablePureComponent from 'react-immutable-pure-component'; -import { me, profile_directory } from '../../initial_state'; +import { profile_directory } from '../../initial_state'; import { fetchFollowRequests } from 'gabsocial/actions/accounts'; import { List as ImmutableList } from 'immutable'; import NavigationBar from '../compose/components/navigation_bar'; @@ -34,10 +34,13 @@ const messages = defineMessages({ profile_directory: { id: 'getting_started.directory', defaultMessage: 'Profile directory' }, }); -const mapStateToProps = state => ({ - myAccount: state.getIn(['accounts', me]), - unreadFollowRequests: state.getIn(['user_lists', 'follow_requests', 'items'], ImmutableList()).size, -}); +const mapStateToProps = state => { + const me = state.get('me'); + return { + myAccount: state.getIn(['accounts', me]), + unreadFollowRequests: state.getIn(['user_lists', 'follow_requests', 'items'], ImmutableList()).size, + } +}; const mapDispatchToProps = dispatch => ({ fetchFollowRequests: () => dispatch(fetchFollowRequests()), diff --git a/app/gabsocial/features/groups/timeline/index.js b/app/gabsocial/features/groups/timeline/index.js index 2d23853e5..8aed8bb2f 100644 --- a/app/gabsocial/features/groups/timeline/index.js +++ b/app/gabsocial/features/groups/timeline/index.js @@ -10,15 +10,17 @@ import { expandGroupTimeline } from '../../../actions/timelines'; import MissingIndicator from '../../../components/missing_indicator'; import LoadingIndicator from '../../../components/loading_indicator'; import ComposeFormContainer from '../../../../gabsocial/features/compose/containers/compose_form_container'; -import { me } from 'gabsocial/initial_state'; import Avatar from '../../../components/avatar'; -const mapStateToProps = (state, props) => ({ - account: state.getIn(['accounts', me]), - group: state.getIn(['groups', props.params.id]), - relationships: state.getIn(['group_relationships', props.params.id]), - hasUnread: state.getIn(['timelines', `group:${props.params.id}`, 'unread']) > 0, -}); +const mapStateToProps = (state, props) => { + const me = state.get('me'); + return { + account: state.getIn(['accounts', me]), + group: state.getIn(['groups', props.params.id]), + relationships: state.getIn(['group_relationships', props.params.id]), + hasUnread: state.getIn(['timelines', `group:${props.params.id}`, 'unread']) > 0, + } +}; export default @connect(mapStateToProps) @injectIntl diff --git a/app/gabsocial/features/status/components/action_bar.js b/app/gabsocial/features/status/components/action_bar.js index 128159bc6..f2b8433cc 100644 --- a/app/gabsocial/features/status/components/action_bar.js +++ b/app/gabsocial/features/status/components/action_bar.js @@ -6,7 +6,7 @@ import IconButton from '../../../components/icon_button'; import ImmutablePropTypes from 'react-immutable-proptypes'; import DropdownMenuContainer from '../../../containers/dropdown_menu_container'; import { defineMessages, injectIntl } from 'react-intl'; -import { me, isStaff } from '../../../initial_state'; +import { isStaff } from '../../../initial_state'; const messages = defineMessages({ delete: { id: 'status.delete', defaultMessage: 'Delete' }, @@ -33,6 +33,12 @@ const messages = defineMessages({ copy: { id: 'status.copy', defaultMessage: 'Copy link to post' }, }); +const mapStateToProps = state => { + return { + me: state.get('me'), + }; +}; + const mapDispatchToProps = (dispatch) => ({ onOpenUnauthorizedModal() { dispatch(openModal('UNAUTHORIZED')); @@ -64,6 +70,7 @@ class ActionBar extends React.PureComponent { }; handleReplyClick = () => { + const { me } = this.props; if (me) { this.props.onReply(this.props.status); } else { @@ -72,6 +79,7 @@ class ActionBar extends React.PureComponent { } handleReblogClick = (e) => { + const { me } = this.props; if (me) { this.props.onReblog(this.props.status, e); } else { @@ -80,6 +88,7 @@ class ActionBar extends React.PureComponent { } handleFavouriteClick = () => { + const { me } = this.props; if (me) { this.props.onFavourite(this.props.status); } else { @@ -154,7 +163,7 @@ class ActionBar extends React.PureComponent { } render () { - const { status, intl } = this.props; + const { status, intl, me } = this.props; const publicStatus = ['public', 'unlisted'].includes(status.get('visibility')); const mutingConversation = status.get('muted'); @@ -227,4 +236,4 @@ class ActionBar extends React.PureComponent { } } -export default injectIntl(connect(null, mapDispatchToProps)(ActionBar)); +export default injectIntl(connect(mapStateToProps, mapDispatchToProps)(ActionBar)); diff --git a/app/gabsocial/features/status/index.js b/app/gabsocial/features/status/index.js index 20fc94490..471c5e869 100644 --- a/app/gabsocial/features/status/index.js +++ b/app/gabsocial/features/status/index.js @@ -39,7 +39,7 @@ import { openModal } from '../../actions/modal'; import { defineMessages, injectIntl, FormattedMessage } from 'react-intl'; import ImmutablePureComponent from 'react-immutable-pure-component'; import { HotKeys } from 'react-hotkeys'; -import { boostModal, deleteModal, me } from '../../initial_state'; +import { boostModal, deleteModal } from '../../initial_state'; import { attachFullscreenListener, detachFullscreenListener, isFullscreen } from '../ui/util/fullscreen'; import { textForScreenReader, defaultMediaVisibility } from '../../components/status'; import Icon from 'gabsocial/components/icon'; @@ -106,6 +106,7 @@ const makeMapStateToProps = () => { descendantsIds, askReplyConfirmation: state.getIn(['compose', 'text']).trim().length !== 0, domain: state.getIn(['meta', 'domain']), + me: state.get('me'), }; }; @@ -419,7 +420,7 @@ class Status extends ImmutablePureComponent { render () { let ancestors, descendants; - const { status, ancestorsIds, descendantsIds, intl, domain } = this.props; + const { status, ancestorsIds, descendantsIds, intl, domain, me } = this.props; const { fullscreen } = this.state; if (status === null) { diff --git a/app/gabsocial/features/ui/components/compose_modal.js b/app/gabsocial/features/ui/components/compose_modal.js index aa5c96d91..369afa3db 100644 --- a/app/gabsocial/features/ui/components/compose_modal.js +++ b/app/gabsocial/features/ui/components/compose_modal.js @@ -2,7 +2,6 @@ import React from 'react'; import PropTypes from 'prop-types'; import ImmutablePropTypes from 'react-immutable-proptypes'; import { connect } from 'react-redux'; -import { me } from '../../../initial_state'; import { defineMessages, injectIntl, FormattedMessage } from 'react-intl'; import ImmutablePureComponent from 'react-immutable-pure-component'; import ComposeFormContainer from '../../compose/containers/compose_form_container'; @@ -16,6 +15,7 @@ const messages = defineMessages({ }); const mapStateToProps = state => { + const me = state.get('me'); return { account: state.getIn(['accounts', me]), composeText: state.getIn(['compose', 'text']), diff --git a/app/gabsocial/features/ui/components/follow_requests_nav_link.js b/app/gabsocial/features/ui/components/follow_requests_nav_link.js index f447660f4..2639e7122 100644 --- a/app/gabsocial/features/ui/components/follow_requests_nav_link.js +++ b/app/gabsocial/features/ui/components/follow_requests_nav_link.js @@ -4,14 +4,16 @@ import { fetchFollowRequests } from 'gabsocial/actions/accounts'; import { connect } from 'react-redux'; import { NavLink, withRouter } from 'react-router-dom'; import IconWithBadge from 'gabsocial/components/icon_with_badge'; -import { me } from 'gabsocial/initial_state'; import { List as ImmutableList } from 'immutable'; import { FormattedMessage } from 'react-intl'; -const mapStateToProps = state => ({ - locked: state.getIn(['accounts', me, 'locked']), - count: state.getIn(['user_lists', 'follow_requests', 'items'], ImmutableList()).size, -}); +const mapStateToProps = state => { + const me = state.get('me'); + return { + locked: state.getIn(['accounts', me, 'locked']), + count: state.getIn(['user_lists', 'follow_requests', 'items'], ImmutableList()).size, + } +}; export default @withRouter @connect(mapStateToProps) diff --git a/app/gabsocial/features/ui/components/link_footer.js b/app/gabsocial/features/ui/components/link_footer.js index 324b2dde5..65b22971b 100644 --- a/app/gabsocial/features/ui/components/link_footer.js +++ b/app/gabsocial/features/ui/components/link_footer.js @@ -2,14 +2,17 @@ import React from 'react'; import PropTypes from 'prop-types'; import { FormattedMessage, injectIntl } from 'react-intl'; import { Link } from 'react-router-dom'; -import { invitesEnabled, version, repository, source_url, me } from 'gabsocial/initial_state'; +import { invitesEnabled, version, repository, source_url } from 'gabsocial/initial_state'; import { connect } from 'react-redux'; import { openModal } from '../../../actions/modal'; -const mapStateToProps = state => ({ - account: state.getIn(['accounts', me]), - siteTitle: state.getIn(['instance', 'title']), -}); +const mapStateToProps = state => { + const me = state.get('me'); + return { + account: state.getIn(['accounts', me]), + siteTitle: state.getIn(['instance', 'title']), + } +}; const mapDispatchToProps = (dispatch) => ({ onOpenHotkeys() { diff --git a/app/gabsocial/features/ui/components/promo_panel.js b/app/gabsocial/features/ui/components/promo_panel.js index ce19f33ee..b33d4294c 100644 --- a/app/gabsocial/features/ui/components/promo_panel.js +++ b/app/gabsocial/features/ui/components/promo_panel.js @@ -4,7 +4,7 @@ import { FormattedMessage } from 'react-intl'; import Icon from 'gabsocial/components/icon'; import ProBadge from 'gabsocial/components/pro_badge'; import { connect } from 'react-redux'; -import { me, promoItems } from '../../../initial_state'; +import { promoItems } from '../../../initial_state'; export default class PromoPanel extends React.PureComponent { diff --git a/app/gabsocial/features/ui/components/sign_up_panel.js b/app/gabsocial/features/ui/components/sign_up_panel.js index e2d47126d..b28010f4c 100644 --- a/app/gabsocial/features/ui/components/sign_up_panel.js +++ b/app/gabsocial/features/ui/components/sign_up_panel.js @@ -2,15 +2,15 @@ import React from 'react'; import { connect } from 'react-redux'; import { FormattedMessage, injectIntl } from 'react-intl'; import { NavLink } from 'react-router-dom'; -import { me } from 'gabsocial/initial_state'; const mapStateToProps = state => { return { siteTitle: state.getIn(['instance', 'title']), + me: state.get('me'), }; }; -const SignUpPanel = ({ siteTitle }) => { +const SignUpPanel = ({ siteTitle, me }) => { if (me) return null; return ( diff --git a/app/gabsocial/features/ui/components/tabs_bar.js b/app/gabsocial/features/ui/components/tabs_bar.js index 893e6488d..a088b9c8a 100644 --- a/app/gabsocial/features/ui/components/tabs_bar.js +++ b/app/gabsocial/features/ui/components/tabs_bar.js @@ -4,7 +4,6 @@ import { NavLink, withRouter } from 'react-router-dom'; import { FormattedMessage, injectIntl } from 'react-intl'; import { throttle } from 'lodash'; import { connect } from 'react-redux'; -import { me } from '../../../initial_state'; import classNames from 'classnames'; import NotificationsCounterIcon from './notifications_counter_icon'; import SearchContainer from 'gabsocial/features/compose/containers/search_container'; @@ -190,6 +189,7 @@ class TabsBar extends React.PureComponent { } const mapStateToProps = state => { + const me = state.get('me'); return { account: state.getIn(['accounts', me]), logo: state.getIn(['soapbox', 'logo']), diff --git a/app/gabsocial/features/ui/components/unauthorized_modal.js b/app/gabsocial/features/ui/components/unauthorized_modal.js index 0e0bba2a5..2b9f8e4f4 100644 --- a/app/gabsocial/features/ui/components/unauthorized_modal.js +++ b/app/gabsocial/features/ui/components/unauthorized_modal.js @@ -2,7 +2,6 @@ import React from 'react'; import PropTypes from 'prop-types'; import ImmutablePropTypes from 'react-immutable-proptypes'; import { connect } from 'react-redux'; -import { me } from '../../../initial_state'; import { defineMessages, injectIntl, FormattedMessage } from 'react-intl'; import Avatar from '../../../components/avatar'; import ImmutablePureComponent from 'react-immutable-pure-component'; @@ -13,6 +12,7 @@ const messages = defineMessages({ }); const mapStateToProps = state => { + const me = state.get('me'); return { account: state.getIn(['accounts', me]), siteTitle: state.getIn(['instance', 'title']), diff --git a/app/gabsocial/features/ui/components/user_panel.js b/app/gabsocial/features/ui/components/user_panel.js index 60832103a..7aa79019b 100644 --- a/app/gabsocial/features/ui/components/user_panel.js +++ b/app/gabsocial/features/ui/components/user_panel.js @@ -3,7 +3,7 @@ import PropTypes from 'prop-types'; import { connect } from 'react-redux'; import { Link } from 'react-router-dom'; import { injectIntl, FormattedMessage } from 'react-intl'; -import { autoPlayGif, me } from '../../../initial_state'; +import { autoPlayGif } from '../../../initial_state'; import { makeGetAccount } from '../../../selectors'; import ImmutablePropTypes from 'react-immutable-proptypes'; import ImmutablePureComponent from 'react-immutable-pure-component'; @@ -20,6 +20,7 @@ class UserPanel extends ImmutablePureComponent { render() { const { account, intl, domain } = this.props; + if (!account) return null; const displayNameHtml = { __html: account.get('display_name_html') }; const acct = account.get('acct').indexOf('@') === -1 && domain ? `${account.get('acct')}@${domain}` : account.get('acct'); @@ -83,6 +84,7 @@ class UserPanel extends ImmutablePureComponent { const mapStateToProps = state => { + const me = state.get('me'); const getAccount = makeGetAccount(); return { diff --git a/app/gabsocial/features/ui/containers/status_list_container.js b/app/gabsocial/features/ui/containers/status_list_container.js index f130f9f40..1e7421571 100644 --- a/app/gabsocial/features/ui/containers/status_list_container.js +++ b/app/gabsocial/features/ui/containers/status_list_container.js @@ -3,7 +3,6 @@ import StatusList from '../../../components/status_list'; import { Map as ImmutableMap, List as ImmutableList } from 'immutable'; import { createSelector } from 'reselect'; import { debounce } from 'lodash'; -import { me } from '../../../initial_state'; import { dequeueTimeline } from 'gabsocial/actions/timelines'; import { scrollTopTimeline } from '../../../actions/timelines'; @@ -11,7 +10,8 @@ const makeGetStatusIds = () => createSelector([ (state, { type }) => state.getIn(['settings', type], ImmutableMap()), (state, { type }) => state.getIn(['timelines', type, 'items'], ImmutableList()), (state) => state.get('statuses'), -], (columnSettings, statusIds, statuses) => { + (state) => state.get('me'), +], (columnSettings, statusIds, statuses, me) => { return statusIds.filter(id => { if (id === null) return true; diff --git a/app/gabsocial/features/ui/index.js b/app/gabsocial/features/ui/index.js index 920f3ef90..ab9c35dcc 100644 --- a/app/gabsocial/features/ui/index.js +++ b/app/gabsocial/features/ui/index.js @@ -65,7 +65,7 @@ import { GroupCreate, GroupEdit, } from './util/async-components'; -import { me, meUsername } from '../../initial_state'; +import { meUsername } from '../../initial_state'; import { previewState as previewMediaState } from './components/media_modal'; import { previewState as previewVideoState } from './components/video_modal'; @@ -79,12 +79,15 @@ const messages = defineMessages({ publish: { id: 'compose_form.publish', defaultMessage: 'Publish' }, }); -const mapStateToProps = state => ({ - isComposing: state.getIn(['compose', 'is_composing']), - hasComposingText: state.getIn(['compose', 'text']).trim().length !== 0, - hasMediaAttachments: state.getIn(['compose', 'media_attachments']).size > 0, - dropdownMenuIsOpen: state.getIn(['dropdown_menu', 'openId']) !== null, -}); +const mapStateToProps = state => { + return { + isComposing: state.getIn(['compose', 'is_composing']), + hasComposingText: state.getIn(['compose', 'text']).trim().length !== 0, + hasMediaAttachments: state.getIn(['compose', 'media_attachments']).size > 0, + dropdownMenuIsOpen: state.getIn(['dropdown_menu', 'openId']) !== null, + me: state.get('me'), + } +}; const keyMap = { help: '?', @@ -302,6 +305,7 @@ class UI extends React.PureComponent { } handleDrop = (e) => { + const { me } = this.props; if (!me) return; if (this.dataTransferIsText(e.dataTransfer)) return; @@ -345,6 +349,7 @@ class UI extends React.PureComponent { } componentWillMount () { + const { me } = this.props; window.addEventListener('beforeunload', this.handleBeforeUnload, false); document.addEventListener('dragenter', this.handleDragEnter, false); @@ -372,6 +377,7 @@ class UI extends React.PureComponent { } componentDidMount () { + const { me } = this.props; if (!me) return; this.hotkeys.__mousetrap__.stopCallback = (e, element) => { return ['TEXTAREA', 'SELECT', 'INPUT'].includes(element.tagName); @@ -492,7 +498,7 @@ class UI extends React.PureComponent { render () { const { draggingOver } = this.state; - const { intl, children, isComposing, location, dropdownMenuIsOpen } = this.props; + const { intl, children, isComposing, location, dropdownMenuIsOpen, me } = this.props; const handlers = me ? { help: this.handleHotkeyToggleHelp, diff --git a/app/gabsocial/features/ui/util/react_router_helpers.js b/app/gabsocial/features/ui/util/react_router_helpers.js index 042c182c4..9ee8d28f0 100644 --- a/app/gabsocial/features/ui/util/react_router_helpers.js +++ b/app/gabsocial/features/ui/util/react_router_helpers.js @@ -1,13 +1,19 @@ import React from 'react'; +import { connect } from 'react-redux'; import PropTypes from 'prop-types'; import { Redirect, Route } from 'react-router-dom'; import ColumnsAreaContainer from '../containers/columns_area_container'; import ColumnLoading from '../components/column_loading'; import BundleColumnError from '../components/bundle_column_error'; import BundleContainer from '../containers/bundle_container'; -import { me } from 'gabsocial/initial_state'; -export class WrappedRoute extends React.Component { +const mapStateToProps = state => { + return { + me: state.get('me'), + }; +}; + +class WrappedRoute extends React.Component { static propTypes = { component: PropTypes.func.isRequired, page: PropTypes.func, @@ -64,7 +70,7 @@ export class WrappedRoute extends React.Component { } render () { - const { component: Component, content, publicRoute, ...rest } = this.props; + const { component: Component, content, publicRoute, me, ...rest } = this.props; if (!publicRoute && !me) { const actualUrl = encodeURIComponent(this.props.computedMatch.url); @@ -77,3 +83,6 @@ export class WrappedRoute extends React.Component { return