@@ -145,16 +145,21 @@ func DecodePollEvents(data []byte) ([]PollEvent, string, error) {
145145 case map [string ]any :
146146 cursor := firstString (value , "next_cursor" , "nextCursor" , "cursor" , "after" , "after_id" , "afterId" )
147147 if nested , ok := firstAny (value , "events" , "items" , "messages" , "deliveries" , "data" ); ok {
148- if nestedMap , ok := nested .(map [string ]any ); ok {
149- if nestedEvents , ok := firstAny (nestedMap , "events" , "items" , "messages" , "deliveries" ); ok {
150- nested = nestedEvents
151- }
152- if cursor == "" {
153- cursor = firstString (nestedMap , "next_cursor" , "nextCursor" , "cursor" , "after" , "after_id" , "afterId" )
154- }
148+ events , nestedCursor , decoded := decodePollEventValue (nested )
149+ if cursor == "" {
150+ cursor = nestedCursor
155151 }
156- if list , ok := nested .([]any ); ok {
157- return decodePollEventList (list ), cursor , nil
152+ if decoded && (len (events ) > 0 || nestedCursor != "" ) {
153+ return events , cursor , nil
154+ }
155+ }
156+ if nested , ok := firstAny (value , "event" , "remote_event" , "remoteEvent" , "delivery" , "payload" ); ok {
157+ events , nestedCursor , decoded := decodePollEventValue (nested )
158+ if cursor == "" {
159+ cursor = nestedCursor
160+ }
161+ if decoded && (len (events ) > 0 || nestedCursor != "" ) {
162+ return events , cursor , nil
158163 }
159164 }
160165 if event , ok := decodePollEventMap (value ); ok {
@@ -166,6 +171,30 @@ func DecodePollEvents(data []byte) ([]PollEvent, string, error) {
166171 }
167172}
168173
174+ func decodePollEventValue (value any ) ([]PollEvent , string , bool ) {
175+ switch typed := value .(type ) {
176+ case []any :
177+ return decodePollEventList (typed ), "" , true
178+ case map [string ]any :
179+ cursor := firstString (typed , "next_cursor" , "nextCursor" , "cursor" , "after" , "after_id" , "afterId" )
180+ if nested , ok := firstAny (typed , "events" , "items" , "messages" , "deliveries" ); ok {
181+ events , nestedCursor , decoded := decodePollEventValue (nested )
182+ if cursor == "" {
183+ cursor = nestedCursor
184+ }
185+ if decoded {
186+ return events , cursor , true
187+ }
188+ }
189+ if event , ok := decodePollEventMap (typed ); ok {
190+ return []PollEvent {event }, cursor , true
191+ }
192+ return nil , cursor , cursor != ""
193+ default :
194+ return nil , "" , false
195+ }
196+ }
197+
169198func WritePumpState (path string , state PumpState ) error {
170199 if path == "" {
171200 return os .ErrInvalid
0 commit comments