Maxim Moiseev avatar Maxim Moiseev committed 5277747

anyString convertion tool added to be used in places where both quoted and unquoted strings are possible

Comments (0)

Files changed (2)

src/Common/Data.fs

         
     let string' = unquote << string
     
+    let anyString (token:JToken) =
+        if token.Type = JTokenType.String then
+            token |> string |> unquote
+        else
+            token |> string
+    
     let intBool (token:JToken) = 0 <> (token |> int)
 
     let UnixTimeStart = DateTime(1970, 1, 1)
          UnixTimeStart + TimeSpan.FromSeconds(x |> float)
 
     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
+        anyString token |> int64 |> fromUnixtime
 
     let parseComplexId id =
         let idRx = Regex("([0-9]+)_([\-0-9]+)")
     let userDescriptor (ts:JToken[]) =
         { new IUserDescriptor with
             override this.UserId = ts.[0] |> int64
-            override this.UserName = ts.[1] |> string
-            override this.PhotoUrl = ts.[2] |> string
-            override this.ThumbnailFileName = ts.[3] |> string
+            override this.UserName = ts.[1] |> anyString
+            override this.PhotoUrl = ts.[2] |> anyString
+            override this.ThumbnailFileName = ts.[3] |> anyString
             override this.Gender = ts.[4] |> int |> enum<Gender>
             override this.IsOnline = ts.[5] |> intBool
         }
         
     let message (ts:JToken[]) =
         { new IMessage with
-            override this.MessageId = ts.[0] |> string' |> int64
+            override this.MessageId = ts.[0] |> anyString |> int64
             override this.Timestamp = parseTimestamp ts.[1]
-            override this.Text = (Seq.toArray ts.[2]).[0] |> string'
+            override this.Text = (Seq.toArray ts.[2]).[0] |> anyString
             override this.Sender = userDescriptor (Seq.toArray ts.[3])
             override this.IsRead = ts.[5] |> intBool
         }

src/Linq2vk.Core.Tests/SimpleTests.cs

             var messages = _api.Inbox.Take(5);
             foreach (var msg in messages) {
                 Console.WriteLine("Message: {0}, From: {1}, Text:'{2}'", msg.MessageId, msg.Sender.UserName, msg.Text);
+                Console.WriteLine("Sent at: {0}", msg.Timestamp);
             }
         }
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.