Skip to content
Snippets Groups Projects
Commit f18dd360 authored by inso's avatar inso
Browse files

Handle unpublished uid

parent f74a760b
Branches
Tags
No related merge requests found
...@@ -119,6 +119,13 @@ ...@@ -119,6 +119,13 @@
</property> </property>
</widget> </widget>
</item> </item>
<item>
<widget class="QPushButton" name="button_publish_uid">
<property name="text">
<string>Publish UID</string>
</property>
</widget>
</item>
<item> <item>
<widget class="QPushButton" name="button_membership"> <widget class="QPushButton" name="button_membership">
<property name="text"> <property name="text">
......
...@@ -275,6 +275,16 @@ class Account(QObject): ...@@ -275,6 +275,16 @@ class Account(QObject):
value += w.value(community) value += w.value(community)
return value return value
def published_uid(self, community):
'''
Check if this account identity is a member of a community
:param community: The target community of this request
:return: True if the account is a member of the target community
'''
self_person = Person.lookup(self.pubkey, community)
return self_person.published_uid(community)
def member_of(self, community): def member_of(self, community):
''' '''
Check if this account identity is a member of a community Check if this account identity is a member of a community
...@@ -283,6 +293,7 @@ class Account(QObject): ...@@ -283,6 +293,7 @@ class Account(QObject):
:return: True if the account is a member of the target community :return: True if the account is a member of the target community
''' '''
self_person = Person.lookup(self.pubkey, community) self_person = Person.lookup(self.pubkey, community)
logging.debug("Self person : {0}".format(self_person.uid))
return self_person.is_member(community) return self_person.is_member(community)
def send_selfcert(self, password, community): def send_selfcert(self, password, community):
......
...@@ -259,6 +259,30 @@ class Person(object): ...@@ -259,6 +259,30 @@ class Person(object):
return membership_data return membership_data
@cached
def published_uid(self, community):
try:
data = community.request(bma.wot.Lookup,
req_args={'search': self.pubkey},
cached=cached)
except ValueError as e:
if '404' in str(e):
return False
timestamp = 0
for result in data['results']:
if result["pubkey"] == self.pubkey:
uids = result['uids']
person_uid = ""
for uid_data in uids:
if uid_data["meta"]["timestamp"] > timestamp:
timestamp = uid_data["meta"]["timestamp"]
person_uid = uid_data["uid"]
if person_uid == self.uid:
return True
return False
@cached @cached
def is_member(self, community): def is_member(self, community):
''' '''
......
...@@ -24,12 +24,14 @@ class PersonsWatcher(Watcher): ...@@ -24,12 +24,14 @@ class PersonsWatcher(Watcher):
def watch(self): def watch(self):
logging.debug("Watching persons") logging.debug("Watching persons")
for p in Person._instances.values(): instances = Person._instances.copy()
for p in instances.values():
if not self.exiting: if not self.exiting:
for func in [Person.membership, for func in [Person.membership,
Person.is_member, Person.is_member,
Person.certifiers_of, Person.certifiers_of,
Person.certified_by]: Person.certified_by,
Person.published_uid]:
if not self.exiting: if not self.exiting:
if p.reload(func, self.community): if p.reload(func, self.community):
logging.debug("Change detected on {0} about {1}".format(p.pubkey, logging.debug("Change detected on {0} about {1}".format(p.pubkey,
......
...@@ -52,11 +52,24 @@ class CommunityTabWidget(QWidget, Ui_CommunityTabWidget): ...@@ -52,11 +52,24 @@ class CommunityTabWidget(QWidget, Ui_CommunityTabWidget):
self.table_identities.customContextMenuRequested.connect(self.identity_context_menu) self.table_identities.customContextMenuRequested.connect(self.identity_context_menu)
self.table_identities.sortByColumn(0, Qt.AscendingOrder) self.table_identities.sortByColumn(0, Qt.AscendingOrder)
try:
if self.account.published_uid(self.community):
if self.account.member_of(self.community): if self.account.member_of(self.community):
self.button_membership.setText("Renew membership") self.button_membership.setText("Renew membership")
self.button_publish_uid.hide()
self.button_leaving.show()
else: else:
self.button_membership.setText("Send membership demand") self.button_membership.setText("Send membership demand")
self.button_leaving.hide() self.button_leaving.hide()
self.button_publish_uid.hide()
else:
self.button_membership.hide()
self.button_leaving.hide()
self.button_publish_uid.show()
except PersonNotFoundError:
self.button_membership.hide()
self.button_leaving.hide()
self.button_publish_uid.show()
self.wot_tab = WotTabWidget(app, account, community, password_asker, self) self.wot_tab = WotTabWidget(app, account, community, password_asker, self)
self.tabs_information.addTab(self.wot_tab, QIcon(':/icons/wot_icon'), "WoT") self.tabs_information.addTab(self.wot_tab, QIcon(':/icons/wot_icon'), "WoT")
......
...@@ -217,9 +217,6 @@ Would you like to publish the key ?""").format(self.account.pubkey)) ...@@ -217,9 +217,6 @@ Would you like to publish the key ?""").format(self.account.pubkey))
"{0}".format(e), "{0}".format(e),
QMessageBox.Ok) QMessageBox.Ok)
else:
return
if self.community not in self.account.communities: if self.community not in self.account.communities:
self.account.add_community(self.community) self.account.add_community(self.community)
super().accept() super().accept()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment