mirror of
https://github.com/ecency/ecency-mobile.git
synced 2024-12-19 19:31:54 +03:00
migrated get notifications endpoint
This commit is contained in:
parent
48b4bec41f
commit
8b9ef8b4a3
@ -49,7 +49,7 @@ class NotificationView extends PureComponent {
|
|||||||
|
|
||||||
this.setState({ selectedFilter: filters[index].key, selectedIndex: index });
|
this.setState({ selectedFilter: filters[index].key, selectedIndex: index });
|
||||||
await changeSelectedFilter(filters[index].key, index);
|
await changeSelectedFilter(filters[index].key, index);
|
||||||
getActivities(null, filters[index].key, false);
|
getActivities(filters[index].key, false);
|
||||||
};
|
};
|
||||||
|
|
||||||
_renderList = (data) => {
|
_renderList = (data) => {
|
||||||
|
@ -337,49 +337,24 @@ export const getLeaderboard = async (duration:'day'|'week'|'month') => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const getActivities = (data) =>
|
/**
|
||||||
new Promise((resolve, reject) => {
|
* fetches notifications from ecency server using filter and since props
|
||||||
let url = null;
|
* @param data optional filter and since props;
|
||||||
switch (data.type) {
|
* @returns array of notifications
|
||||||
case 'activities':
|
*/
|
||||||
url = `/activities/${data.user}`;
|
export const getNotifications = async (data:{
|
||||||
break;
|
filter?: "rvotes"|"mentions"|"follows"|"replies"|"reblogs"|"transfers",
|
||||||
case 'votes':
|
since?:string
|
||||||
url = `/rvotes/${data.user}`;
|
}) => {
|
||||||
break;
|
try{
|
||||||
case 'replies':
|
const response = await ecencyApi.post(`/private-api/notifications`, data);
|
||||||
url = `/replies/${data.user}`;
|
return response.data;
|
||||||
break;
|
}catch(error){
|
||||||
case 'mentions':
|
console.warn("Failed to get notifications", error)
|
||||||
url = `/mentions/${data.user}`;
|
bugsnag.notify(error)
|
||||||
break;
|
throw error;
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
api
|
}
|
||||||
.get(url, {
|
|
||||||
params: {
|
|
||||||
since: data.since,
|
|
||||||
},
|
|
||||||
})
|
|
||||||
.then((res) => {
|
|
||||||
resolve(res.data);
|
|
||||||
})
|
|
||||||
.catch((error) => {
|
|
||||||
bugsnag.notify(error);
|
|
||||||
reject(error);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
export const getUnreadNotificationCount = async () => {
|
export const getUnreadNotificationCount = async () => {
|
||||||
|
@ -6,7 +6,7 @@ import get from 'lodash/get';
|
|||||||
import { injectIntl } from 'react-intl';
|
import { injectIntl } from 'react-intl';
|
||||||
|
|
||||||
// Actions and Services
|
// Actions and Services
|
||||||
import { getActivities, markActivityAsRead, markNotifications } from '../../../providers/ecency/ecency';
|
import { getNotifications, markNotifications } from '../../../providers/ecency/ecency';
|
||||||
import { updateUnreadActivityCount } from '../../../redux/actions/accountAction';
|
import { updateUnreadActivityCount } from '../../../redux/actions/accountAction';
|
||||||
|
|
||||||
// Constants
|
// Constants
|
||||||
@ -29,21 +29,20 @@ class NotificationContainer extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
const { username, isConnected } = this.props;
|
const { isConnected } = this.props;
|
||||||
|
|
||||||
if (username && isConnected) {
|
if (isConnected) {
|
||||||
this._getAvtivities(username);
|
this._getAvtivities();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_getAvtivities = (user, type = null, loadMore = false) => {
|
_getAvtivities = (type = null, loadMore = false) => {
|
||||||
const { lastNotificationId, notifications, endOfNotification } = this.state;
|
const { lastNotificationId, notifications, endOfNotification } = this.state;
|
||||||
const since = loadMore ? lastNotificationId : null;
|
const since = loadMore ? lastNotificationId : null;
|
||||||
const { username } = this.props;
|
|
||||||
|
|
||||||
if (!endOfNotification || !loadMore) {
|
if (!endOfNotification || !loadMore) {
|
||||||
this.setState({ isNotificationRefreshing: true });
|
this.setState({ isNotificationRefreshing: true });
|
||||||
getActivities({ user: user || username, type, since })
|
getNotifications({ filter:type, since:since })
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
console.log(res);
|
console.log(res);
|
||||||
const lastId = res.length > 0 ? [...res].pop().id : null;
|
const lastId = res.length > 0 ? [...res].pop().id : null;
|
||||||
@ -152,7 +151,7 @@ class NotificationContainer extends Component {
|
|||||||
(nextProps.username !== username && nextProps.username)
|
(nextProps.username !== username && nextProps.username)
|
||||||
) {
|
) {
|
||||||
this.setState({ endOfNotification: false }, () =>
|
this.setState({ endOfNotification: false }, () =>
|
||||||
this._getAvtivities(nextProps.username, selectedFilter),
|
this._getAvtivities(selectedFilter),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user