tinode / chat

Instant messaging platform. Backend in Go. Clients: Swift iOS, Java Android, JS webapp, scriptable command line; chatbots
GNU General Public License v3.0
11.94k stars 1.87k forks source link

Problem performing fnd on user tag #111

Closed jaylevin closed 6 years ago

jaylevin commented 6 years ago

Hello, I have a small clarification question regarding https://github.com/tinode/chat/blob/master/docs/API.md#fnd-and-tags-finding-users-and-topics.

Here is what I am doing:

  1. User subscribes to fnd topic, does a {set topic="fnd"} on public field to person@example.com. There is another user in database with tags:[person@example.com]
  2. Then finally (and unsuccessfully): {get topic="fnd" what="sub"}

I noticed that by setting the public field of the user's fnd topic to the tag being searched for violates the condition that the public field is a vCard? Currently I am just setting the entire public field to the tag being searched for, no email: prefix... Is this where I go wrong?

Here is my server log.. Obviously something is failing with my {set}, no clue what it could be

2018/06/25 11:24:52 set:<topic:"fnd" query:<desc:<public:"person@example.com" > > > 2018/06/25 11:24:52 s.set: processing 'set' 2018/06/25 11:24:52 s.set: sending to topic 2018/06/25 11:24:52 topic[fndxQy56wpOmGk] meta.Set.Desc failed: {set} generated no update to DB 2018/06/25 11:24:52 grpc: writing message to stream ctrl:<topic:"fnd" code:304 text:"not modified" > 2018/06/25 11:24:52 get:<topic:"fnd" query:<what:"sub" > > 2018/06/25 11:24:52 s.get: processing 'get.sub' 2018/06/25 11:24:52 grpc: writing message to stream ctrl:<topic:"fnd" code:200 text:"ok" >

Thank you for your help

or-else commented 6 years ago

I cannot reproduce. I just tested it on the public server at api.tinode.co and it worked as expected:

[19:14:39:899] out: {"set":{"id":"113377","topic":"fnd","desc":{"public":"a@example.com"}}}
tinode.js:895 [19:14:40:068] in: {"ctrl":{"id":"113377","topic":"fnd","code":200,"text":"ok","ts":"2018-06-25T19:14:39.990Z"}}
tinode.js:895 [19:14:40:073] out: {"get":{"id":"113378","topic":"fnd","what":"sub"}}
tinode.js:895 [19:14:40:260] in: {"meta":{"id":"113378","topic":"fnd","ts":"2018-06-25T19:14:40.169Z","sub":[{"updated":"2018-06-25T19:14:12.263Z","acs":{"mode":0},"public":{"fn":"Alice Johnson","photo":{"data":"<9760, bytes: /9j/4AAQSkZJ...kPDXadVL/9k=>","type":"jpg"}},"private":["a@example.com"],"user":"usrnHOIUmeyZEg"}]}}

You can try it yourself. I've added a tag a@example.com to Alice. You can login as another user, for instance as Bob, then search for a@example.com.

Can you show how to reproduce the issue with api.tinode.co?

topic[fndxQy56wpOmGk] meta.Set.Desc failed: {set} generated no update to DB

That's likely not an error. It means that you are not modifying the field. It must have held the same value before.

field of the user's fnd topic to the tag being searched for violates the condition that the public field is a vCard

It's supposed to be that way for fnd.

jaylevin commented 6 years ago

I am unable to reproduce on api.tinode.co, but still am confused to where I'm going wrong... Whatever is triggering that error seems to be my problem though.

What I don't get is the docs explicitly say that the public field of the fnd topic is ephemeral, which means performing a {set} will not modify anything in the DB... hence this error seems like expected behavior to me: topic[fndxQy56wpOmGk] meta.Set.Desc failed: {set} generated no update to DB.

What confuses me is that that error is not present in your reproduction above. Why is this?

or-else commented 6 years ago

I would suggest to verify basics: make sure the other user actually has person@example.com set, and not, for instance email:person@examle.com or preson@exmaple.com. Make sure fnd works for existing tags. See if you can reproduce the bug using your server and stock web client.

or-else commented 6 years ago

Is it possible that you are using an older server with the newer client or vice versa?

Could you please start a new server instance, execute the steps which lead to the error and show the entire server log.

or-else commented 6 years ago

OK, I can reproduce the issue now. It's grpc-specific. Looking into it.

or-else commented 6 years ago

So, it's not exactly a bug but a side effect of using protocol buffers.

Protobufs don't support generic objects. One can't create an object (or a dictionary or a map) and have protobuf correctly serialize/deserialize it if the object is not defined in advance in a .proto file. But Tinode uses such generic objects in a few places. To pass a generic object through protobuf it's first converted into json then sent as an array of bytes. When you set public to person@examle.com you set it as a literal string person@examle.com which is not valid json and consequently server fails to parse it. There was no reporting of such errors on the server. I added it now. Send it as a quoted string "person@examle.com". Then it will be parsed correctly. Likewise, when you receive a generic object from server you must deserialize it from json.

I've added appropriate conversion to tn-cli (see large-files branch).

jaylevin commented 6 years ago

Works like a charm. Thank you very much!