mirror of
https://github.com/ecency/ecency-mobile.git
synced 2024-12-02 11:15:35 +03:00
Merge branch 'development' of https://github.com/ecency/ecency-mobile into sa/refer-screen
This commit is contained in:
commit
bfa34d9813
@ -1236,6 +1236,59 @@ export const unfollowUser = async (currentAccount, pin, data) => {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const markHiveNotifications = async (currentAccount, pinHash) => {
|
||||||
|
const digitPinCode = getDigitPinCode(pinHash);
|
||||||
|
const key = getAnyPrivateKey(currentAccount.local, digitPinCode);
|
||||||
|
|
||||||
|
const now = new Date().toISOString();
|
||||||
|
const date = now.split('.')[0];
|
||||||
|
|
||||||
|
const params = {
|
||||||
|
id: 'notify',
|
||||||
|
required_auths: [],
|
||||||
|
required_posting_auths: [currentAccount.name],
|
||||||
|
json: JSON.stringify(['setLastRead', { date }]),
|
||||||
|
};
|
||||||
|
const params1 = {
|
||||||
|
id: 'ecency_notify',
|
||||||
|
required_auths: [],
|
||||||
|
required_posting_auths: [currentAccount.name],
|
||||||
|
json: JSON.stringify(['setLastRead', { date }]),
|
||||||
|
};
|
||||||
|
|
||||||
|
const opArray: Operation[] = [
|
||||||
|
['custom_json', params],
|
||||||
|
['custom_json', params1],
|
||||||
|
];
|
||||||
|
|
||||||
|
if (currentAccount.local.authType === AUTH_TYPE.STEEM_CONNECT) {
|
||||||
|
const token = decryptKey(get(currentAccount, 'local.accessToken'), digitPinCode);
|
||||||
|
const api = new hsClient({
|
||||||
|
accessToken: token,
|
||||||
|
});
|
||||||
|
|
||||||
|
return api.broadcast(opArray).then((resp) => resp.result);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (key) {
|
||||||
|
const privateKey = PrivateKey.fromString(key);
|
||||||
|
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
sendHiveOperations(opArray, privateKey)
|
||||||
|
.then((result) => {
|
||||||
|
resolve(result);
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
reject(err);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return Promise.reject(
|
||||||
|
new Error('Check private key permission! Required private posting key or above.'),
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
export const lookupAccounts = async (username) => {
|
export const lookupAccounts = async (username) => {
|
||||||
try {
|
try {
|
||||||
const users = await client.database.call('lookup_accounts', [username, 20]);
|
const users = await client.database.call('lookup_accounts', [username, 20]);
|
||||||
|
@ -16,6 +16,8 @@ import ROUTES from '../../../constants/routeNames';
|
|||||||
// Components
|
// Components
|
||||||
import NotificationScreen from '../screen/notificationScreen';
|
import NotificationScreen from '../screen/notificationScreen';
|
||||||
import { showProfileModal } from '../../../redux/actions/uiAction';
|
import { showProfileModal } from '../../../redux/actions/uiAction';
|
||||||
|
import { markHiveNotifications } from '../../../providers/hive/dhive';
|
||||||
|
import bugsnapInstance from '../../../config/bugsnag';
|
||||||
|
|
||||||
class NotificationContainer extends Component {
|
class NotificationContainer extends Component {
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
@ -125,7 +127,7 @@ class NotificationContainer extends Component {
|
|||||||
};
|
};
|
||||||
|
|
||||||
_readAllNotification = () => {
|
_readAllNotification = () => {
|
||||||
const { dispatch, intl, isConnected } = this.props;
|
const { dispatch, intl, isConnected, currentAccount, pinCode } = this.props;
|
||||||
const { notifications } = this.state;
|
const { notifications } = this.state;
|
||||||
|
|
||||||
if (!isConnected) {
|
if (!isConnected) {
|
||||||
@ -138,6 +140,13 @@ class NotificationContainer extends Component {
|
|||||||
.then(() => {
|
.then(() => {
|
||||||
const updatedNotifications = notifications.map((item) => ({ ...item, read: 1 }));
|
const updatedNotifications = notifications.map((item) => ({ ...item, read: 1 }));
|
||||||
dispatch(updateUnreadActivityCount(0));
|
dispatch(updateUnreadActivityCount(0));
|
||||||
|
markHiveNotifications(currentAccount, pinCode)
|
||||||
|
.then(() => {
|
||||||
|
console.log('Hive notifications marked as Read');
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
bugsnapInstance.notify(err);
|
||||||
|
});
|
||||||
this.setState({ notifications: updatedNotifications, isRefreshing: false });
|
this.setState({ notifications: updatedNotifications, isRefreshing: false });
|
||||||
})
|
})
|
||||||
.catch(() => {
|
.catch(() => {
|
||||||
@ -161,11 +170,11 @@ class NotificationContainer extends Component {
|
|||||||
|
|
||||||
UNSAFE_componentWillReceiveProps(nextProps) {
|
UNSAFE_componentWillReceiveProps(nextProps) {
|
||||||
const { selectedFilter } = this.state;
|
const { selectedFilter } = this.state;
|
||||||
const { username } = this.props;
|
const { currentAccount } = this.props;
|
||||||
|
|
||||||
if (
|
if (
|
||||||
(nextProps.activeBottomTab === ROUTES.TABBAR.NOTIFICATION && nextProps.username) ||
|
(nextProps.activeBottomTab === ROUTES.TABBAR.NOTIFICATION && nextProps.currentAccount.name) ||
|
||||||
(nextProps.username !== username && nextProps.username)
|
(nextProps.currentAccount.name !== currentAccount.name && nextProps.currentAccount.name)
|
||||||
) {
|
) {
|
||||||
this.setState({ endOfNotification: false }, () => this._getActivities(selectedFilter));
|
this.setState({ endOfNotification: false }, () => this._getActivities(selectedFilter));
|
||||||
}
|
}
|
||||||
@ -194,8 +203,8 @@ class NotificationContainer extends Component {
|
|||||||
const mapStateToProps = (state) => ({
|
const mapStateToProps = (state) => ({
|
||||||
isLoggedIn: state.application.isLoggedIn,
|
isLoggedIn: state.application.isLoggedIn,
|
||||||
isConnected: state.application.isConnected,
|
isConnected: state.application.isConnected,
|
||||||
|
pinCode: state.application.pin,
|
||||||
username: state.account.currentAccount.name,
|
currentAccount: state.account.currentAccount,
|
||||||
activeBottomTab: state.ui.activeBottomTab,
|
activeBottomTab: state.ui.activeBottomTab,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user