From 3ab1191cd288b27371f12b8430d5a59115c2e839 Mon Sep 17 00:00:00 2001 From: Vladislav Veselskiy Date: Thu, 6 Feb 2025 18:12:54 +0300 Subject: [PATCH] Add file push_type.go. --- push_type.go | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 push_type.go diff --git a/push_type.go b/push_type.go new file mode 100644 index 0000000..322ac3d --- /dev/null +++ b/push_type.go @@ -0,0 +1,43 @@ +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 + } +}