weixin_39997443
weixin_39997443
2021-01-12 08:44

Search Plugin Bug

There is no way to set ACS from search plugin.

This is the result of problem. Web client shows disabled icons near user name. image

Is this a bug report of a feature request?

  • [x] Bug report
  • [ ] Feature

Your environment

Server-side

  • [x] Own setup:
  • platform Linux
  • version of tinode server 0.16
  • database backend mysql
  • gRPC/1.29.0-dev

Client-side

  • [x] TinodeWeb/tinodejs: javascript client
  • Version of the client 0.16.3

Steps to reproduce

Developing search plugin. Regarding this doc: https://gowalker.org/github.com/tinode/chat/pbx#PluginClient Find should return type SearchFound whitch should contain type TopicSub list in result. For TopicSub we can set AccessMode (https://gowalker.org/github.com/tinode/chat/pbx#AccessMode) that have want and given properties. Fragments for search plugin python code


class Plugin(pbx.PluginServicer):
    def Find(
            self,
            event,
            context  # type: grpc.RpcContext
    ):
        sf = pb.SearchFound()

        query = event.query

        cursor = get_cursor()
        term = '%' + query + '%'

        user_id = event.user_id[3:]
        user_id_int = decode_uid(user_id)

        cursor.execute(SEARCH_QUERY, (term, user_id_int))

        for row in cursor.fetchall():
            ts = pb.TopicSub()
            ts.user_id = encode_uid(row['id'])
            ts.public = row['public']

            access = json.loads(row['access'])

            ts.acs.given = access['Auth'].encode('utf-8')
            ts.acs.want = access['Anon'].encode('utf-8')

            ts.updated_at = int(row['updatedat'].strftime('%s')) * 1000

            sf.result.append(ts)
        cursor.close()

        sf.status = pb.RespCode.RESPOND

        return sf

And now we go to server code Method pluginFind passes response to pbSubSliceDeserialize from pbconverter.go (https://github.com/tinode/chat/blob/8d77b2be39a24e85f125e09e247ab17437df7878/server/pbconverter.go#L832) Server sets ModeGiven and ModeWant. After that here in topic.go (https://github.com/tinode/chat/blob/8d77b2be39a24e85f125e09e247ab17437df7878/server/topic.go#L1828) server is trying to read default access if topic category is find. So there is no way to set acs for search results from plugin.

Expected behaviour

There should be ability to set ACS for search results from plugin.

Actual behaviour

There is no way to set ACS for search results from plugin.

Client-side log


{"meta":{"id":"116792","topic":"fnd","ts":"2020-03-12T13:49:30.486Z","sub":[{"updated":"2020-03-11T14:45:07Z","acs":{"mode":"N"},"public":{"fn":"Generated test_1"},"user":"usroTqZNkdr74w"}]}}

该提问来源于开源项目:tinode/chat

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

5条回答

  • weixin_39997443 weixin_39997443 4月前

    The problem is that default search returns list of subscriptions with ACS mode from user config (in my case JRWPA)

    
    {"meta":{"id":"123237","topic":"fnd","ts":"2020-03-12T17:12:48.159Z","sub":[{"updated":"2020-03-11T16:45:00.401Z","acs":{"mode":"JRWPA"},"public":{"fn":"Generated test"},"private":["test"],"user":"usr0R4O4rKOL0c"}]}}
    

    And there is no possibility to set any ACS mode from search plugin. So it will always show N.

    点赞 评论 复制链接分享
  • weixin_39846553 weixin_39846553 4月前

    OK, I see your point. That's indeed an oversight. I'll try to fix it in the next release.

    点赞 评论 复制链接分享
  • weixin_39846553 weixin_39846553 4月前

    Done: https://github.com/tinode/chat/commit/41f95284684c1f7e6e749aa0bc815b389706c8b2

    点赞 评论 复制链接分享
  • weixin_39846553 weixin_39846553 4月前

    It's been released as 0.16.4. Do you have further questions?

    点赞 评论 复制链接分享
  • weixin_39846553 weixin_39846553 4月前

    Actually it is not a bug. Maybe it's a logical problem or some misunderstanding.

    What exactly do you expect to see in ModeGiven and ModeWant? These values are present only for existing subscriptions. I.e. if Bob and Alice have a p2p topic, then ModeWant and ModeGiven are defined for them. Otherwise they are undefined. 'Find' assumes that you are searching for new contacts, consequently, these contacts generally don't have a p2p topic with the current user (other than by chance) and it does not return ModeGiven/ModeWant because they are usually N.

    defacs on the other hand are useful. They tell you what kind of connection you can create with the new user/topic.

    点赞 评论 复制链接分享

相关推荐