Commits

Maxim Moiseev committed e0f5dc1

empty statuses parsing fixed

Comments (0)

Files changed (1)

src/Linq2vk.Core/Data.fs

     open Newtonsoft.Json.Linq
         
     let parseComplexId id =
-        let idRx = Regex("([0-9]+)_([0-9+])")
+        let idRx = Regex("([0-9]+)_([\-0-9]+)")
         let m = idRx.Match(id)
         let parseGroup (i:int) =
             m.Groups.[i].Value |> int64
         if m.Success then 
             (parseGroup 1, parseGroup 2)
         else
-            raise <| ArgumentException("Invalid complex id format")
+            raise <| ArgumentException(sprintf "Invalid complex id format: %s" id)
 
     let friend (ts:JToken array) =
         { new IFriend with 
         }
 
     let status (ts:JToken array) =
+        let parseTimestamp (token:JToken) =
+            // This is the UserAPI! Sometimes timestamp is a number,
+            // sometimes it is a string containing that number
+            let timestamp =
+                if token.Type = JTokenType.String then
+                    token |> string'
+                else
+                    token |> string
+            timestamp |> int64 |> fromUnixtime
+    
         let (_, statusId) = parseComplexId (ts.[0] |> string)
         { new IStatus with
             override this.Id = ts.[0] |> string
             override this.Reserved = 0
             override this.Name = ts.[3] |> string'
             override this.Timestamp = 
-                let t = ts.[4]
-                // This is the UserAPI! Sometimes timestamp is a number,
-                // sometimes it is a string containing that number
-                let timestamp =
-                    if t.Type = JTokenType.String then
-                        t |> string'
-                    else
-                        t |> string
-                timestamp |> int64 |> fromUnixtime
-                        
+                if statusId <> -1L then
+                    parseTimestamp ts.[4]
+                else
+                    DateTime.MinValue
             override this.Text = ts.[5] |> string'
         }