Steem - Notifier v0.2 - Mentions/Rewards/Votes/Transfers 🙌🙌 + Extras

View this thread on: d.buzz | hive.blog | peakd.com | ecency.com
·@sambillingham·
0.000 HBD
Steem - Notifier v0.2 - Mentions/Rewards/Votes/Transfers 🙌🙌 + Extras
> Steem Notifier is a minimal taskbar application that sends notifications about your Steem account through you native operating systems notification interface. 

[v0.2.0 has been merged into master](https://github.com/code-with-sam/steem-notifier)

![steem-notifier-v0.2.0.jpg](https://res.cloudinary.com/hpiynhbhq/image/upload/v1515190987/mzaq9fg0hkc5qrktfqou.jpg)

In my never-ending quest to reduce the number of tabs I have open I’ve been working on steem-notifier to bring in the features I want.

```V0.2.0``` Brings with it the ability to get notifications for votes, mentions, comments, transfers and account rewards. I felt it was important to allow the user to choose which notifications they would like to receive. New interface allows for individual selection while still keeping it as minimal as possible.

I’ve added internal notifications to give clear feedback when the notifications are enabled or disabled. 

![Screen Shot 2018-01-05 at 21.15.16.png](https://res.cloudinary.com/hpiynhbhq/image/upload/v1515191947/se7bjttzbv8s2z4fxatk.png)

## Problems with the Doc's & API
Supporting the ability for all of these notifications was more difficult than I expected. I had been using the ```streamTransactions()``` function which seemed like it should be able to receive all transactions across the blockchain. What I did not realise is that author rewards are virtual transactions. To get access to the virtual transaction I had to do some digging.

I found that ```src/api/methods.js``` lists all available methods on the steem.js library many that are not included in the documentation. Virtual Transactions are included in the operations of each block. This is not mentioned anywhere, even if you search the github repo for 'virtual' or 'author_reward', nothing, so confusing.
```json
{
   "api": "database_api",
   "method": "get_ops_in_block",
   "params": ["blockNum", "onlyVirtual"]
},
``` 
Following the same naming conventions of the other steem-js API calls I was about to construct this function.
```javascript
steem.api.getOpsInBlock(blockNum, false, (err, operations) =>{
	console.log(operations)
}
```
It seems obvious now but for awhile I was passing in a ```blockId``` to this function it needs to be a block number, not id. Operations will be an array of operations for that block, it’s then possible to loop over each operation ([full list here](https://github.com/steemit/steem-js/blob/e1b23be8b87902743623fc0e98a9b92b34ed2431/src/auth/serializer/src/operations.js#L708) - also not in docs 🙁 I will work to change that I think) and check if it corresponds to what you’re looking for. true/false allows you to specify if you want just the virtual transactions e.g ‘author_reward’, but I realised I could make use of that same function for my other operations if I flag false.

My final call to the steem api looks something like this. Where transaction will be ‘comment’, ‘vote, ‘author_reward’. A bit nesty I know, i'll fix it in a later version.💩
```
  stream = steem.api.streamBlockNumber((err, blockNum) => {
      steem.api.getOpsInBlock(blockNum, false, (err, operations) =>{
          operations.forEach( (tx, i, arr) => {
            let transaction = tx.op[0]
					})
			})
})
```
## Adding Mentions
![mention.png](https://res.cloudinary.com/hpiynhbhq/image/upload/v1515192797/oga9mq48btnylpkkykx4.png)

The feature I wanted most was to be notified of mentions. I know their are a couple services out there that do this but I thought this is a great use case for my native notifications. There is nothing out of the box for notifications, so it requires you to check the contents of every comment/post coming through the steem network. It sounds like a lot, but our computers work pretty fast these days. It looks like this in steem-notifier.
```
if(transaction == 'comment') {
   let commentBody = tx.op[1].body;
   let mentionUsername = '@'+USERNAME;
   let includesMention = commentBody.includes(mentionUsername);
   transaction = includesMention ? 'mention' : 'comment'
}
```
Note that posts/comments are considered the same on the blockchain, that is why we’re checking ```'comment'```

## couple smaller changes. 
- Removed the dock icon on a Mac, it’s normal for apps like these to run form the taskbar only
- can enable/disable without having to quit the app
- fix position between windows + mac environments

As I’m sure is clear this is still very alpha software and I may have introduced new bugs in this version that I’ve not experienced yet.

### bug fixes - 0.2.0
- enabling notifications without username would get notifications for all users… and then crash very quickly.. 🙈

### bug fixes - 0.1.1 
- multiple window creation issue has been fixed, where clicking the app icon would create a new window instead of reopening the previous one.
- explanation for node-notifier lib local include (still working on an alternative to this. see [readme]()


Please let me know if you get a chance to try this app out and if there are any feature requests, issue or comments just shoot a message on here to github. 👊

[Github Pull Request](https://github.com/code-with-sam/steem-notifier/pull/4) & [Merge into Master/commits](https://github.com/code-with-sam/steem-notifier/commits/master)


<br /><hr/><em>Posted on <a href="https://utopian.io/utopian-io/@sambillingham/steem-notifier-v0-2-mentions-rewards-votes-transfers-extras">Utopian.io -  Rewarding Open Source Contributors</a></em><hr/>
👍 , , , , , , , , ,