mirror of
https://github.com/ecency/ecency-mobile.git
synced 2024-11-29 22:07:46 +03:00
Merge pull request #2195 from ecency/notify
add marking hive notifications
This commit is contained in:
commit
f94a724404
@ -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) => {
|
||||
try {
|
||||
const users = await client.database.call('lookup_accounts', [username, 20]);
|
||||
|
@ -16,6 +16,8 @@ import ROUTES from '../../../constants/routeNames';
|
||||
// Components
|
||||
import NotificationScreen from '../screen/notificationScreen';
|
||||
import { showProfileModal } from '../../../redux/actions/uiAction';
|
||||
import { markHiveNotifications } from '../../../providers/hive/dhive';
|
||||
import bugsnapInstance from '../../../config/bugsnag';
|
||||
|
||||
class NotificationContainer extends Component {
|
||||
constructor(props) {
|
||||
@ -125,7 +127,7 @@ class NotificationContainer extends Component {
|
||||
};
|
||||
|
||||
_readAllNotification = () => {
|
||||
const { dispatch, intl, isConnected } = this.props;
|
||||
const { dispatch, intl, isConnected, currentAccount, pinCode } = this.props;
|
||||
const { notifications } = this.state;
|
||||
|
||||
if (!isConnected) {
|
||||
@ -138,6 +140,13 @@ class NotificationContainer extends Component {
|
||||
.then(() => {
|
||||
const updatedNotifications = notifications.map((item) => ({ ...item, read: 1 }));
|
||||
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 });
|
||||
})
|
||||
.catch(() => {
|
||||
@ -161,11 +170,11 @@ class NotificationContainer extends Component {
|
||||
|
||||
UNSAFE_componentWillReceiveProps(nextProps) {
|
||||
const { selectedFilter } = this.state;
|
||||
const { username } = this.props;
|
||||
const { currentAccount } = this.props;
|
||||
|
||||
if (
|
||||
(nextProps.activeBottomTab === ROUTES.TABBAR.NOTIFICATION && nextProps.username) ||
|
||||
(nextProps.username !== username && nextProps.username)
|
||||
(nextProps.activeBottomTab === ROUTES.TABBAR.NOTIFICATION && nextProps.currentAccount.name) ||
|
||||
(nextProps.currentAccount.name !== currentAccount.name && nextProps.currentAccount.name)
|
||||
) {
|
||||
this.setState({ endOfNotification: false }, () => this._getActivities(selectedFilter));
|
||||
}
|
||||
@ -194,8 +203,8 @@ class NotificationContainer extends Component {
|
||||
const mapStateToProps = (state) => ({
|
||||
isLoggedIn: state.application.isLoggedIn,
|
||||
isConnected: state.application.isConnected,
|
||||
|
||||
username: state.account.currentAccount.name,
|
||||
pinCode: state.application.pin,
|
||||
currentAccount: state.account.currentAccount,
|
||||
activeBottomTab: state.ui.activeBottomTab,
|
||||
});
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user