Skip to content

Commit

Permalink
i have fcm
Browse files Browse the repository at this point in the history
  • Loading branch information
or-else committed Oct 10, 2018
1 parent 1ea4a3d commit 33ab495
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
1 change: 1 addition & 0 deletions docker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ You can specify the following environment variables when issuing `docker run` co
| `FCM_VAPID_KEY` | string | | Also called 'Web Client certificate' in the FCM console. Required by the web client to receive push notifications. |
| `MEDIA_HANDLER` | string | `fs` | Handler of large files, either `fs` or `s3` |
| `MYSQL_DSN` | string | `'root@tcp(mysql)/tinode'` | MySQL [DSN](https://github.com/go-sql-driver/mysql#dsn-data-source-name). |
| `PLUGIN_PYTHON_CHAT_BOT_ENABLED` | bool | `false` | Enable calling into the plugin provided by Python chatbot |
| `RESET_DB` | bool | `false` | Drop and recreate the database. |
| `SMTP_HOST_URL` | string | `'http://localhost:6060/'` | URL of the host where the webapp is running (email verification). |
| `SMTP_PASSWORD` | string | | Password to use for authentication with the SMTP server (email verification). |
Expand Down
2 changes: 0 additions & 2 deletions server/hub.go
Original file line number Diff line number Diff line change
Expand Up @@ -607,8 +607,6 @@ func topicInit(sreg *sessionJoin, h *Hub) {
}
}

// t.clearId is not currently used for p2p topics

// Publics is already swapped
userData.public = sub1.GetPublic()
userData.topicName = userID2.UserId()
Expand Down
19 changes: 12 additions & 7 deletions server/push/fcm/push_fcm.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"errors"
"log"
"strconv"
"time"

fbase "firebase.google.com/go"
fcm "firebase.google.com/go/messaging"
Expand Down Expand Up @@ -111,7 +112,7 @@ func payloadToData(pl *push.Payload) (map[string]string, error) {
// Must use "xfrom" because "from" is a reserved word.
// Google did not bother to document it anywhere.
data["xfrom"] = pl.From
data["ts"] = pl.Timestamp.String()
data["ts"] = pl.Timestamp.Format(time.RFC3339Nano)
data["seq"] = strconv.Itoa(pl.SeqId)
data["mime"] = pl.ContentType
data["content"], err = drafty.ToPlainText(pl.Content)
Expand Down Expand Up @@ -173,13 +174,17 @@ func sendNotifications(rcpt *push.Receipt, config *configType) {
Color: config.IconColor,
},
}
} else {
// No need to handle webpush separately.
msg.Notification = &fcm.Notification{
Title: "New message",
Body: data["content"],
}
}

// Firebase messaging is buggy and poorly documented. If
// msg.Notification is defined, then firebase will ignore
// whatever handler is set in setBackgroundMessageHandler.
// See dicussion of this madness here:
// https://github.com/firebase/quickstart-js/issues/71
// msg.Notification = &fcm.Notification{
// Title: "New message",
// Body: data["content"],
// }
_, err := handler.client.Send(ctx, &msg)
if err != nil {
if fcm.IsMessageRateExceeded(err) ||
Expand Down

0 comments on commit 33ab495

Please sign in to comment.