mirror of
https://github.com/binwiederhier/ntfy.git
synced 2025-07-20 10:04:08 +00:00
Handle anonymous read restrictions by sending a poll_request event
If a topic does not allow anonymous reads, this change ensures that we send a "poll_request" event instead of relaying the message via Firebase. Additionally, we include generic text in the title and body/message. This way, if the client cannot retrieve the actual message, the user will still receive a notification, prompting them to update the client manually.
This commit is contained in:
parent
630f2957de
commit
6b2cfb1d1d
1 changed files with 30 additions and 8 deletions
|
@ -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
|
||||
|
@ -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,
|
||||
},
|
||||
},
|
||||
},
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue