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

[Gekidou] Add push notification check to ping #19610

Merged
merged 7 commits into from
Mar 2, 2022

Conversation

larkox
Copy link
Contributor

@larkox larkox commented Feb 22, 2022

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

Ping endpoint now can receive a device ID, which will report whether the device is able to receive push notifications.

@larkox larkox added the Docs/Needed Requires documentation label Feb 22, 2022
@larkox larkox requested a review from enahum February 22, 2022 09:56
@mm-cloud-bot mm-cloud-bot added release-note Denotes a PR that will be considered when it comes time to generate release notes. labels Feb 22, 2022
@@ -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)
Copy link
Contributor

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?

Copy link
Contributor Author

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.

@@ -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) {
Copy link
Contributor

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?

@larkox larkox marked this pull request as ready for review February 23, 2022 11:09
@larkox larkox added 2: Dev Review Requires review by a developer 3: Security Review Review requested from Security Team labels Feb 23, 2022
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)
Copy link
Contributor

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?

Copy link
Contributor Author

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".

@larkox larkox requested a review from enahum February 23, 2022 11:12
@DSchalla DSchalla requested review from jupenur and removed request for DSchalla February 23, 2022 15:08
@jupenur jupenur removed the 3: Security Review Review requested from Security Team label Feb 23, 2022
Copy link
Member

@agnivade agnivade left a 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()
Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Member

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 👍

@@ -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{
Copy link
Member

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 := ...

app/notification_push.go Outdated Show resolved Hide resolved
@agnivade
Copy link
Member

Also, this needs changes to the mattermost-api-reference repo.

Copy link
Member

@agnivade agnivade left a 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 larkox added Do Not Merge/Awaiting PR Awaiting another pull request before merging (e.g. server changes) and removed Docs/Needed Requires documentation labels Mar 1, 2022
@enahum
Copy link
Contributor

enahum commented Mar 1, 2022

@larkox no, this can be merged now.. no need to wait for the proxy

@larkox larkox removed the Do Not Merge/Awaiting PR Awaiting another pull request before merging (e.g. server changes) label Mar 1, 2022
@larkox
Copy link
Contributor Author

larkox commented Mar 1, 2022

/update-branch

@larkox larkox added the EETests label Mar 2, 2022
@mattermod mattermod removed the EETests label Mar 2, 2022
@larkox larkox merged commit 32e3c2f into mattermost:master Mar 2, 2022
@amyblais amyblais added this to the v6.6.0 milestone Mar 2, 2022
@amyblais amyblais added Changelog/Done Required changelog entry has been written Docs/Not Needed Does not require documentation labels Mar 2, 2022
Willyfrog pushed a commit to Willyfrog/mattermost-server that referenced this pull request Mar 31, 2022
* 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>
@amyblais
Copy link
Member

/cherry-pick release-6.3

@mattermod
Copy link
Contributor

Cherry pick is scheduled.

@mattermod mattermod added the CherryPick/Done Successfully cherry-picked to the quality or patch release tracked in the milestone label Apr 21, 2022
mattermost-build pushed a commit to mattermost-build/mattermost that referenced this pull request Apr 21, 2022
* 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)
mattermod added a commit to mattermost-build/mattermost that referenced this pull request Apr 21, 2022
@larkox larkox mentioned this pull request Apr 22, 2022
mattermod pushed a commit that referenced this pull request Apr 28, 2022
Automatic Merge
@amyblais
Copy link
Member

/cherry-pick release-6.5

@mattermod
Copy link
Contributor

Cherry pick is scheduled.

mattermost-build pushed a commit to mattermost-build/mattermost that referenced this pull request May 13, 2022
* 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)
mattermod added a commit to mattermost-build/mattermost that referenced this pull request May 13, 2022
mattermod added a commit to mattermost-build/mattermost that referenced this pull request May 18, 2022
larkox added a commit to larkox/mattermost-server that referenced this pull request May 18, 2022
* 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>
FreedomBen pushed a commit to FreedomBen/mattermost-server that referenced this pull request Jun 14, 2022
* 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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
4: Reviews Complete All reviewers have approved the pull request Changelog/Done Required changelog entry has been written CherryPick/Done Successfully cherry-picked to the quality or patch release tracked in the milestone Docs/Done Required documentation has been written Docs/Not Needed Does not require documentation release-note Denotes a PR that will be considered when it comes time to generate release notes.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants