This commit is contained in:
parent
019a57e7cf
commit
dd7a39a158
@ -24,6 +24,7 @@ type userSubscription struct {
|
||||
AutoNotify bool
|
||||
}
|
||||
|
||||
// subscriptions are stored in format ChatID(int64),AutoNotify(bool):ChatID,AutoNotify
|
||||
func getUserSubscribedChats(username string) []userSubscription {
|
||||
|
||||
serializedSubscriptions, exists := shared.Users.Get(username, "subscribed_chats")
|
||||
@ -32,13 +33,37 @@ func getUserSubscribedChats(username string) []userSubscription {
|
||||
}
|
||||
|
||||
subscriptions := []userSubscription{}
|
||||
for _, chatID := range strings.Split(serializedSubscriptions, ":") {
|
||||
if id, err := strconv.ParseInt(chatID, 10, 64); err == nil {
|
||||
for _, sub := range strings.Split(serializedSubscriptions, ":") {
|
||||
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{
|
||||
ChatID: id,
|
||||
ChatID: chatID,
|
||||
AutoNotify: true,
|
||||
})
|
||||
continue
|
||||
}
|
||||
|
||||
autoNotify, err := strconv.ParseBool(splitedSub[1])
|
||||
if err != nil {
|
||||
autoNotify = true
|
||||
}
|
||||
|
||||
subscriptions = append(subscriptions, userSubscription{
|
||||
ChatID: chatID,
|
||||
AutoNotify: autoNotify,
|
||||
})
|
||||
}
|
||||
|
||||
return subscriptions
|
||||
@ -48,7 +73,13 @@ func setUserSubscribedChats(username string, subscriptions []userSubscription) {
|
||||
|
||||
subs := make([]string, len(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, ":"))
|
||||
|
Loading…
Reference in New Issue
Block a user