-
Notifications
You must be signed in to change notification settings - Fork 14
Johnpooch/migrate fcm #200
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
base: master
Are you sure you want to change the base?
Changes from all commits
5192d46
c52c6a0
dc3da43
4dc4ba4
2c80989
df0bf2a
785a81a
80270ba
3b412ec
059058e
546a5d7
b49961a
f764f73
33a5be0
58475d9
0f9c5a7
c342b24
799fb5f
3b8506e
09ce6ea
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| # OAuth Client Id from Google Cloud Project | ||
| OAUTH_CLIENT_ID=your-client-id-here | ||
|
|
||
| # OAuth Secret from Google Cloud Project | ||
| OAUTH_SECRET=your-secret-here | ||
|
|
||
| # Server key from FCM | ||
| FCM_SERVER_KEY=your-server-key-here |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -36,4 +36,5 @@ game/game.debug | |
| # Diff tool files | ||
| *.orig | ||
|
|
||
| .env | ||
| .env | ||
| service-account-key.json | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -320,7 +320,7 @@ func (u *User) ID(ctx context.Context) *datastore.Key { | |
| return UserID(ctx, u.Id) | ||
| } | ||
|
|
||
| func infoToUser(ui *oauth2service.Userinfoplus) *User { | ||
| func infoToUser(ui *oauth2service.Userinfo) *User { | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I had to change this to get the service to start. I suspect it comes from some indirect dependency which was upgraded and the original type no longer exists? |
||
| u := &User{ | ||
| Email: ui.Email, | ||
| FamilyName: ui.FamilyName, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,11 +18,24 @@ services: | |
| - .:/go/src/app | ||
| networks: | ||
| - diplicity-net | ||
| env_file: | ||
| - .env | ||
| ports: | ||
| - "8080:8080" | ||
| - "8000:8000" | ||
| diplicity-configuration: | ||
| image: curlimages/curl:latest | ||
| container_name: diplicity-configuration | ||
| depends_on: | ||
| - diplicity-application | ||
| entrypoint: > | ||
| sh -c " | ||
| sleep 20 && | ||
| curl -XPOST http://diplicity-application:8080/_configure | ||
| -d '{\"OAuth\": { \"ClientID\": \"${OAUTH_CLIENT_ID}\", \"Secret\": \"${OAUTH_SECRET}\" }, \"FCMConf\": { \"ServerKey\": \"${FCM_SERVER_KEY}\" }}' | ||
| " | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a helper container that comes up and sends the values from .env to the service. Saves having to do it manually every time. There's a few values missing like SendGrid, but I'll add them as I go |
||
| env_file: | ||
| - .env | ||
| networks: | ||
| - diplicity-net | ||
| networks: | ||
| diplicity-net: | ||
| name: diplicity-net | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,12 +11,12 @@ import ( | |
| "strings" | ||
| "time" | ||
|
|
||
| "firebase.google.com/go/v4/messaging" | ||
| "github.com/aymerick/raymond" | ||
| "github.com/davecgh/go-spew/spew" | ||
| "github.com/kvannotten/mailstrip" | ||
| "github.com/zond/diplicity/auth" | ||
| "github.com/zond/enmime" | ||
| fcm "github.com/zond/go-fcm" | ||
| "github.com/zond/godip" | ||
| "github.com/zond/godip/variants" | ||
| "golang.org/x/net/context" | ||
|
|
@@ -312,12 +312,6 @@ func sendMsgNotificationsToFCM(ctx context.Context, host string, gameID *datasto | |
| return err | ||
| } | ||
|
|
||
| dataPayload, err := NewFCMData(msgContext.fcmData) | ||
| if err != nil { | ||
| log.Errorf(ctx, "Unable to encode FCM data payload %v: %v; fix NewFCMData", msgContext.fcmData, err) | ||
| return err | ||
| } | ||
|
|
||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've gotten rid of the data payload in notifications for now. I understand that they are used to power the click action on the client side. I'm not convinced that it is the best approach, I'm going to re-implement the click actions later, and hopefully in a way that is a little more straight-forward. I was struggling a lot with the encoding and decoding of data. Felt like client knew too much about what was being sent to it. I reckon there's an easier way. |
||
| if len(msgContext.userConfig.FCMTokens) == 0 { | ||
| log.Infof(ctx, "%q hasn't registered any FCM tokens, will skip sending notifiations", userId) | ||
| return nil | ||
|
|
@@ -336,24 +330,14 @@ func sendMsgNotificationsToFCM(ctx context.Context, host string, gameID *datasto | |
| if runes := []rune(notificationBody); len(runes) > 512 { | ||
| notificationBody = string(runes[:512]) + "..." | ||
| } | ||
| notificationPayload := &fcm.NotificationPayload{ | ||
| notificationPayload := &messaging.Notification{ | ||
| Title: fmt.Sprintf( | ||
| "%s: %s => %s", | ||
| msgContext.game.DescFor(msgContext.member.Nation), | ||
| msgContext.game.AbbrNat(msgContext.message.Sender), | ||
| msgContext.game.AbbrNats(msgContext.message.ChannelMembers).String(), | ||
| ), | ||
| Body: notificationBody, | ||
| Tag: "diplicity-engine-new-message", | ||
| ClickAction: fmt.Sprintf("%s://%s/Game/%s/Channel/%s/Messages", DefaultScheme, host, gameID.Encode(), channelMembers.String()), | ||
| } | ||
|
|
||
| fcmToken.MessageConfig.Customize(ctx, notificationPayload, msgContext.mailData) | ||
| if fcmToken.MessageConfig.DontSendData { | ||
| dataPayload = nil | ||
| } | ||
| if fcmToken.MessageConfig.DontSendNotification { | ||
| notificationPayload = nil | ||
| Body: notificationBody, | ||
| } | ||
|
|
||
| if err := datastore.RunInTransaction(ctx, func(ctx context.Context) error { | ||
|
|
@@ -362,7 +346,6 @@ func sendMsgNotificationsToFCM(ctx context.Context, host string, gameID *datasto | |
| 0, | ||
| time.Duration(0), | ||
| notificationPayload, | ||
| dataPayload, | ||
| map[string][]string{ | ||
| userId: []string{fcmToken.Value}, | ||
| }, | ||
|
|
||
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.
@zond do you anticipate any problems with upgrading to go 1.23? It is required for the new FCM package, or some of its dependencies.