Compare commits
13 Commits
Author | SHA1 | Date |
---|---|---|
|
b1a0b41a2b | |
|
1c35dfb76a | |
|
5a37fba851 | |
|
58c1ec0f8e | |
|
9a5bdda1d9 | |
|
615aa4e963 | |
|
43af89bf21 | |
|
86447177ca | |
|
2b7e4413cc | |
|
47724f54c2 | |
|
723c8a3d98 | |
|
2b543fa47c | |
|
4b7991bbbf |
|
@ -0,0 +1,7 @@
|
|||
package notification
|
||||
|
||||
const (
|
||||
SortOrderDesc = "-order"
|
||||
SortOrderAsc = "order"
|
||||
SortDefault = "-lastPushAt"
|
||||
)
|
|
@ -3,9 +3,9 @@ package main
|
|||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/Selly-Modules/natsio"
|
||||
"git.selly.red/Selly-Modules/natsio"
|
||||
|
||||
"github.com/Selly-Modules/notification"
|
||||
"git.selly.red/Selly-Modules/notification"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
@ -24,37 +24,37 @@ func main() {
|
|||
|
||||
userID := "61a499ad8d5770f8872b03d8"
|
||||
requestID, err := c.PushToUsers(notification.PushRequest{
|
||||
Title: "Notification 1",
|
||||
Body: "nats stream view notification",
|
||||
Title: "Notification campaign 111",
|
||||
Body: "Notification campaign 11",
|
||||
Data: "{}",
|
||||
Users: []string{userID},
|
||||
Label: "tracking-label",
|
||||
Category: "order",
|
||||
Label: "tracking-campaign",
|
||||
Category: "campaign",
|
||||
})
|
||||
if err != nil {
|
||||
fmt.Println("Push err: ", err)
|
||||
}
|
||||
fmt.Println("Request id: ", requestID)
|
||||
|
||||
total, err := c.CountUnread(notification.CountUnread{
|
||||
unread, err := c.CountUnread(notification.CountUnread{
|
||||
User: userID,
|
||||
Category: "order",
|
||||
Category: "", // count all if not specify category
|
||||
})
|
||||
fmt.Println("Count: ", total, err)
|
||||
fmt.Println("Count: ", unread, err)
|
||||
|
||||
res, err := c.Query(notification.Query{
|
||||
User: userID,
|
||||
Category: "order",
|
||||
Page: 0,
|
||||
Limit: 20,
|
||||
Category: "", // get all if not specify category
|
||||
})
|
||||
fmt.Println("Query : ", res, err)
|
||||
|
||||
total, err = c.CountUnread(notification.CountUnread{
|
||||
unread, err = c.CountUnread(notification.CountUnread{
|
||||
User: userID,
|
||||
Category: "order",
|
||||
Category: "",
|
||||
})
|
||||
fmt.Println("Count: 2", total, err)
|
||||
fmt.Printf("Count: 2 %+v, %v\n", unread, err)
|
||||
|
||||
err = c.Subscribe("test", []string{
|
||||
"eX1gEc7WokSHh-zJ3WR5Hn:APA91bFZDuzkjjFFL6TNpMg0ot93a0wsypWi4aCdm7M2x6AihgjS_QWsbKSFCT4hNhv_d8wKGy-DG6_3e8OlwPiWiJB4R33xLbbUekgxKcfCiiFooIC1E1OE3XWkvUtn4egn8aLG5jqv",
|
||||
|
|
11
go.mod
11
go.mod
|
@ -1,14 +1,13 @@
|
|||
module github.com/Selly-Modules/notification
|
||||
module git.selly.red/Selly-Modules/notification
|
||||
|
||||
go 1.17
|
||||
|
||||
require github.com/Selly-Modules/natsio v0.0.0-20211202032952-04a8b182fb92
|
||||
|
||||
require (
|
||||
git.selly.red/Selly-Modules/natsio v1.0.2-0.20221010041139-c11419a3ad33 // indirect
|
||||
github.com/logrusorgru/aurora v2.0.3+incompatible // indirect
|
||||
github.com/nats-io/nats.go v1.13.0 // indirect
|
||||
github.com/nats-io/nats.go v1.17.0 // indirect
|
||||
github.com/nats-io/nkeys v0.3.0 // indirect
|
||||
github.com/nats-io/nuid v1.0.1 // indirect
|
||||
github.com/thoas/go-funk v0.9.1 // indirect
|
||||
golang.org/x/crypto v0.0.0-20210616213533-5ff15b29337e // indirect
|
||||
github.com/thoas/go-funk v0.9.2 // indirect
|
||||
golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d // indirect
|
||||
)
|
||||
|
|
36
go.sum
36
go.sum
|
@ -1,7 +1,10 @@
|
|||
github.com/Selly-Modules/natsio v0.0.0-20211202032952-04a8b182fb92 h1:tZMu1uKbo2l5G7aYRkCtyjQl4Gog4X98mYT/QZC94+8=
|
||||
github.com/Selly-Modules/natsio v0.0.0-20211202032952-04a8b182fb92/go.mod h1:NG55g9ip18nvN5tfP6PcSEKec10/lOeIOZC8HqBVNlQ=
|
||||
git.selly.red/Selly-Modules/natsio v0.0.0-20211202032952-04a8b182fb92 h1:tZMu1uKbo2l5G7aYRkCtyjQl4Gog4X98mYT/QZC94+8=
|
||||
git.selly.red/Selly-Modules/natsio v0.0.0-20211202032952-04a8b182fb92/go.mod h1:NG55g9ip18nvN5tfP6PcSEKec10/lOeIOZC8HqBVNlQ=
|
||||
git.selly.red/Selly-Modules/natsio v1.0.2-0.20221010041139-c11419a3ad33 h1:GvQjelaV4XZm++AOihYAKOD6k9510aMAr6B6MGnrXPs=
|
||||
git.selly.red/Selly-Modules/natsio v1.0.2-0.20221010041139-c11419a3ad33/go.mod h1:KNODhfeBqxRmHHQHHU+p3JfH42t8s5aNxfgr6X8fr6g=
|
||||
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8=
|
||||
github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA=
|
||||
github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs=
|
||||
|
@ -11,17 +14,24 @@ github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw
|
|||
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
|
||||
github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw=
|
||||
github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
|
||||
github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
|
||||
github.com/golang/snappy v0.0.3/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
|
||||
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
|
||||
github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
|
||||
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
github.com/klauspost/compress v1.13.4 h1:0zhec2I8zGnjWcKyLl6i3gPqKANCCn5e9xmviEEeX6s=
|
||||
github.com/klauspost/compress v1.13.4/go.mod h1:8dP1Hq4DHOhN9w426knH3Rhby4rFm6D8eO+e+Dq5Gzg=
|
||||
github.com/klauspost/compress v1.13.6/go.mod h1:/3/Vjq9QcHkK5uEr5lBEmyoZ1iFhe47etQ6QUkpK6sk=
|
||||
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
|
||||
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
|
||||
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
|
||||
github.com/logrusorgru/aurora v2.0.3+incompatible h1:tOpm7WcpBTn4fjmVfgpQq0EfczGlG91VSDkswnjF5A8=
|
||||
github.com/logrusorgru/aurora v2.0.3+incompatible/go.mod h1:7rIyQOR62GCctdiQpZ/zOJlFyk6y+94wXzv6RNZgaR4=
|
||||
github.com/minio/highwayhash v1.0.1 h1:dZ6IIu8Z14VlC0VpfKofAhCy74wu/Qb5gcn52yWoz/0=
|
||||
github.com/minio/highwayhash v1.0.1/go.mod h1:BQskDq+xkJ12lmlUUi7U0M5Swg3EWR+dLTk+kldvVxY=
|
||||
github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe/go.mod h1:wL8QJuTMNUDYhXwkmfOly8iTdp5TEcJFWZD2D7SIkUc=
|
||||
github.com/nats-io/jwt v1.2.2 h1:w3GMTO969dFg+UOKTmmyuu7IGdusK+7Ytlt//OYH/uU=
|
||||
github.com/nats-io/jwt v1.2.2/go.mod h1:/xX356yQA6LuXI9xWW7mZNpxgF2mBmGecH+Fj34sP5Q=
|
||||
github.com/nats-io/jwt/v2 v2.0.3 h1:i/O6cmIsjpcQyWDYNcq2JyZ3/VTF8SJ4JWluI5OhpvI=
|
||||
|
@ -31,34 +41,53 @@ github.com/nats-io/nats-server/v2 v2.6.1/go.mod h1:Az91TbZiV7K4a6k/4v6YYdOKEoxCX
|
|||
github.com/nats-io/nats.go v1.12.3/go.mod h1:BPko4oXsySz4aSWeFgOHLZs3G4Jq4ZAyE6/zMCxRT6w=
|
||||
github.com/nats-io/nats.go v1.13.0 h1:LvYqRB5epIzZWQp6lmeltOOZNLqCvm4b+qfvzZO03HE=
|
||||
github.com/nats-io/nats.go v1.13.0/go.mod h1:BPko4oXsySz4aSWeFgOHLZs3G4Jq4ZAyE6/zMCxRT6w=
|
||||
github.com/nats-io/nats.go v1.17.0 h1:1jp5BThsdGlN91hW0k3YEfJbfACjiOYtUiLXG0RL4IE=
|
||||
github.com/nats-io/nats.go v1.17.0/go.mod h1:BPko4oXsySz4aSWeFgOHLZs3G4Jq4ZAyE6/zMCxRT6w=
|
||||
github.com/nats-io/nkeys v0.2.0/go.mod h1:XdZpAbhgyyODYqjTawOnIOI7VlbKSarI9Gfy1tqEu/s=
|
||||
github.com/nats-io/nkeys v0.3.0 h1:cgM5tL53EvYRU+2YLXIK0G2mJtK12Ft9oeooSZMA2G8=
|
||||
github.com/nats-io/nkeys v0.3.0/go.mod h1:gvUNGjVcM2IPr5rCsRsC6Wb3Hr2CQAm08dsxtV6A5y4=
|
||||
github.com/nats-io/nuid v1.0.1 h1:5iA8DT8V7q8WK2EScv2padNa/rTESc1KdnPw4TC2paw=
|
||||
github.com/nats-io/nuid v1.0.1/go.mod h1:19wcPz3Ph3q0Jbyiqsd0kePYG7A95tJPxeL+1OSON2c=
|
||||
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
|
||||
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
|
||||
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/thoas/go-funk v0.9.1 h1:O549iLZqPpTUQ10ykd26sZhzD+rmR5pWhuElrhbC20M=
|
||||
github.com/thoas/go-funk v0.9.1/go.mod h1:+IWnUfUmFO1+WVYQWQtIJHeRRdaIyyYglZN7xzUPe4Q=
|
||||
github.com/thoas/go-funk v0.9.2 h1:oKlNYv0AY5nyf9g+/GhMgS/UO2ces0QRdPKwkhY3VCk=
|
||||
github.com/thoas/go-funk v0.9.2/go.mod h1:+IWnUfUmFO1+WVYQWQtIJHeRRdaIyyYglZN7xzUPe4Q=
|
||||
github.com/tidwall/pretty v1.0.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk=
|
||||
github.com/xdg-go/pbkdf2 v1.0.0/go.mod h1:jrpuAogTd400dnrH08LKmI/xc1MbPOebTwRqcT5RDeI=
|
||||
github.com/xdg-go/scram v1.1.1/go.mod h1:RaEWvsqvNKKvBPvcKeFjrG2cJqOkHTiyTpzz23ni57g=
|
||||
github.com/xdg-go/stringprep v1.0.3/go.mod h1:W3f5j4i+9rC0kuIEJL0ky1VpHXQU3ocBgklLGvcBnW8=
|
||||
github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d/go.mod h1:rHwXgn7JulP+udvsHwJoVG1YGAP6VLg4y9I5dyZdqmA=
|
||||
go.mongodb.org/mongo-driver v1.10.1/go.mod h1:z4XpeoU6w+9Vht+jAFyLgVrD+jGSQQe0+CBWFHNiHt8=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
golang.org/x/crypto v0.0.0-20200323165209-0ec3e9974c59/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||
golang.org/x/crypto v0.0.0-20210314154223-e6e6c4f2bb5b/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4=
|
||||
golang.org/x/crypto v0.0.0-20210616213533-5ff15b29337e h1:gsTQYXdTw2Gq7RBsWvlQ91b+aEQ6bXFUngBGuR8sPpI=
|
||||
golang.org/x/crypto v0.0.0-20210616213533-5ff15b29337e/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
|
||||
golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d h1:sK3txAijHtOK88l68nt020reeT1ZdKLIYetKl95FzVY=
|
||||
golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
|
||||
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
|
||||
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
|
||||
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sys v0.0.0-20190130150945-aca44879d564/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1 h1:SrN+KX8Art/Sf4HNj6Zcz06G7VEz+7w9tdXTPOZ7+l4=
|
||||
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
|
||||
golang.org/x/time v0.0.0-20200416051211-89c76fbcd5d1 h1:NusfzzA6yGQ+ua51ck7E3omNUX/JuqbFSaRGqU8CcLI=
|
||||
golang.org/x/time v0.0.0-20200416051211-89c76fbcd5d1/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
|
||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
|
@ -74,5 +103,8 @@ google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQ
|
|||
google.golang.org/protobuf v1.27.1 h1:SnqbnDw1V7RiZcXPx5MEeqPv2s79L9i7BJUlG/+RurQ=
|
||||
google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
|
||||
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
|
|
67
model.go
67
model.go
|
@ -1,6 +1,6 @@
|
|||
package notification
|
||||
|
||||
import "github.com/Selly-Modules/natsio"
|
||||
import "git.selly.red/Selly-Modules/natsio"
|
||||
|
||||
// Config ...
|
||||
type Config struct {
|
||||
|
@ -10,13 +10,23 @@ type Config struct {
|
|||
|
||||
// PushRequest ...
|
||||
type PushRequest struct {
|
||||
Title string `json:"title"`
|
||||
Body string `json:"body"`
|
||||
Data string `json:"data"`
|
||||
Users []string `json:"users"`
|
||||
Label string `json:"label,omitempty"`
|
||||
Category string `json:"category,omitempty"`
|
||||
Sound string `json:"sound,omitempty"`
|
||||
Title string `json:"title"`
|
||||
Body string `json:"body"`
|
||||
Data string `json:"data"`
|
||||
Users []string `json:"users"`
|
||||
Label string `json:"label,omitempty"`
|
||||
Category string `json:"category,omitempty"`
|
||||
Sound *Sound `json:"sound,omitempty"`
|
||||
Link string `json:"link"` // for webpush
|
||||
Order int `json:"order"` // for sort
|
||||
DisplayUntil int64 `json:"displayUntil"` // time.Unix
|
||||
SaveNotification bool `json:"saveNotification"`
|
||||
}
|
||||
|
||||
// Sound ...
|
||||
type Sound struct {
|
||||
IOSFileName string `json:"iosFileName"`
|
||||
AndroidChannel string `json:"androidChannel"`
|
||||
}
|
||||
|
||||
// PushResponse ...
|
||||
|
@ -25,32 +35,25 @@ type PushResponse struct {
|
|||
}
|
||||
|
||||
type pushRequest struct {
|
||||
APIKey string `json:"apiKey"`
|
||||
Title string `json:"title"`
|
||||
Body string `json:"body"`
|
||||
Data string `json:"data"`
|
||||
SendBy string `json:"sendBy"`
|
||||
Users []string `json:"users"`
|
||||
Topic string `json:"topic"`
|
||||
Label string `json:"label"`
|
||||
Category string `json:"category"`
|
||||
Sound string `json:"sound,omitempty"`
|
||||
PushRequest
|
||||
Version string `json:"version"`
|
||||
APIKey string `json:"apiKey"`
|
||||
SendBy string `json:"sendBy"`
|
||||
}
|
||||
|
||||
// Query ...
|
||||
type Query struct {
|
||||
User string `json:"user"`
|
||||
Category string `json:"category,omitempty"`
|
||||
Status string `json:"status"`
|
||||
Page int64 `json:"page,omitempty"`
|
||||
Limit int64 `json:"limit,omitempty"`
|
||||
Sort string `json:"sort,omitempty"` // SortDefault, SortOrderDesc, SortOrderAsc
|
||||
}
|
||||
|
||||
type query struct {
|
||||
APIKey string `json:"apiKey"`
|
||||
User string `json:"user"`
|
||||
Category string `json:"category,omitempty"`
|
||||
Page int64 `json:"page,omitempty"`
|
||||
Limit int64 `json:"limit,omitempty"`
|
||||
APIKey string `json:"apiKey"`
|
||||
Query
|
||||
}
|
||||
|
||||
// Notification ...
|
||||
|
@ -90,13 +93,17 @@ type CountUnread struct {
|
|||
|
||||
// CountUnreadResponse ...
|
||||
type CountUnreadResponse struct {
|
||||
Total int64 `json:"total"`
|
||||
List []CategoryCount `json:"list"`
|
||||
}
|
||||
|
||||
type CategoryCount struct {
|
||||
Category string `json:"category"`
|
||||
TotalUnread int64 `json:"totalUnread"`
|
||||
}
|
||||
|
||||
type countUnread struct {
|
||||
APIKey string `json:"apiKey"`
|
||||
User string `json:"user"`
|
||||
Category string `json:"category"`
|
||||
CountUnread
|
||||
APIKey string `json:"apiKey"`
|
||||
}
|
||||
|
||||
// CommonError ...
|
||||
|
@ -114,3 +121,9 @@ type subscribe struct {
|
|||
Subscribe
|
||||
APIKey string `json:"apiKey"`
|
||||
}
|
||||
|
||||
// ReadAll ...
|
||||
type ReadAll struct {
|
||||
User string `json:"user"`
|
||||
Category string `json:"category,omitempty"`
|
||||
}
|
||||
|
|
|
@ -5,9 +5,12 @@ import (
|
|||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/Selly-Modules/natsio"
|
||||
"git.selly.red/Selly-Modules/natsio"
|
||||
)
|
||||
|
||||
// version specify current version of client
|
||||
const version = "1.0.4"
|
||||
|
||||
const (
|
||||
SendByTopic = "topic"
|
||||
SendByUsers = "users"
|
||||
|
@ -17,6 +20,7 @@ const (
|
|||
SubjectPushNotification = "push_notification"
|
||||
SubjectGetNotification = "get_notification"
|
||||
SubjectReadNotification = "read_notification"
|
||||
SubjectReadAllNotification = "read_all_notification"
|
||||
SubjectCountUnreadNotification = "count_unread_notification"
|
||||
SubjectSubscribeTopic = "subscribe_topic"
|
||||
SubjectUnsubscribeTopic = "unsubscribe_topic"
|
||||
|
@ -53,15 +57,10 @@ func NewClient(cfg Config) (*Client, error) {
|
|||
// PushToUsers push notification to list user id
|
||||
func (c *Client) PushToUsers(payload PushRequest) (requestID string, err error) {
|
||||
p := pushRequest{
|
||||
APIKey: c.Config.APIKey,
|
||||
Title: payload.Title,
|
||||
Body: payload.Body,
|
||||
Data: payload.Data,
|
||||
SendBy: SendByUsers,
|
||||
Users: payload.Users,
|
||||
Label: payload.Label,
|
||||
Category: payload.Category,
|
||||
Sound: payload.Sound,
|
||||
Version: version,
|
||||
APIKey: c.Config.APIKey,
|
||||
SendBy: SendByUsers,
|
||||
PushRequest: payload,
|
||||
}
|
||||
msg, err := c.natsServer.Request(SubjectPushNotification, toBytes(p))
|
||||
if err != nil {
|
||||
|
@ -83,11 +82,8 @@ func (c *Client) PushToUsers(payload PushRequest) (requestID string, err error)
|
|||
// Query get list notification by user id
|
||||
func (c *Client) Query(q Query) (ListNotificationResponse, error) {
|
||||
p := query{
|
||||
APIKey: c.Config.APIKey,
|
||||
User: q.User,
|
||||
Category: q.Category,
|
||||
Page: q.Page,
|
||||
Limit: q.Limit,
|
||||
APIKey: c.Config.APIKey,
|
||||
Query: q,
|
||||
}
|
||||
msg, err := c.natsServer.Request(SubjectGetNotification, toBytes(p))
|
||||
if err != nil {
|
||||
|
@ -107,27 +103,26 @@ func (c *Client) Query(q Query) (ListNotificationResponse, error) {
|
|||
}
|
||||
|
||||
// CountUnread count total unread notification
|
||||
func (c *Client) CountUnread(q CountUnread) (int64, error) {
|
||||
func (c *Client) CountUnread(q CountUnread) ([]CategoryCount, error) {
|
||||
p := countUnread{
|
||||
APIKey: c.Config.APIKey,
|
||||
User: q.User,
|
||||
Category: q.Category,
|
||||
APIKey: c.Config.APIKey,
|
||||
CountUnread: q,
|
||||
}
|
||||
msg, err := c.natsServer.Request(SubjectCountUnreadNotification, toBytes(p))
|
||||
if err != nil {
|
||||
return 0, err
|
||||
return nil, err
|
||||
}
|
||||
var res struct {
|
||||
Data CountUnreadResponse `json:"data"`
|
||||
Error string `json:"error"`
|
||||
}
|
||||
if err := json.Unmarshal(msg.Data, &res); err != nil {
|
||||
return 0, err
|
||||
if err = json.Unmarshal(msg.Data, &res); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if res.Error != "" {
|
||||
return 0, errors.New(res.Error)
|
||||
return nil, errors.New(res.Error)
|
||||
}
|
||||
return res.Data.Total, nil
|
||||
return res.Data.List, nil
|
||||
}
|
||||
|
||||
// Read mark notification as read
|
||||
|
@ -150,6 +145,29 @@ func (c *Client) Read(notificationID string) error {
|
|||
return err
|
||||
}
|
||||
|
||||
// ReadAll mark notification as read
|
||||
func (c *Client) ReadAll(r ReadAll) error {
|
||||
p := struct {
|
||||
ReadAll
|
||||
APIKey string `json:"apiKey"`
|
||||
}{
|
||||
ReadAll: r,
|
||||
APIKey: c.Config.APIKey,
|
||||
}
|
||||
msg, err := c.natsServer.Request(SubjectReadAllNotification, toBytes(p))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
var res CommonError
|
||||
if err := json.Unmarshal(msg.Data, &res); err != nil {
|
||||
return err
|
||||
}
|
||||
if res.Error != "" {
|
||||
err = errors.New(res.Error)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
// Subscribe tokens to topic
|
||||
func (c *Client) Subscribe(topic string, tokens []string) error {
|
||||
p := subscribe{
|
||||
|
|
Loading…
Reference in New Issue