diff --git a/src/components/notification/view/notificationView.js b/src/components/notification/view/notificationView.js index c3b16a0b9..38816f767 100644 --- a/src/components/notification/view/notificationView.js +++ b/src/components/notification/view/notificationView.js @@ -49,7 +49,7 @@ class NotificationView extends PureComponent { this.setState({ selectedFilter: filters[index].key, selectedIndex: index }); await changeSelectedFilter(filters[index].key, index); - getActivities(null, filters[index].key, false); + getActivities(filters[index].key, false); }; _renderList = (data) => { diff --git a/src/providers/ecency/ecency.ts b/src/providers/ecency/ecency.ts index 9209a0a8d..65e293401 100644 --- a/src/providers/ecency/ecency.ts +++ b/src/providers/ecency/ecency.ts @@ -337,49 +337,24 @@ export const getLeaderboard = async (duration:'day'|'week'|'month') => { } } -export const getActivities = (data) => - new Promise((resolve, reject) => { - let url = null; - switch (data.type) { - case 'activities': - url = `/activities/${data.user}`; - break; - case 'votes': - url = `/rvotes/${data.user}`; - break; - case 'replies': - url = `/replies/${data.user}`; - break; - case 'mentions': - url = `/mentions/${data.user}`; - break; - case 'follows': - url = `/follows/${data.user}`; - break; - case 'reblogs': - url = `/reblogs/${data.user}`; - break; - case 'transfers': - url = `/transfers/${data.user}`; - break; - default: - url = `/activities/${data.user}`; - break; +/** + * fetches notifications from ecency server using filter and since props + * @param data optional filter and since props; + * @returns array of notifications + */ +export const getNotifications = async (data:{ + filter?: "rvotes"|"mentions"|"follows"|"replies"|"reblogs"|"transfers", + since?:string + }) => { + try{ + const response = await ecencyApi.post(`/private-api/notifications`, data); + return response.data; + }catch(error){ + console.warn("Failed to get notifications", error) + bugsnag.notify(error) + throw error; } - api - .get(url, { - params: { - since: data.since, - }, - }) - .then((res) => { - resolve(res.data); - }) - .catch((error) => { - bugsnag.notify(error); - reject(error); - }); - }); + } export const getUnreadNotificationCount = async () => { diff --git a/src/screens/notification/container/notificationContainer.js b/src/screens/notification/container/notificationContainer.js index 67bc85076..cc3a35764 100644 --- a/src/screens/notification/container/notificationContainer.js +++ b/src/screens/notification/container/notificationContainer.js @@ -6,7 +6,7 @@ import get from 'lodash/get'; import { injectIntl } from 'react-intl'; // Actions and Services -import { getActivities, markActivityAsRead, markNotifications } from '../../../providers/ecency/ecency'; +import { getNotifications, markNotifications } from '../../../providers/ecency/ecency'; import { updateUnreadActivityCount } from '../../../redux/actions/accountAction'; // Constants @@ -29,21 +29,20 @@ class NotificationContainer extends Component { } componentDidMount() { - const { username, isConnected } = this.props; + const { isConnected } = this.props; - if (username && isConnected) { - this._getAvtivities(username); + if (isConnected) { + this._getAvtivities(); } } - _getAvtivities = (user, type = null, loadMore = false) => { + _getAvtivities = (type = null, loadMore = false) => { const { lastNotificationId, notifications, endOfNotification } = this.state; const since = loadMore ? lastNotificationId : null; - const { username } = this.props; if (!endOfNotification || !loadMore) { this.setState({ isNotificationRefreshing: true }); - getActivities({ user: user || username, type, since }) + getNotifications({ filter:type, since:since }) .then((res) => { console.log(res); const lastId = res.length > 0 ? [...res].pop().id : null; @@ -152,7 +151,7 @@ class NotificationContainer extends Component { (nextProps.username !== username && nextProps.username) ) { this.setState({ endOfNotification: false }, () => - this._getAvtivities(nextProps.username, selectedFilter), + this._getAvtivities(selectedFilter), ); } }