From 1c93a9fa1faf02b714f5ceece759cd546b61a5a6 Mon Sep 17 00:00:00 2001 From: "V.G. Bulavintsev" Date: Wed, 23 Dec 2020 13:10:49 +0100 Subject: [PATCH] Fix remote preview for channels --- .../restapi/metadata_endpoint_base.py | 5 +++-- .../restapi/remote_query_endpoint.py | 2 ++ .../widgets/channelcontentswidget.py | 20 ++++++++++--------- 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/src/tribler-core/tribler_core/modules/metadata_store/restapi/metadata_endpoint_base.py b/src/tribler-core/tribler_core/modules/metadata_store/restapi/metadata_endpoint_base.py index 5b5a6bb01e4..53dd65cf1b9 100644 --- a/src/tribler-core/tribler_core/modules/metadata_store/restapi/metadata_endpoint_base.py +++ b/src/tribler-core/tribler_core/modules/metadata_store/restapi/metadata_endpoint_base.py @@ -1,9 +1,10 @@ from tribler_core.modules.metadata_store.serialization import CHANNEL_TORRENT, COLLECTION_NODE, REGULAR_TORRENT from tribler_core.restapi.rest_endpoint import RESTEndpoint +# This dict is used to translate JSON fields into the columns used in Pony for _sorting_. +# id_ is not in the list because there is not index on it, so we never really want to sort on it. json2pony_columns = { 'category': "tags", - 'id': "rowid", 'name': "title", 'size': "size", 'infohash': "infohash", @@ -16,7 +17,7 @@ 'health': 'HEALTH', } -# TODO: use the same representation for metatada nodes as in the database +# TODO: use the same representation for metadata nodes as in the database metadata_type_to_search_scope = { '': frozenset((REGULAR_TORRENT, CHANNEL_TORRENT, COLLECTION_NODE)), "channel": frozenset((CHANNEL_TORRENT, COLLECTION_NODE)), diff --git a/src/tribler-core/tribler_core/modules/metadata_store/restapi/remote_query_endpoint.py b/src/tribler-core/tribler_core/modules/metadata_store/restapi/remote_query_endpoint.py index 575110a6bf6..3817c6dc820 100644 --- a/src/tribler-core/tribler_core/modules/metadata_store/restapi/remote_query_endpoint.py +++ b/src/tribler-core/tribler_core/modules/metadata_store/restapi/remote_query_endpoint.py @@ -27,6 +27,8 @@ def sanitize_parameters(self, parameters): sanitized["metadata_type"] = [str(mt) for mt in sanitized["metadata_type"] if mt] if "channel_pk" in parameters: sanitized["channel_pk"] = parameters["channel_pk"] + if "origin_id" in parameters: + sanitized["origin_id"] = parameters["origin_id"] return sanitized diff --git a/src/tribler-gui/tribler_gui/widgets/channelcontentswidget.py b/src/tribler-gui/tribler_gui/widgets/channelcontentswidget.py index 2ba5f942f14..ab71db58898 100644 --- a/src/tribler-gui/tribler_gui/widgets/channelcontentswidget.py +++ b/src/tribler-gui/tribler_gui/widgets/channelcontentswidget.py @@ -176,8 +176,9 @@ def push_channels_stack(self, model): self.channels_stack.append(model) connect(self.model.info_changed, self.on_model_info_changed) - connect(self.window().core_manager.events_manager.received_remote_query_results, - self.model.on_new_entry_received) + connect( + self.window().core_manager.events_manager.received_remote_query_results, self.model.on_new_entry_received + ) connect(self.window().core_manager.events_manager.node_info_updated, self.model.update_node_info) with self.freeze_controls(): @@ -239,8 +240,9 @@ def reset_view(self): def disconnect_current_model(self): self.model.info_changed.disconnect() disconnect(self.window().core_manager.events_manager.node_info_updated, self.model.update_node_info) - disconnect(self.window().core_manager.events_manager.received_remote_query_results, - self.model.on_new_entry_received) + disconnect( + self.window().core_manager.events_manager.received_remote_query_results, self.model.on_new_entry_received + ) self.controller.unset_model() # Disconnect the selectionChanged signal def go_back(self, checked=False): @@ -288,12 +290,12 @@ def preview_clicked(self, checked=False): params = dict() if "public_key" in self.model.channel_info: - # This is a channel contents query, limit the search by channel_pk and torrent md type - params.update({'metadata_type': 'torrent', 'channel_pk': self.model.channel_info["public_key"]}) - elif self.model.text_filter: - # GigaChannel Community v1.0 does not support searching for text in a specific channel + # This is a channel contents query, limit the search by channel_pk and origin_id + params.update( + {'channel_pk': self.model.channel_info["public_key"], 'origin_id': self.model.channel_info["id"]} + ) + if self.model.text_filter: params.update({'txt_filter': self.model.text_filter}) - if self.model.hide_xxx is not None: params.update({'hide_xxx': self.model.hide_xxx}) if self.model.sort_by is not None: