package push_common import ( "strconv" "strings" "git.bit5.ru/backend/errors" ) type PushId uint32 func (id PushId) String() string { return uint32ToString(uint32(id)) } //----------------------------------------------------------------------------- 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"` } //----------------------------------------------------------------------------- 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"` } //----------------------------------------------------------------------------- type TextVariant struct { Lang int `json:"lang"` Title string `json:"title"` Message string `json:"message"` }