mirror of
https://git.klmp200.net/ALFRED/ALFRED.git
synced 2025-01-18 10:36:44 +01:00
Encode auto notify into the user data
This commit is contained in:
parent
019a57e7cf
commit
dd7a39a158
@ -24,6 +24,7 @@ type userSubscription struct {
|
|||||||
AutoNotify bool
|
AutoNotify bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// subscriptions are stored in format ChatID(int64),AutoNotify(bool):ChatID,AutoNotify
|
||||||
func getUserSubscribedChats(username string) []userSubscription {
|
func getUserSubscribedChats(username string) []userSubscription {
|
||||||
|
|
||||||
serializedSubscriptions, exists := shared.Users.Get(username, "subscribed_chats")
|
serializedSubscriptions, exists := shared.Users.Get(username, "subscribed_chats")
|
||||||
@ -32,13 +33,37 @@ func getUserSubscribedChats(username string) []userSubscription {
|
|||||||
}
|
}
|
||||||
|
|
||||||
subscriptions := []userSubscription{}
|
subscriptions := []userSubscription{}
|
||||||
for _, chatID := range strings.Split(serializedSubscriptions, ":") {
|
for _, sub := range strings.Split(serializedSubscriptions, ":") {
|
||||||
if id, err := strconv.ParseInt(chatID, 10, 64); err == nil {
|
splitedSub := strings.Split(sub, ",")
|
||||||
|
|
||||||
|
// malformated
|
||||||
|
if len(splitedSub) == 0 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
chatID, err := strconv.ParseInt(splitedSub[0], 10, 64)
|
||||||
|
if err != nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
// only ChatID
|
||||||
|
if len(splitedSub) == 1 {
|
||||||
subscriptions = append(subscriptions, userSubscription{
|
subscriptions = append(subscriptions, userSubscription{
|
||||||
ChatID: id,
|
ChatID: chatID,
|
||||||
AutoNotify: true,
|
AutoNotify: true,
|
||||||
})
|
})
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
autoNotify, err := strconv.ParseBool(splitedSub[1])
|
||||||
|
if err != nil {
|
||||||
|
autoNotify = true
|
||||||
|
}
|
||||||
|
|
||||||
|
subscriptions = append(subscriptions, userSubscription{
|
||||||
|
ChatID: chatID,
|
||||||
|
AutoNotify: autoNotify,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
return subscriptions
|
return subscriptions
|
||||||
@ -48,7 +73,13 @@ func setUserSubscribedChats(username string, subscriptions []userSubscription) {
|
|||||||
|
|
||||||
subs := make([]string, len(subscriptions))
|
subs := make([]string, len(subscriptions))
|
||||||
for i, sub := range subscriptions {
|
for i, sub := range subscriptions {
|
||||||
subs[i] = strconv.FormatInt(sub.ChatID, 10)
|
subs[i] = strings.Join(
|
||||||
|
[]string{
|
||||||
|
strconv.FormatInt(sub.ChatID, 10),
|
||||||
|
strconv.FormatBool(sub.AutoNotify),
|
||||||
|
},
|
||||||
|
",",
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
shared.Users.Set(username, "subscribed_chats", strings.Join(subs, ":"))
|
shared.Users.Set(username, "subscribed_chats", strings.Join(subs, ":"))
|
||||||
|
Loading…
Reference in New Issue
Block a user