From 047f524824901d823e2941df5fec7a7bb09279ba Mon Sep 17 00:00:00 2001 From: Pierre Balzack <96387156+balzack@users.noreply.github.com> Date: Sat, 22 Apr 2023 12:09:49 -0700 Subject: [PATCH 1/2] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index bcdea955..d94a9f44 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ Databag is a self-hosted messaging service. Notable features include: - Decentralized (direct communication between app and server node) - Federated (accounts on different nodes can communicate) - Public-Private key based identity (not bound to any blockchain or hosting domain) -- End-to-End encryption (the hosting admin cannot view sealed topics) +- End-to-End encryption (the hosting admin cannot view sealed topics, deafult unsealed) - Audio and Video Calls (nat tranversal requires separate relay server) - Topic based threads (messages organized by topic not contacts) - Lightweight (server can run on a raspberry pi zero v1.3) From 3bfce5e40c5237ada3afbabfb7c3f64249cfb85a Mon Sep 17 00:00:00 2001 From: Roland Osborne Date: Sat, 22 Apr 2023 15:59:33 -0700 Subject: [PATCH 2/2] insuring single push sent per device --- net/server/internal/api_setPushEvent.go | 53 ++++++++++++++----------- 1 file changed, 30 insertions(+), 23 deletions(-) diff --git a/net/server/internal/api_setPushEvent.go b/net/server/internal/api_setPushEvent.go index d328ad3d..87df7ac0 100644 --- a/net/server/internal/api_setPushEvent.go +++ b/net/server/internal/api_setPushEvent.go @@ -52,36 +52,43 @@ func SendPushEvent(account store.Account, event string) { ErrMsg(err); return } + + tokens := make(map[string]bool) for rows.Next() { var pushToken string var messageTitle string var messageBody string + rows.Scan(&pushToken, &messageTitle, &messageBody) - url := "https://fcm.googleapis.com/fcm/send" - payload := Payload{ Title: messageTitle, Body: messageBody, Sound: "default" }; - message := Message{ Notification: payload, To: pushToken }; + if _, exists := tokens[pushToken]; !exists { + tokens[pushToken] = true; - body, err := json.Marshal(message) - if err != nil { - ErrMsg(err) - continue - } - req, err := http.NewRequest(http.MethodPost, url, bytes.NewBuffer(body)) - if err != nil { - ErrMsg(err) - continue - } - req.Header.Set("Content-Type", "application/json; charset=utf-8") - req.Header.Set("Authorization", "key=AAAAkgDXt8c:APA91bEjH67QpUWU6uAfCIXLqm0kf6AdPNVICZPCcWbmgW9NGYIErAxMDTy4LEbe4ik93Ho4Z-AJNIhr6nXXKC9qKmyKkkYHJWAEVH47_FXBQV6rsoi9ZB_oiuV66XKKAy1V40GmvfaX") - client := &http.Client{} - resp, err := client.Do(req) - if err != nil { - ErrMsg(err) - continue - } - if resp.StatusCode != 200 { - ErrMsg(errors.New("failed to push notification")); + url := "https://fcm.googleapis.com/fcm/send" + payload := Payload{ Title: messageTitle, Body: messageBody, Sound: "default" }; + message := Message{ Notification: payload, To: pushToken }; + + body, err := json.Marshal(message) + if err != nil { + ErrMsg(err) + continue + } + req, err := http.NewRequest(http.MethodPost, url, bytes.NewBuffer(body)) + if err != nil { + ErrMsg(err) + continue + } + req.Header.Set("Content-Type", "application/json; charset=utf-8") + req.Header.Set("Authorization", "key=AAAAkgDXt8c:APA91bEjH67QpUWU6uAfCIXLqm0kf6AdPNVICZPCcWbmgW9NGYIErAxMDTy4LEbe4ik93Ho4Z-AJNIhr6nXXKC9qKmyKkkYHJWAEVH47_FXBQV6rsoi9ZB_oiuV66XKKAy1V40GmvfaX") + client := &http.Client{} + resp, err := client.Do(req) + if err != nil { + ErrMsg(err) + continue + } + if resp.StatusCode != 200 { + ErrMsg(errors.New("failed to push notification")); + } } } }