mirror of
https://github.com/balzack/databag.git
synced 2025-02-14 20:49:16 +00:00
Merge branch 'main' into share
This commit is contained in:
commit
9539a1f038
@ -23,7 +23,7 @@ Databag is a self-hosted messaging service. Notable features include:
|
|||||||
- Decentralized (direct communication between app and server node)
|
- Decentralized (direct communication between app and server node)
|
||||||
- Federated (accounts on different nodes can communicate)
|
- Federated (accounts on different nodes can communicate)
|
||||||
- Public-Private key based identity (not bound to any blockchain or hosting domain)
|
- 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)
|
- Audio and Video Calls (nat tranversal requires separate relay server)
|
||||||
- Topic based threads (messages organized by topic not contacts)
|
- Topic based threads (messages organized by topic not contacts)
|
||||||
- Lightweight (server can run on a raspberry pi zero v1.3)
|
- Lightweight (server can run on a raspberry pi zero v1.3)
|
||||||
|
@ -52,36 +52,43 @@ func SendPushEvent(account store.Account, event string) {
|
|||||||
ErrMsg(err);
|
ErrMsg(err);
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tokens := make(map[string]bool)
|
||||||
for rows.Next() {
|
for rows.Next() {
|
||||||
var pushToken string
|
var pushToken string
|
||||||
var messageTitle string
|
var messageTitle string
|
||||||
var messageBody string
|
var messageBody string
|
||||||
|
|
||||||
rows.Scan(&pushToken, &messageTitle, &messageBody)
|
rows.Scan(&pushToken, &messageTitle, &messageBody)
|
||||||
|
|
||||||
url := "https://fcm.googleapis.com/fcm/send"
|
if _, exists := tokens[pushToken]; !exists {
|
||||||
payload := Payload{ Title: messageTitle, Body: messageBody, Sound: "default" };
|
tokens[pushToken] = true;
|
||||||
message := Message{ Notification: payload, To: pushToken };
|
|
||||||
|
|
||||||
body, err := json.Marshal(message)
|
url := "https://fcm.googleapis.com/fcm/send"
|
||||||
if err != nil {
|
payload := Payload{ Title: messageTitle, Body: messageBody, Sound: "default" };
|
||||||
ErrMsg(err)
|
message := Message{ Notification: payload, To: pushToken };
|
||||||
continue
|
|
||||||
}
|
body, err := json.Marshal(message)
|
||||||
req, err := http.NewRequest(http.MethodPost, url, bytes.NewBuffer(body))
|
if err != nil {
|
||||||
if err != nil {
|
ErrMsg(err)
|
||||||
ErrMsg(err)
|
continue
|
||||||
continue
|
}
|
||||||
}
|
req, err := http.NewRequest(http.MethodPost, url, bytes.NewBuffer(body))
|
||||||
req.Header.Set("Content-Type", "application/json; charset=utf-8")
|
if err != nil {
|
||||||
req.Header.Set("Authorization", "key=AAAAkgDXt8c:APA91bEjH67QpUWU6uAfCIXLqm0kf6AdPNVICZPCcWbmgW9NGYIErAxMDTy4LEbe4ik93Ho4Z-AJNIhr6nXXKC9qKmyKkkYHJWAEVH47_FXBQV6rsoi9ZB_oiuV66XKKAy1V40GmvfaX")
|
ErrMsg(err)
|
||||||
client := &http.Client{}
|
continue
|
||||||
resp, err := client.Do(req)
|
}
|
||||||
if err != nil {
|
req.Header.Set("Content-Type", "application/json; charset=utf-8")
|
||||||
ErrMsg(err)
|
req.Header.Set("Authorization", "key=AAAAkgDXt8c:APA91bEjH67QpUWU6uAfCIXLqm0kf6AdPNVICZPCcWbmgW9NGYIErAxMDTy4LEbe4ik93Ho4Z-AJNIhr6nXXKC9qKmyKkkYHJWAEVH47_FXBQV6rsoi9ZB_oiuV66XKKAy1V40GmvfaX")
|
||||||
continue
|
client := &http.Client{}
|
||||||
}
|
resp, err := client.Do(req)
|
||||||
if resp.StatusCode != 200 {
|
if err != nil {
|
||||||
ErrMsg(errors.New("failed to push notification"));
|
ErrMsg(err)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if resp.StatusCode != 200 {
|
||||||
|
ErrMsg(errors.New("failed to push notification"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user