From 915d599a11b8040c79f857e833e51cb85aa7bf73 Mon Sep 17 00:00:00 2001 From: vyneer Date: Wed, 6 Dec 2023 16:15:40 +0300 Subject: [PATCH] Revert "fix: subs and donos not unmarshalling" This reverts commit 54d2a65719f631d07ee5610f688eb7cbfdaa70ff. --- messageStructs.go | 37 ++++++++++++++++-------------------- parsers.go | 48 +++++------------------------------------------ 2 files changed, 21 insertions(+), 64 deletions(-) diff --git a/messageStructs.go b/messageStructs.go index be77cd2..3e5922b 100644 --- a/messageStructs.go +++ b/messageStructs.go @@ -145,11 +145,6 @@ type ( UUID string `json:"uuid"` } - eventUser struct { - User - CreatedDate string `json:"createdDate"` - } - // SubTier represents a dgg subscription tier SubTier struct { Tier int64 @@ -168,16 +163,16 @@ type ( } subscription struct { - Data string `json:"data"` - Timestamp int64 `json:"timestamp"` - Nick string `json:"nick"` - Tier int64 `json:"tier"` - TierLabel string `json:"tierLabel"` - Giftee string `json:"giftee"` - Quantity int64 `json:"quantity"` - User eventUser `json:"user"` - Recipient eventUser `json:"recipient"` - UUID string `json:"uuid"` + Data string `json:"data"` + Timestamp int64 `json:"timestamp"` + Nick string `json:"nick"` + Tier int64 `json:"tier"` + TierLabel string `json:"tierLabel"` + Giftee string `json:"giftee"` + Quantity int64 `json:"quantity"` + User User `json:"user"` + Recipient User `json:"recipient"` + UUID string `json:"uuid"` } // Donation represents a dgg donation message @@ -190,12 +185,12 @@ type ( } donation struct { - Data string `json:"data"` - Timestamp int64 `json:"timestamp"` - Nick string `json:"nick"` - Amount int64 `json:"amount"` - User eventUser `json:"user"` - UUID string `json:"uuid"` + Data string `json:"data"` + Timestamp int64 `json:"timestamp"` + Nick string `json:"nick"` + Amount int64 `json:"amount"` + User User `json:"user"` + UUID string `json:"uuid"` } // Ping represents a pong response from the server diff --git a/parsers.go b/parsers.go index 4ea3207..ca66eda 100644 --- a/parsers.go +++ b/parsers.go @@ -195,34 +195,9 @@ func parseSubscription(s string) (Subscription, error) { return Subscription{}, err } - userTime, err := time.Parse("2006-01-02T15:04:05-0700", sub.User.CreatedDate) - if err != nil { - return Subscription{}, err - } - - sender := User{ - ID: sub.User.ID, - Nick: sub.User.Nick, - Features: sub.User.Features, - CreatedDate: userTime, - Watching: sub.User.Watching, - } - - recipient := sender - - if sub.Recipient.Nick != "" { - recipientTime, err := time.Parse("2006-01-02T15:04:05-0700", sub.Recipient.CreatedDate) - if err != nil { - return Subscription{}, err - } - - recipient = User{ - ID: sub.Recipient.ID, - Nick: sub.Recipient.Nick, - Features: sub.Recipient.Features, - CreatedDate: recipientTime, - Watching: sub.Recipient.Watching, - } + recipient := sub.Recipient + if recipient.Nick == "" { + recipient = sub.User } tier := SubTier{ @@ -231,7 +206,7 @@ func parseSubscription(s string) (Subscription, error) { } subscription := Subscription{ - Sender: sender, + Sender: sub.User, Recipient: recipient, Timestamp: unixToTime(sub.Timestamp), Message: sub.Data, @@ -249,21 +224,8 @@ func parseDonation(s string) (Donation, error) { return Donation{}, err } - userTime, err := time.Parse("2006-01-02T15:04:05-0700", dono.User.CreatedDate) - if err != nil { - return Donation{}, err - } - - user := User{ - ID: dono.User.ID, - Nick: dono.User.Nick, - Features: dono.User.Features, - CreatedDate: userTime, - Watching: dono.User.Watching, - } - donation := Donation{ - Sender: user, + Sender: dono.User, Timestamp: unixToTime(dono.Timestamp), Message: dono.Data, Amount: dono.Amount,