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 #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 #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.
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:
stern
level, though not without some strange issues that had to be suppressed—see #152);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; anduser_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
; andSendmessage.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; andget_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; andget_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; andupdate_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 https://github.com/Pear-Trading/LocalSpend-Tracker/pull/12 & https://github.com/Pear-Trading/FoodLoop-Web/pull/124
Closes #133 #138 #141 #143 #146 #148 #149 #150 #159 #160
Progresses #153 #154