简体   繁体   中英

Android Couchbase Lite get All Channels

salam
is it possible to get all channels that authenticate user is access to it?
I want to show user documents in the categories of channels

add "channels" peroperty in documents and then :

        com.couchbase.lite.View channelView = _database.getView("channels");
        channelView.setMap(new Mapper() {
            @Override
            public void map(Map<String, Object> document, Emitter emitter) {
                ArrayList<String> channel = (List) document.get("channel");
                String name = (String) document.get("ch_name");
                emitter.emit(channel, name);
            }
        }, "2");


private void startLiveQuery(com.couchbase.lite.View view) throws Exception {
    if (_liveQuery == null) {
        _liveQuery = view.createQuery().toLiveQuery();
        _liveQuery.addChangeListener(new LiveQuery.ChangeListener() {
            public void changed(final LiveQuery.ChangeEvent event) {
                new Thread(new Runnable() {
                    @Override
                    public void run() {
                        for (final Iterator<QueryRow> it = event.getRows(); it.hasNext(); ) {
                            QueryRow query = it.next();
                            _channel = (String) query.getKey();
                            _name = (String) query.getValue();
                        }
                    }
                }).start();
            }
        });
        _liveQuery.start();
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM