From 294b822eeede5300c4d861a92d153eccc23edd71 Mon Sep 17 00:00:00 2001
From: inso <insomniak.fr@gmaiL.com>
Date: Sat, 30 Jul 2016 15:03:04 +0200
Subject: [PATCH] Fix implicit revocation time

---
 src/sakia/core/registry/identity.py | 17 +++++++++++++++++
 src/sakia/gui/community_view.py     |  6 +++---
 2 files changed, 20 insertions(+), 3 deletions(-)

diff --git a/src/sakia/core/registry/identity.py b/src/sakia/core/registry/identity.py
index 2a2cb62d..fcc16720 100644
--- a/src/sakia/core/registry/identity.py
+++ b/src/sakia/core/registry/identity.py
@@ -465,6 +465,23 @@ class Identity(QObject):
         certified_list = await self.certified_by(identities_registry, community)
         return await self._unique_valid(certified_list, community)
 
+    async def identity_revocation_time(self, community):
+        """
+        Get the remaining time before identity implicit revocation
+        :param sakia.core.Community community: the community
+        :return: the remaining time
+        :rtype: int
+        """
+        membership = await self.membership(community)
+        join_block = membership['blockNumber']
+        block = await community.get_block(join_block)
+        join_date = block['medianTime']
+        parameters = await community.parameters()
+        # revocation date is join_date + 1 sigvalidity (expiration date)  + 2*sigvalidity
+        revocation_date = join_date + 3*parameters['sigValidity']
+        current_time = time.time()
+        return revocation_date - current_time
+
     async def membership_expiration_time(self, community):
         """
         Get the remaining time before membership expiration
diff --git a/src/sakia/gui/community_view.py b/src/sakia/gui/community_view.py
index 57fbc2c2..53f47851 100644
--- a/src/sakia/gui/community_view.py
+++ b/src/sakia/gui/community_view.py
@@ -212,14 +212,14 @@ The publication of this document will remove your identity from the network.</p>
         try:
             person = await self.app.identities_registry.future_find(self.app.current_account.pubkey, self.community)
             expiration_time = await person.membership_expiration_time(self.community)
+            revokation_time = await person.identity_revocation_time(self.community)
             parameters = await self.community.parameters()
             sig_validity = parameters['sigValidity']
             warning_expiration_time = int(sig_validity / 3)
             will_expire_soon = (expiration_time < warning_expiration_time)
-            revokation_deadline = expiration_time + 2*sig_validity
-            revokation_soon = (time.time() > revokation_deadline)
+            revokation_soon = (revokation_time < 2*warning_expiration_time)
             if revokation_soon:
-                days = int((revokation_deadline - time.time()) / 3600 / 24)
+                days = int(revokation_time / 3600 / 24)
                 if 'warning_revokation' not in self.status_info:
                     self.status_info.append('warning_revokation')
 
-- 
GitLab