mirror of
https://github.com/balzack/databag.git
synced 2025-04-22 09:35:16 +00:00
integration of final push com
This commit is contained in:
parent
2b6b18337a
commit
45e002a97c
@ -85,6 +85,7 @@ func AddChannel(w http.ResponseWriter, r *http.Request) {
|
||||
SetStatus(account)
|
||||
for _, card := range cards {
|
||||
SetContactChannelNotification(account, card)
|
||||
SetContactPushNotification(card, "content.addChannel." + params.DataType)
|
||||
}
|
||||
|
||||
video := getBoolConfigValue(CNFEnableVideo, true);
|
||||
|
@ -87,6 +87,9 @@ func AddChannelTopic(w http.ResponseWriter, r *http.Request) {
|
||||
SetStatus(act)
|
||||
for _, card := range cards {
|
||||
SetContactChannelNotification(act, &card)
|
||||
if card.GUID != guid {
|
||||
SetContactPushNotification(&card, "content.addChannelTopic." + channelSlot.Channel.DataType)
|
||||
}
|
||||
}
|
||||
WriteResponse(w, getTopicModel(topicSlot))
|
||||
}
|
||||
|
@ -96,6 +96,7 @@ func SetChannelCard(w http.ResponseWriter, r *http.Request) {
|
||||
for _, card := range cards {
|
||||
SetContactChannelNotification(account, &card)
|
||||
}
|
||||
SetContactPushNotification(cardSlot.Card, "content.addChannel." + channelSlot.Channel.DataType)
|
||||
|
||||
video := getBoolConfigValue(CNFEnableVideo, true);
|
||||
audio := getBoolConfigValue(CNFEnableAudio, true);
|
||||
|
@ -101,7 +101,7 @@ func SetOpenMessage(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
// push event
|
||||
SendPushEvent(account, "contact.updateCard");
|
||||
SendPushEvent(account, "contact.addCard");
|
||||
} else {
|
||||
|
||||
// update profile if revision changed
|
||||
@ -159,7 +159,7 @@ func SetOpenMessage(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
// push event
|
||||
SendPushEvent(account, "contact.addCard");
|
||||
SendPushEvent(account, "contact.updateCard");
|
||||
}
|
||||
|
||||
status := &ContactStatus{
|
||||
|
@ -3,12 +3,19 @@ package databag
|
||||
import (
|
||||
"databag/internal/store"
|
||||
"net/http"
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
)
|
||||
|
||||
type push struct {
|
||||
PushToken string
|
||||
MessageTitle string
|
||||
MessageBody string
|
||||
type Payload struct {
|
||||
Title string `json:"title"`
|
||||
Body string `json:"body"`
|
||||
}
|
||||
|
||||
type Message struct {
|
||||
Notification Payload `json:"notification"`
|
||||
To string `json:"to"`
|
||||
}
|
||||
|
||||
//AddPushEvent notify account of event to push notify
|
||||
@ -45,11 +52,36 @@ func SendPushEvent(account store.Account, event string) {
|
||||
return
|
||||
}
|
||||
for rows.Next() {
|
||||
PrintMsg("IN ROW");
|
||||
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 };
|
||||
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"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -10,7 +10,7 @@ var DB *gorm.DB;
|
||||
|
||||
func SetPath(path string) {
|
||||
db, err := gorm.Open(sqlite.Open(path), &gorm.Config{
|
||||
Logger: logger.Default.LogMode(logger.Info),
|
||||
Logger: logger.Default.LogMode(logger.Silent),
|
||||
})
|
||||
if err != nil {
|
||||
panic("failed to connect database")
|
||||
|
Loading…
x
Reference in New Issue
Block a user