Merge pull request #2195 from ecency/notify

add marking hive notifications
This commit is contained in:
Nouman Tahir 2022-02-20 22:36:32 +05:00 committed by GitHub
commit f94a724404
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 68 additions and 6 deletions

View File

@ -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]);

View File

@ -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,
});