Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add push messaging (+ other assorted improvements) #140

Draft
wants to merge 369 commits into
base: development
Choose a base branch
from

Conversation

Rumperuu
Copy link

@Rumperuu Rumperuu commented Nov 1, 2020

NB Travis fails because it can't find the file ./localspend-47012.json, which contains the connection details for the Firebase Cloud Messaging service. This contains sensitive data and shouldn't be tracked, so I'm not sure how to handle this in Travis.

This PR was originally intended to only add push notification functionality to the server. However, it has since expanded to into a bit of a monolith, which certainly isn't ideal and should be avoided in future, but I think I'm the only person working on this at the moment so it shouldn't cause any major issues.

This PR adds the following:

  • bugfixes to allow the Travis tests to pass (these fixes are also available in isolation in Fix is_empty tests #139);
  • an updated, clarified project readme, along with security and contributing guidelines;
  • automated code formatting with Perl-Tidy;
  • code linting with Perl-Critic (and tweaks to pass at the stern level, though not without some strange issues that had to be suppressed—see ‘Subroutine name is a homonym for builtin function’ #152);
  • GitHub Issue templates;
  • the ability for organisations to push messages to customers;
  • subscribable topics for targetting messages;
  • the ability for organisations to create new topics;
  • the ability for customers to view and update their topic subscriptions; and
  • tests for the new routes.

Push Notifications

The message sending functionality uses Firebase Cloud Messaging (though I would like to look into alternatives to this in the future).

First, three new tables have been added to the database:

  • topics, storing subscribable topics (and a ‘default’ topic is now created along with the test users);
  • device_tokens, storing the device tokens of users who have granted permission to send push notifications; and
  • user_topic_subscriptions, tracking user topic subscriptions.

Eight new API routes have been added to lib/Pear/LocalLoop.pm:

  • /device-token/check;
  • /device-token/add;
  • /device-tokens;
  • /topic/add;
  • /topics;
  • /topics/subscriptions;
  • /topics/update; and
  • /send-message.

These lead to three new modules in lib/Pear/LocalLoop/Controller/Api/:

  • Devices.pm;
  • Topic.pm; and
  • Sendmessage.pm.

Devices.pm provides the following subroutines:

  • check_exists(), which checks whether a device token already exists in the database or not;
  • create(), which saves a new device token to the database; and
  • get_all(), which returns a list of all device tokens and their associated users.

Topic.pm provides the following subroutines:

  • create(), which creates a new topic; and
  • get_all(), which returns a list of all topics and the number of users subscribed to each.
  • get_all_and_subscriptions(), which returns a list of all topics and whether a given user is subscribed to them or not; and
  • update_subscriptions(), which updates a user's topic subscriptions.

Sendmessage.pm provides the following subroutines:

  • create_jwt_from_path_and_scopes(), which generates a JSON Web Token for a provided path and set of scopes;
  • post_message(), which sends the message and topic to the Firebase Cloud Messaging endpoint to be distributed to all subscribers.

See also Pear-Trading/LocalSpend-Tracker#12 & Pear-Trading/FoodLoop-Web#124

Closes #133 #138 #141 #143 #146 #148 #149 #150 #159 #160

Progresses #153 #154

Release of category API and admin interface
Category budget view added with test
Placeholder medal and endpoint added
Added placeholder API for user points
@Rumperuu Rumperuu changed the title Push Notifications Add Push Messaging (+ other assorted improvements) Mar 20, 2021
@Rumperuu Rumperuu changed the title Add Push Messaging (+ other assorted improvements) Add push messaging (+ other assorted improvements) Mar 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment