push_common/push_common.go

96 lines
2.7 KiB
Go
Raw Normal View History

2025-01-27 12:09:39 +03:00
package push_common
2025-01-27 14:31:18 +03:00
import (
"strconv"
"strings"
"git.bit5.ru/backend/errors"
)
2025-01-27 12:53:40 +03:00
type PushId uint32
func (id PushId) String() string {
return uint32ToString(uint32(id))
}
//-----------------------------------------------------------------------------
2025-01-27 13:10:03 +03:00
type PushPreview struct {
Id PushId `json:"id"`
Ctime uint32 `json:"ctime"`
Stime uint32 `json:"stime"`
Status int `json:"status"`
Info string `json:"info,omitempty"`
MaxVersion string `json:"maxVersion,omitempty"`
Platforms []uint32 `json:"platforms,omitempty"`
PlayersIds []uint32 `json:"playersIds,omitempty"`
Title string `json:"title"`
Message string `json:"message"`
Total int `json:"total"`
Sent int `json:"sent"`
Fails int `json:"fails"`
ForTest bool `json:"forTest,omitempty"`
}
//-----------------------------------------------------------------------------
2025-01-27 14:31:18 +03:00
type PushDef struct {
MaxVersion string `json:"maxVersion"`
Platforms []uint32 `json:"platforms"`
PlayersIds []uint32 `json:"playersIds"`
Stime uint32 `json:"stime"`
TextVariants []*TextVariant `json:"textVariants"`
ForTest bool `json:"forTest"`
ImageUrl string `json:"imageUrl"`
}
func (pushDef *PushDef) Validate() error {
if len(pushDef.TextVariants) == 0 {
return errors.New("No text variants")
}
return nil
}
func (pushDef *PushDef) Info() string {
var strs []string
if len(pushDef.Platforms) > 0 {
strs = append(strs, "Platforms: "+sliceUint32ToString(pushDef.Platforms, ","))
}
if len(pushDef.MaxVersion) > 0 {
strs = append(strs, "Max.ver: "+pushDef.MaxVersion)
}
if len(pushDef.PlayersIds) > 0 {
playersIdsStr := sliceUint32ToString(pushDef.PlayersIds, ",")
strs = append(strs, "Plr.ids: "+playersIdsStr)
}
return strings.Join(strs, "; ")
}
func sliceUint32ToString(nums []uint32, sep string) string {
strs := make([]string, 0, len(nums))
for _, num := range nums {
str := strconv.FormatUint(uint64(num), 10)
strs = append(strs, str)
}
return strings.Join(strs, sep)
}
//-----------------------------------------------------------------------------
type IncomingPushInfo struct {
Id int `json:"id"`
MaxVersion string `json:"maxVersion"`
Platforms []uint32 `json:"platforms"`
PlayersIds []uint32 `json:"playersIds"`
TextVariants []*TextVariant `json:"textVariants"`
ImageUrl string `json:"imageUrl"`
}
//-----------------------------------------------------------------------------
2025-01-27 12:09:39 +03:00
type TextVariant struct {
Lang int `json:"lang"`
Title string `json:"title"`
Message string `json:"message"`
}