-
Notifications
You must be signed in to change notification settings - Fork 7.3k
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
[Gekidou] Add push notification check to ping #19610
Conversation
app/notification_push.go
Outdated
@@ -390,6 +391,8 @@ func (a *App) sendToPushProxy(msg *model.PushNotification, session *model.Sessio | |||
mlog.String("status", model.PushSendPrepare), | |||
) | |||
|
|||
fmt.Printf("%s %s\n", msg.DeviceId, msg.Platform) |
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.
do we want to keep this for some reason? or was it there while you developed?
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.
Forgot to remove. Was there to understand the(and test with a real) deviceID.
app/notification_push.go
Outdated
@@ -568,6 +571,47 @@ func (a *App) BuildPushNotificationMessage(contentsConfig string, post *model.Po | |||
return msg, nil | |||
} | |||
|
|||
func (a *App) TestPushNotification(deviceID string) (canSend bool, err error) { |
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.
perhaps we should rename the function not to confuse it with unit tests? something like SendTestPushNotification
?
api4/system.go
Outdated
@@ -183,6 +183,17 @@ func getSystemPing(c *Context, w http.ResponseWriter, r *http.Request) { | |||
w.Header().Set(filestoreStatusKey, s[filestoreStatusKey]) | |||
} | |||
|
|||
if deviceID := r.FormValue("device_id"); deviceID != "" { | |||
canSend, err := c.App.TestPushNotification(deviceID) |
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.
Forgot to change it here?
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.
Trusted too much in the "rename symbol".
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.
Lastly, let's also add a test please :)
api4/system.go
Outdated
if deviceID := r.FormValue("device_id"); deviceID != "" { | ||
canSend, err := c.App.SendTestPushNotification(deviceID) | ||
if err != nil { | ||
s["CanReceiveNotifications"] = err.Error() |
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.
We don't do the same for other keys in the map. To remain consistent, I'd suggest to log a warning and return false instead.
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.
The problem is that returning false will mean "You cannot receive push notifications from this server". And that is a value that will be stored in the client "forever". This error may be something temporal. That will translate into the 3 states possible in the client: Can receive, cannot receive or unknown. We could hide the error from the client, by sending directly unknown, but not sure if we want to give more information to the user.
About logging or not a warning, I have no problem in doing that.
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.
We could hide the error from the client, by sending directly unknown,
I like it, let's do that 👍
app/notification_push.go
Outdated
@@ -568,6 +568,47 @@ func (a *App) BuildPushNotificationMessage(contentsConfig string, post *model.Po | |||
return msg, nil | |||
} | |||
|
|||
func (a *App) SendTestPushNotification(deviceID string) (canSend bool, err error) { | |||
var msg *model.PushNotification = &model.PushNotification{ |
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.
Nit: the more idiomatic way is msg := ...
Also, this needs changes to the mattermost-api-reference repo. |
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 isn't quite what I was suggesting. There is still some repetition going on here. What I had in mind was to have a single method that can handle a nil session and avoid doing anything session related in that.
So far the session is only used in the Info log method and in the model.PushStatusRemove
case. For the first one, we can have a slice of mlog.Fields and conditionally append the session field. And then for the second one, an if condition will suffice.
This makes a single method work with and without session. After this, we have 2 top-level methods - one having session in it's signature, the other doesn't, and passes a nil session to this underlying method.
Sorry for the double work here, but it's good to keep things clean in this notification flow.
@larkox no, this can be merged now.. no need to wait for the proxy |
/update-branch |
* Add push notification check to ping * Add test type and missing details * Address feedback * Fix function name * Address feedback Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
/cherry-pick release-6.3 |
Cherry pick is scheduled. |
* Add push notification check to ping * Add test type and missing details * Address feedback * Fix function name * Address feedback Co-authored-by: Mattermod <mattermod@users.noreply.github.com> (cherry picked from commit 32e3c2f)
…erver-mattermost#19610-upstream-release-6.3
/cherry-pick release-6.5 |
Cherry pick is scheduled. |
* Add push notification check to ping * Add test type and missing details * Address feedback * Fix function name * Address feedback Co-authored-by: Mattermod <mattermod@users.noreply.github.com> (cherry picked from commit 32e3c2f)
…erver-mattermost#19610-upstream-release-6.5
…erver-mattermost#19610-upstream-release-6.5
* Add push notification check to ping * Add test type and missing details * Address feedback * Fix function name * Address feedback Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
* Add push notification check to ping * Add test type and missing details * Address feedback * Fix function name * Address feedback Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
Summary
Add push notification check to ping.
Changes in the API require doc changes.
Related PRs
Mobile (Gekidou): mattermost/mattermost-mobile#6002
Push Proxy: mattermost/mattermost-push-proxy#96
Ticket Link
None
Release Note