Better Connectivity, Notifications for Followed Accounts, and maybe Mac

in utopian-io •  7 years ago  (edited)

I've fixed some problems relating to connectivity, added an option to monitor not just a user account but also activity on all accounts followed by that account, and added the follow_api to the set of remote procedure calls available via functions.sh.

Bug Fixes

Thanks to @evilest-fiend for pointing out that the local keyword in bash will always return 0 (success) no matter if the assignment comes from a subshell that fails.

For issue #9, the fix was to separate the local VARIABLE and the VARIABLE=$(...) logic onto separate lines so that the subshell failing could propagate its error up to the caller and an appropriate execution path could be taken.

For issue #10, with terrible connection issues for a few days it became obvious that the various RPC calls needed better fault tolerance, so a new function was created to do the work of fetching remote content. The function was then put in place of wget in a few places so that error recovery could actually happen. When the recovery strategy is set to "slow" it will keep trying to reconnect rather than allow the code to fall through. All the places that are doing math on the result of an RPC call behave much better now.

fetch implementation

If the caller would prefer to be notified of the error and have the call fail quickly, they should instead set the RECOVERY global to some other value, eg "fast".

New Features

While implementing the original set of RPC functions I noticed that there really weren't enough functions there to do all the stuff that steem can do. So I went searching for other APIs. And I found some. Apparently you can call a generic call method, tell it the api you want, the method, the arguments, and it will call it. So I went digging some more and found there were a bunch of APIs that I could use so I coded up the follow_api in this update. It is now possible to fetch:

  • followers
  • following
  • follow counts

To simplify parsing, the followers and following will both handle determining the appropriate number of invocations, as the original methods required the caller make separate invocations of no more than 100. These will both handle calling more than once if the provided limit is greater than 100.

Also, the follower/following counts have a couple of convenience methods for easier parsing.

notify.sh

Argument parsing has been added to notify.sh so that it will now provide a usage output when invalid arguments are passed. Also, verbose and following argument have been added. Overall console output was decreased and the verbose argument will put back in some of those orginal output messages.

Argument parsing is handled identically to other updates as it is modeled off how balances.sh does it.

The -f or following argument will cause notify.sh to also walk the list of followed names for the specified account and produce desktop notifications for voting and commenting activities.

This was implemented using the newly added follow_api calls. A global list of all the accounts being followed by the specified account is constructed using the get_following method and passing it the entire list size as discovered by rpc_get_following_count. This works because the rpc_get_following method was implemented to work around the 100 limit on the original backing RPC method.

get_following implementation

Essentially rpc_get_following iterates over multiple calls to get the followers until there are none left to fetch.

check_followed implementation

The logic for check_followed, which does the work of looking for activity on followed accounts, keeps a global list of the last record number of account history for each followed account. When it fetches a new value that doesn't match the old, then it fetches all of the missing updates for that account (much like how the main fetches updates on the watched account) and loops over them, calling the same methods that the main calls for the watched account. Some minor updates were made to those methods so that they display an account name for the activity when it isn't activity on the watched account.

vote on followed account

example of updated output

Also, rudimentary support has been added for Mac to create notifications, but it needs actual testing on a modern Mac. I used an old tehcnique for shelling out to apple script to pop up a notification. It should work on newer macs, but I don't have one, so I wasn't able to test this.

This post covers content in the Git Repo from commit #d2d07d8 to commit #ece17aad.



Posted on Utopian.io - Rewarding Open Source Contributors

Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!
Sort Order:  

Thank you for the contribution. It has been approved.

You can contact us on Discord.
[utopian-moderator]

@not-a-bird, Upvote for supporting you.

Hey @not-a-bird I am @utopian-io. I have just upvoted you!

Achievements

  • You have less than 500 followers. Just gave you a gift to help you succeed!
  • Seems like you contribute quite often. AMAZING!

Community-Driven Witness!

I am the first and only Steem Community-Driven Witness. Participate on Discord. Lets GROW TOGETHER!

mooncryption-utopian-witness-gif

Up-vote this comment to grow my power and help Open Source contributions like this one. Want to chat? Join me on Discord https://discord.gg/Pc8HG9x