Compare commits
No commits in common. "main" and "v1.0.8" have entirely different histories.
|
@ -2,9 +2,6 @@ package push_common
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
|
||||||
"io"
|
|
||||||
"net/http"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
@ -98,27 +95,6 @@ type TextVariant struct {
|
||||||
Message string `json:"message"`
|
Message string `json:"message"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func FindTextVariantByLang(textVariants []*TextVariant, lang int) *TextVariant {
|
|
||||||
for _, textVariant := range textVariants {
|
|
||||||
if textVariant.Lang == lang {
|
|
||||||
return textVariant
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func ReadTextVariantsFromRequest(request *http.Request, textVariants *[]*TextVariant) error {
|
|
||||||
b, err := io.ReadAll(request.Body)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if b == nil {
|
|
||||||
return errors.New("Can not read text variants. Request body bytes is nil.")
|
|
||||||
}
|
|
||||||
|
|
||||||
return json.Unmarshal(b, textVariants)
|
|
||||||
}
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
type PushRequest struct {
|
type PushRequest struct {
|
||||||
|
@ -227,65 +203,3 @@ type PushPayload struct {
|
||||||
ImageUrl string `json:"imageUrl"`
|
ImageUrl string `json:"imageUrl"`
|
||||||
TextVariants []*TextVariant `json:"textVariants"`
|
TextVariants []*TextVariant `json:"textVariants"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func ReadPayloadFromRequest(request *http.Request, payload *PushPayload) error {
|
|
||||||
b, err := io.ReadAll(request.Body)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if b == nil {
|
|
||||||
return errors.New("Can not read text variants. Request body bytes is nil.")
|
|
||||||
}
|
|
||||||
|
|
||||||
return json.Unmarshal(b, payload)
|
|
||||||
}
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
|
|
||||||
type Push struct {
|
|
||||||
Id uint32 `json:"id"`
|
|
||||||
Status int `json:"status"`
|
|
||||||
Ctime uint32 `json:"ctime"`
|
|
||||||
Mtime uint32 `json:"mtime"`
|
|
||||||
Ttl uint32 `json:"ttl"`
|
|
||||||
Stime uint32 `json:"stime"`
|
|
||||||
Srtime uint32 `json:"srtime"`
|
|
||||||
Info string `json:"info"`
|
|
||||||
Label string `json:"label"`
|
|
||||||
MaxVersion string `json:"maxVersion,omitempty"`
|
|
||||||
Platforms []uint32 `json:"platforms,omitempty"`
|
|
||||||
PlayersIds []uint32 `json:"playersIds,omitempty"`
|
|
||||||
Title string `json:"title"`
|
|
||||||
Message string `json:"message"`
|
|
||||||
TextVariants []*TextVariant `json:"textVariants"` // For incoming push only.
|
|
||||||
Jobs []*PushJob `json:"jobs"` // Incoming push has no jobs.
|
|
||||||
Total int `json:"total"`
|
|
||||||
Sent int `json:"sent"` // Incoming push has not field "Sent".
|
|
||||||
Fails int `json:"fails"` // Incoming push has not field "Fails".
|
|
||||||
ForTest bool `json:"forTest,omitempty"`
|
|
||||||
ImageUrl string `json:"imageUrl,omitempty"`
|
|
||||||
}
|
|
||||||
|
|
||||||
func (push *Push) IsDone() bool {
|
|
||||||
return push.Total == (push.Sent + push.Fails)
|
|
||||||
}
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
|
|
||||||
type JobId uint32
|
|
||||||
|
|
||||||
type PushJob struct {
|
|
||||||
Id JobId `json:"id"`
|
|
||||||
Platform Platform `json:"platform"`
|
|
||||||
Message string `json:"message"`
|
|
||||||
Title string `json:"title"`
|
|
||||||
Language int `json:"language"`
|
|
||||||
Utc_delta int `json:"utc_delta"`
|
|
||||||
Total int `json:"total"`
|
|
||||||
Sent int `json:"sent"`
|
|
||||||
Fails int `json:"fails"`
|
|
||||||
}
|
|
||||||
|
|
||||||
func (job *PushJob) IsDone() bool {
|
|
||||||
return job.Total == (job.Sent + job.Fails)
|
|
||||||
}
|
|
||||||
|
|
43
push_type.go
43
push_type.go
|
@ -1,43 +0,0 @@
|
||||||
package push_common
|
|
||||||
|
|
||||||
import "strings"
|
|
||||||
|
|
||||||
type PushType uint8
|
|
||||||
|
|
||||||
const (
|
|
||||||
PushType_User PushType = 1
|
|
||||||
PushType_Auto PushType = 2
|
|
||||||
)
|
|
||||||
|
|
||||||
func PushTypeToString(pt PushType) string {
|
|
||||||
switch pt {
|
|
||||||
case PushType_User:
|
|
||||||
return "user"
|
|
||||||
case PushType_Auto:
|
|
||||||
return "auto"
|
|
||||||
}
|
|
||||||
return "error"
|
|
||||||
}
|
|
||||||
|
|
||||||
const AutoPushInfoPrefix = "#"
|
|
||||||
|
|
||||||
// Автоматическое пуш-оповещение - пуш-оповещение,
|
|
||||||
// которое было создано автоматически (а не пользователем инсайдера).
|
|
||||||
func IsAutoPush(pushInfo string) bool {
|
|
||||||
return strings.HasPrefix(pushInfo, AutoPushInfoPrefix)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Пользовательское пуш-оповещение - пуш-оповещение,
|
|
||||||
// которое было создано пользователем инсайдера (а не автоматически).
|
|
||||||
func IsUserPush(pushInfo string) bool {
|
|
||||||
isAuto := IsAutoPush(pushInfo)
|
|
||||||
return !isAuto
|
|
||||||
}
|
|
||||||
|
|
||||||
func ConvertPushInfoToType(pushInfo string) PushType {
|
|
||||||
if IsAutoPush(pushInfo) {
|
|
||||||
return PushType_Auto
|
|
||||||
} else {
|
|
||||||
return PushType_User
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue