migrated mark notification and get unread count apis

This commit is contained in:
Nouman Tahir 2021-07-02 15:06:56 +05:00
parent 2e8158e4f9
commit 3031ca7f87
4 changed files with 31 additions and 37 deletions

View File

@ -296,33 +296,28 @@ export const getActivities = (data) =>
});
});
export const getUnreadActivityCount = (data) =>
new Promise((resolve, reject) => {
api
.get(`/activities/${data.user}/unread-count`)
.then((res) => {
resolve(res.data ? res.data.count : 0);
})
.catch((error) => {
bugsnag.notify(error);
reject(error);
});
});
export const markActivityAsRead = (user, id = null) =>
new Promise((resolve, reject) => {
api
.put(`/activities/${user}`, {
id,
})
.then((res) => {
resolve(res.data);
})
.catch((error) => {
bugsnag.notify(error);
reject(error);
});
});
export const getUnreadNotificationCount = async () => {
try {
const response = await ecencyApi.post(`/private-api/notifications/unread`)
return response.data ? response.data.count : 0;
} catch(error) {
bugsnag.notify(error);
throw error;
}
}
export const markNotifications = async (id: string | null = null) => {
try{
const data = id ? { id } : {};
const response = await ecencyApi.post((`/private-api/notifications/mark`), data);
return response.data
}catch(error) {
bugsnag.notify(error);
throw error
}
};
export const setPushToken = (data) =>
new Promise((resolve, reject) => {

View File

@ -9,7 +9,7 @@ import { Client as hsClient } from 'hivesigner';
import Config from 'react-native-config';
import { get, has } from 'lodash';
import { getServer, getCache, setCache } from '../../realm/realm';
import { getUnreadActivityCount } from '../ecency/ecency';
import { getUnreadNotificationCount } from '../ecency/ecency';
import { userActivity } from '../ecency/ePoint';
// Utils
@ -202,9 +202,7 @@ export const getUser = async (user, loggedIn = true) => {
if (loggedIn) {
try {
unreadActivityCount = await getUnreadActivityCount({
user,
});
unreadActivityCount = await getUnreadNotificationCount();
} catch (error) {
unreadActivityCount = 0;
}

View File

@ -43,7 +43,7 @@ import {
} from '../../../realm/realm';
import { getUser, getPost } from '../../../providers/hive/dhive';
import { migrateToMasterKeyWithAccessToken, switchAccount } from '../../../providers/hive/auth';
import { setPushToken, markActivityAsRead } from '../../../providers/ecency/ecency';
import { setPushToken, markActivityAsRead, markNotifications } from '../../../providers/ecency/ecency';
import { navigate } from '../../../navigation/service';
// Actions
@ -473,7 +473,7 @@ class ApplicationContainer extends Component {
break;
}
markActivityAsRead(username, activity_id).then((result) => {
markNotifications(activity_id).then((result) => {
dispatch(updateUnreadActivityCount(result.unread));
});

View File

@ -6,7 +6,7 @@ import get from 'lodash/get';
import { injectIntl } from 'react-intl';
// Actions and Services
import { getActivities, markActivityAsRead } from '../../../providers/ecency/ecency';
import { getActivities, markActivityAsRead, markNotifications } from '../../../providers/ecency/ecency';
import { updateUnreadActivityCount } from '../../../redux/actions/accountAction';
// Constants
@ -66,15 +66,16 @@ class NotificationContainer extends Component {
};
_navigateToNotificationRoute = (data) => {
const { navigation, username, dispatch } = this.props;
const { navigation, dispatch } = this.props;
const type = get(data, 'type');
const permlink = get(data, 'permlink');
const author = get(data, 'author');
let routeName;
let params;
let key;
markActivityAsRead(username, data.id).then((result) => {
dispatch(updateUnreadActivityCount(result.unread));
markNotifications(data.id).then((result) => {
const {unread} = result;
dispatch(updateUnreadActivityCount(unread));
});
if (permlink && author) {
@ -117,7 +118,7 @@ class NotificationContainer extends Component {
this.setState({ isNotificationRefreshing: true });
markActivityAsRead(username)
markNotifications(username)
.then(() => {
const updatedNotifications = notifications.map((item) => ({ ...item, read: 1 }));
dispatch(updateUnreadActivityCount(0));