-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfriends.go
62 lines (54 loc) · 1.31 KB
/
friends.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package push_notification
import (
"context"
"firebase.google.com/go/messaging"
"log"
"strings"
)
const (
SOLICITUD_ADD_CONTACT = "SOLICITUD_ADD_CONTACT"
)
func FriendsReciver(ctx context.Context, e FirestoreEvent) error {
fullPath := strings.Split(e.Value.Name, "/documents/")[1]
pathParts := strings.Split(fullPath, "/")
//collection := pathParts[0]
uidR := pathParts[1]
uidS := pathParts[3]
//doc := strings.Join(pathParts[1:], "/")
name := e.Value.Fields.Name.StringValue
if name == "" {
name = e.Value.Fields.Nickname.StringValue
}
body := string(name + " quiere ser parte de tu red Dinamo")
data := DataNotification{
UsersID: []string{
uidR,
},
Message: &messaging.MulticastMessage{
Tokens: nil,
Data: map[string]string{
"type": SOLICITUD_ADD_CONTACT,
"id_sender": uidS,
"avatar": e.Value.Fields.Photo.StringValue,
"body": body,
"title": "Nueva Solicitud de amistad",
},
//Notification: &messaging.Notification{
//Title: "Nueva Solicitud de amistad",
//Body: body,
//ImageURL: e.Value.Fields.Photo.StringValue,
//},
},
}
err := SendPushNotificaction(ctx, &data)
if err != nil {
log.Println(err)
return err
}
err = HmsSendPushNotificaction(ctx, &data)
if err != nil {
log.Println(err)
return err
}
return nil
}