-
Notifications
You must be signed in to change notification settings - Fork 70
Added the device_tokens endpoint #329
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
Conversation
before_filter :authenticate_user! | ||
|
||
def create | ||
@device_token = DeviceToken.all.build device_token_params.merge! user_id: current_user.id |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is .all()
really needed to instantiate a new DeviceToken
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's enough with a DeviceToken.new(...)
, isn't it?
@@ -0,0 +1,3 @@ | |||
window.TimeOverflowRegisterExpoDeviceToken = function (token) { | |||
$.post('/device_tokens', { token: token }); | |||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe doc the "hack" (:trollface:) somewhere in the wiki and add a link there here?
before_filter :authenticate_user! | ||
|
||
def create | ||
@device_token = DeviceToken.all.build device_token_params.merge! user_id: current_user.id |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's enough with a DeviceToken.new(...)
, isn't it?
{ | ||
"to" => token, | ||
"title" => @notification.title, | ||
"body" => @notification.body |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please, use attr_readers for the ivars
def broadcast | ||
notification = PostNotification.new | ||
|
||
@post.organization.users.each do |user| |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would decouple this class from the details of the data model by passing the list of users in the constructor instead. This way if we ever change the data model we don't need to touch the push notifications implementation.
t.timestamps | ||
end | ||
add_index :device_tokens, [:user_id, :token] | ||
add_index :device_tokens, [:user_id] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one is useless due to the left-most thingie. Postgresql can use that one above when only needing user_id
@@ -0,0 +1,19 @@ | |||
module PushNotifications | |||
class UsersBroadcasterService |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you're still working on it, right? because I don't see this class used.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this class will be used once we implement the logic behind sending push notifications to users :)
|
||
t.timestamps | ||
end | ||
add_index :device_tokens, [:user_id, :token] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should be uniq
|
||
t.timestamps | ||
end | ||
add_index :device_tokens, [:user_id, :token], unique: true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👏
@@ -0,0 +1,19 @@ | |||
class DeviceTokensController < PostsController |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this controller inheriting from PostsController
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good catch
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
waaaaaaat 👓
If I understand this correctly we're still missing
right? In that case I would remove the route from this PR, merge and have an upcoming PR adding the services. It feels like all we can do as a first step for push notifications is done here. Also, it will make it easier to review these services and classes later. |
Yup, I would also merge this, even if we there's nothing that sends notifications. I wouldn't remove the route though, since we could start registering mobile devices. |
In order to send push notifications we need a place to store the device tokens for each users. In this PR:
device_tokens
) with a minimal API (just the create action).The future TimeOverflow mobile app will be implemented in this repo: https://github.com/coopdevs/timeoverflow-mobile-app 👶📱