Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions data_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
package groupme

import (
"encoding/json"
"regexp"
"time"
)
Expand All @@ -23,6 +24,20 @@ func (id ID) String() string {
return string(id)
}

// UnmarshalJSON also accepts numeric IDs, which GroupMe relays unchanged from
// clients that send them.
func (id *ID) UnmarshalJSON(data []byte) error {
if len(data) > 0 && data[0] != '"' {
var num json.Number
if err := json.Unmarshal(data, &num); err != nil {
return err
}
*id = ID(num)
return nil
}
return json.Unmarshal(data, (*string)(id))
}

// Timestamp is the number of seconds since the UNIX epoch
type Timestamp uint64

Expand Down
6 changes: 6 additions & 0 deletions real_time.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,12 @@ func NewPushSubscription(context context.Context) *PushSubscription {
return &r
}

func (r *PushSubscription) reportError(err error) {
for _, h := range r.handlers {
h.HandleError(err)
}
}

func (r *PushSubscription) AddHandler(h Handler) {
r.handlers = append(r.handlers, h)
}
Expand Down
6 changes: 5 additions & 1 deletion real_time_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package groupme

import (
"encoding/json"
"fmt"
"strconv"
)

Expand Down Expand Up @@ -59,7 +60,10 @@ func init() {
return
}
var out Message
if json.Unmarshal(b, &out) != nil || out.ID == "" {
if err := json.Unmarshal(b, &out); err != nil {
r.reportError(fmt.Errorf("failed to decode GroupMe push message: %w", err))
return
} else if out.ID == "" {
return
}
if out.ConversationID == "" {
Expand Down
Loading