diff --git a/src/sakia/gui/navigation/controller.py b/src/sakia/gui/navigation/controller.py index 873677558c8c761d664e507906e4391a56bfad23..14f359340b07562f9066b0d73365458abc662cad 100644 --- a/src/sakia/gui/navigation/controller.py +++ b/src/sakia/gui/navigation/controller.py @@ -64,6 +64,7 @@ class NavigationController(QObject): navigation.init_navigation() app.new_connection.connect(navigation.add_connection) app.view_in_wot.connect(navigation.open_wot_view) + app.identity_changed.connect(navigation.handle_identity_change) return navigation def open_network_view(self, _): @@ -112,6 +113,11 @@ class NavigationController(QObject): self.view.set_model(self.model) + def handle_identity_change(self, identity): + node = self.model.handle_identity_change(identity) + if node: + self.view.update_connection(node) + def handle_view_change(self, raw_data): """ Handle view change diff --git a/src/sakia/gui/navigation/identity/controller.py b/src/sakia/gui/navigation/identity/controller.py index cc796ac000486a033fb5f4ff7e467083dca304fa..142729495dcacca553a7c9eec638a1706463c208 100644 --- a/src/sakia/gui/navigation/identity/controller.py +++ b/src/sakia/gui/navigation/identity/controller.py @@ -62,6 +62,7 @@ class IdentityController(QObject): view.set_table_identities_model(table_model) view.table_certifiers.customContextMenuRequested['QPoint'].connect(identity.identity_context_menu) identity.view_in_wot.connect(app.view_in_wot) + app.identity_changed.connect(identity.handle_identity_change) return identity def identity_context_menu(self, point): diff --git a/src/sakia/gui/navigation/model.py b/src/sakia/gui/navigation/model.py index 825b277bacaa1ca7f948461a045c73bd9bd0f6cc..d77cfcd046355b6007fddfca0737811c8ee24ae8 100644 --- a/src/sakia/gui/navigation/model.py +++ b/src/sakia/gui/navigation/model.py @@ -23,6 +23,15 @@ class NavigationModel(QObject): self._current_data = None self._contacts_processor = ContactsProcessor.instanciate(self.app) + def handle_identity_change(self, identity): + for node in self.navigation[3]['children']: + if node['component'] == "Informations": + connection = node["misc"]["connection"] + if connection.pubkey == identity.pubkey and connection.uid == identity.uid: + icon = self.identity_icon(connection) + node["icon"] = icon + return node + def init_navigation_data(self): self.navigation = [ { @@ -80,14 +89,10 @@ class NavigationModel(QObject): else: title = connection.title() if connection.uid: - if self.identity_is_member(connection): - icon = ':/icons/member' - else: - icon = ':/icons/not_member' node = { 'title': title, 'component': "Informations", - 'icon': icon, + 'icon': self.identity_icon(connection), 'dependencies': { 'blockchain_service': self.app.blockchain_service, 'identities_service': self.app.identities_service, @@ -135,6 +140,12 @@ class NavigationModel(QObject): return node + def identity_icon(self, connection): + if self.identity_is_member(connection): + return ':/icons/member' + else: + return ':/icons/not_member' + def view_in_wot(self, connection): identity = self.app.identities_service.get_identity(connection.pubkey, connection.uid) self.app.view_in_wot.emit(identity) @@ -231,4 +242,4 @@ class NavigationModel(QObject): @staticmethod def copy_pubkey_to_clipboard_with_crc(connection): clipboard = QApplication.clipboard() - clipboard.setText(str(CRCPubkey.from_pubkey(connection.pubkey))) \ No newline at end of file + clipboard.setText(str(CRCPubkey.from_pubkey(connection.pubkey))) diff --git a/src/sakia/gui/navigation/view.py b/src/sakia/gui/navigation/view.py index 80124e08814fa0233755138688e6f2a3a6215d3c..a5159d6fb6c0cfb94dc96540d67dee49eeac0b66 100644 --- a/src/sakia/gui/navigation/view.py +++ b/src/sakia/gui/navigation/view.py @@ -49,3 +49,6 @@ class NavigationView(QFrame, Ui_Navigation): def add_connection(self, raw_data): self.tree_view.model().insert_node(raw_data) self.tree_view.expandAll() + + def update_connection(self, raw_data): + self.tree_view.model().modelReset.emit() diff --git a/src/sakia/services/identities.py b/src/sakia/services/identities.py index 36650aef0d10fcd01dbbbb020e5e30baf6f43657..efa457ff6298d8a53eb08d3c408d84a54eca0838 100644 --- a/src/sakia/services/identities.py +++ b/src/sakia/services/identities.py @@ -67,6 +67,9 @@ class IdentitiesService(QObject): return 0 def _get_connections_identities(self): + """ + :rtype: List of sakia.data.entities.Identity + """ connections = self._connections_processor.connections_with_uids(self.currency) identities = [] for c in connections: @@ -278,6 +281,21 @@ class IdentitiesService(QObject): for idty in identities: self._identities_processor.insert_or_update_identity(idty) + def _parse_median_time(self, block): + """ + Parse revoked pubkeys found in a block and refresh local data + + :param duniterpy.documents.Block block: the block received + :return: list of identities updated + """ + identities = [] + connections_identities = self._get_connections_identities() + parameters = self._blockchain_processor.parameters(block.currency) + for idty in connections_identities: + if idty.member and idty.membership_timestamp + parameters.ms_validity < block.mediantime: + identities.append(idty) + return identities + def _parse_revocations(self, block): """ Parse revoked pubkeys found in a block and refresh local data @@ -423,6 +441,7 @@ class IdentitiesService(QObject): need_refresh += self._parse_identities(block) need_refresh += self._parse_memberships(block) need_refresh += await self._parse_certifications(block) + need_refresh += self._parse_median_time(block) return set(need_refresh) async def handle_new_blocks(self, blocks):