webim / webim-client-sdk-ios

Webim Mobile SDK for iOS (Swift)
MIT License
5 stars 25 forks source link

Incorrect timestamp of message #1

Closed Beniamiiin closed 7 years ago

Beniamiiin commented 7 years ago

Function Message.getTime() return incorrect timestamp. Also, I'm sure that you have a mistake not only in this function. Please, check all places where you use timestamps.

For example, look at this log:

Response: 
https://demo.webim.ru/l/v/m/history?page-id=22ead2cb653e4ff2a34a83ef328dd1b9&auth-token=2964a3906518490c8343b231d1008c6d

JSON: 
{
  "result" : "ok",
  "data" : {
    "hasMore" : true,
    "revision" : "1510656906966707",
    "messages" : [
      {
        "avatar" : null,
        "chatId" : "2026",
        "authorId" : null,
        "data" : null,
        "id" : "16233",
        "ts_m" : 1510149539705190,
        "text" : "Оператор закрыл диалог",
        "clientSideId" : "bd63a8882417434a85ed9a5f2120bcdb",
        "kind" : "info",
        "name" : ""
      }
    ]
  }
}

Mind you, values of revision and ts_m are incorrect they have to be 1510656906 and 1510149539. "revision" : "1510656906966707" - it looks like 1510656906.966707. I think that way because in this response I see that format of timestamp:

Response: 
https://demo.webim.ru/l/v/m/delta?page-id=22ead2cb653e4ff2a34a83ef328dd1b9&since=46&auth-token=2964a3906518490c8343b231d1008c6d&ts=532350245371

JSON: 
{
  "revision" : 47,
  "deltaList" : [
    {
      "id" : "8e6e1a020b1d4a4ebad827db93a253a6_8",
      "data" : {
        "avatar" : null,
        "authorId" : null,
        "ts" : 1510657473.682209,
        "sessionId" : "8e6e1a020b1d4a4ebad827db93a253a6",
        "id" : "8e6e1a020b1d4a4ebad827db93a253a6_8",
        "text" : "test message",
        "clientSideId" : "eZqZ4yEQRtaOahG1gfhdC8mDw0M8nv0C",
        "kind" : "visitor",
        "name" : "Никита"
      },
      "event" : "add",
      "objectType" : "CHAT_MESSAGE"
    }
  ]
}
webim commented 7 years ago

Hi @Beniamiiin !

Thanks for your report!

As we just have checked getTime() method is working properly: it returns the correct timestamp in milliseconds. So you can try out this code and get the right Date object: let messageDate = Date(timeIntervalSince1970: TimeInterval(message.getTime() / 1000))

This image is representing a result of using this code: 2017-11-14 16 27 15

You don't have to be worried about Webim server responses' content because it is used only by internal entities of the library.

Have a nice day!