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

Handle anonymous read restrictions by sending a poll_request event #1287

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 30 additions & 8 deletions server/server_firebase.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,13 +175,26 @@ func toFirebaseMessage(m *message, auther user.Auther) (*messaging.Message, erro
} else {
// If anonymous read for a topic is not allowed, we cannot send the message along
// via Firebase. Instead, we send a "poll_request" message, asking the client to poll.
//App function needs all the data to create a message object, if not, it fails,
//so we set it but put a placeholders to not to send the actual message
//but generic title and message instead, we also add the poll_id so client knowns
//what message is goint to "decode" (retrieve)
data = map[string]string{
"id": m.ID,
"time": fmt.Sprintf("%d", m.Time),
"event": pollRequestEvent,
"topic": m.Topic,
}
// TODO Handle APNS?
"id": m.ID,
"time": fmt.Sprintf("%d", m.Time),
"event": pollRequestEvent,
"topic": m.Topic,
"priority": fmt.Sprintf("%d", m.Priority),
"tags": strings.Join(m.Tags, ","),
"click": m.Click,
"icon": m.Icon,
"title": "Private",
"message": "Message",
"content_type": m.ContentType,
"encoding": m.Encoding,
"poll_id": m.ID,
}
apnsConfig = createAPNSAlertConfig(m, data)
}
}
var androidConfig *messaging.AndroidConfig
Expand Down Expand Up @@ -225,14 +238,23 @@ func createAPNSAlertConfig(m *message, data map[string]string) *messaging.APNSCo
for k, v := range data {
apnsData[k] = v
}
alertTitle := m.Title
alertBody := maybeTruncateAPNSBodyMessage(m.Message)
// If the event is pollRequestEvent (server/topic is restricted) we dont want to
//send the actual message to Firebase/APNS, so we send a generic text
//if for some reason, client cant retrieve the message, it shows this as the message and title
if event, ok := data["event"]; ok && event == pollRequestEvent {
alertTitle = "New Notification received"
alertBody = "Message cant be retrieved, open the app and refresh content"
}
return &messaging.APNSConfig{
Payload: &messaging.APNSPayload{
CustomData: apnsData,
Aps: &messaging.Aps{
MutableContent: true,
Alert: &messaging.ApsAlert{
Title: m.Title,
Body: maybeTruncateAPNSBodyMessage(m.Message),
Title: alertTitle,
Body: alertBody,
},
},
},
Expand Down