From d2cbe9140189381d9f5e3df92d6c5ed24c56d413 Mon Sep 17 00:00:00 2001 From: quadrismegistus Date: Thu, 17 Sep 2020 20:57:07 +0100 Subject: [PATCH] komrade update! --- komrade/backend/keymaker.py | 8 ++--- komrade/backend/komrades.py | 38 ++++++++++++++++++---- komrade/backend/the_operator.py | 47 +++++++++------------------ komrade/cli/cli.py | 57 +++++++++++++++++---------------- 4 files changed, 80 insertions(+), 70 deletions(-) diff --git a/komrade/backend/keymaker.py b/komrade/backend/keymaker.py index af923e4..de5ad5d 100644 --- a/komrade/backend/keymaker.py +++ b/komrade/backend/keymaker.py @@ -267,20 +267,20 @@ class Keymaker(Logger): def find_pubkey(self,name=None): - self.log('<-',name) + # self.log('<-',name) if not name: name=self.name if self.name==name and 'pubkey' in self._keychain and self._keychain['pubkey']: pk=self._keychain['pubkey'] return KomradeAsymmetricPublicKey(b64dec(pk)) if type(pk)==bytes else pk res = self.crypt_keys.get(name, prefix='/pubkey/') - self.log(f'crypt_keys({name}) -->',res) + # self.log(f'crypt_keys({name}) -->',res) if not res: res = self.load_qr(self.name) - self.log(f'load_qr({name}) -->',res) + # self.log(f'load_qr({name}) -->',res) if not res: return key = KomradeAsymmetricPublicKey(b64dec(res)) - self.log('-->',key) + # self.log('-->',key) return key # self.log('I don\'t know my public key! Do I need to register?') # raise KomradeException(f'I don\'t know my public key!\n{self}\n{self._keychain}') diff --git a/komrade/backend/komrades.py b/komrade/backend/komrades.py index b91257b..5617e47 100644 --- a/komrade/backend/komrades.py +++ b/komrade/backend/komrades.py @@ -529,17 +529,41 @@ class KomradeX(Caller): return res - def messages(self,show_read=True,show_unread=True): + def posts(self,**y): + return self.messages( + inbox_prefix='/feed/' + ) + + def messages(self, + show_read=True, + show_unread=True, + inbox_prefix='/inbox/'): # meta inbox - inbox = self.inbox_db.values + self.log('<--',inbox_prefix,'???') + + inbox_db=self.get_inbox_crypt(prefix=inbox_prefix) + read_db=self.get_inbox_crypt(prefix=inbox_prefix+'read/') + unread_db=self.get_inbox_crypt(prefix=inbox_prefix+'unread/') + + inbox = inbox_db.values + read = read_db.values + unread = unread_db.values self.log('<- inbox',inbox) + self.log('<- read',read) + self.log('<- unread',unread) + + # filter out posts!?!?! @hack + if inbox_prefix=='/inbox/': + bad_prefix = '/feed/' if inbox_prefix=='/inbox/' else '/inbox/' + bad_db=self.get_inbox_crypt(prefix=inbox_prefix) + bad = bad_db.values + self.log('bad',bad_prefix,'for me',inbox_prefix,'=',bad) + inbox = [x for x in inbox if x not in set(bad)] + self.log('<- inbox 2',inbox) # filter? - if not show_read: - inbox = [x for x in inbox if not x in set(self.inbox_read_db.values)] - if not show_unread: - inbox = [x for x in inbox if not x in set(self.inbox_unread_db.values)] - self.log('<- inbox 2',inbox) + if not show_read: inbox = [x for x in inbox if not x in set(read)] + if not show_unread: inbox = [x for x in inbox if not x in set(unread)] # decrypt and read all posts msgs=[] diff --git a/komrade/backend/the_operator.py b/komrade/backend/the_operator.py index e6e1704..32d7052 100644 --- a/komrade/backend/the_operator.py +++ b/komrade/backend/the_operator.py @@ -795,39 +795,24 @@ class TheOperator(Operator): else: txt=f'''Komrade @{meet_from_name} would like to make your acquaintance.\n\nTheir public key is:\n{meet_from_uri.decode()}.''' - msg_from_op = Message( - msg_d = { - 'to':meet_uri, - 'to_name':meet_name, + deliver_msg_d = { + 'to':meet_uri, + 'to_name':meet_name, - 'from':self.uri, - 'from_name':self.name, - - 'msg':{ - - 'to':meet_uri, - 'to_name':meet_name, - - 'from':self.uri, - 'from_name':self.name, - - - 'msg':{ - 'txt':txt, - 'type':'prompt', - 'prompt_id':'addcontact', - 'meet_name':meet_from_name, - 'meet':meet_from_uri, - } - } + 'from':self.uri, + 'from_name':self.name, + + 'msg':{ + 'txt':txt, + 'type':'prompt', + 'prompt_id':'addcontact', + 'meet_name':meet_from_name, + 'meet':meet_from_uri, } - ) - self.log('formed msg:',msg_from_op) - msg_from_op.encrypt() - self.log('encrypted formed msg:',msg_from_op) - res = self.actually_deliver_msg(msg_from_op) - res['msg_sent']=txt - return res + } + + self.log('deliver_msg_d ->',deliver_msg_d) + return self.deliver_msg_d(deliver_msg_d) diff --git a/komrade/cli/cli.py b/komrade/cli/cli.py index c36ffab..fa423bb 100644 --- a/komrade/cli/cli.py +++ b/komrade/cli/cli.py @@ -22,7 +22,8 @@ class CLI(Logger): 'who':'show contacts or info', 'msg':'write people', 'update':'check mail', - 'read':'read mail', + 'dms':'read DMs', + 'feed':'read posts', 'verbose':'show/hide log output', 'post':'post to world', 'feed':'fetch posts' @@ -359,29 +360,35 @@ class CLI(Logger): pass - - - def read(self,dat='',inbox_res=None): + def dms(self,dat=''): if self.with_required_login(): msgs=self.komrade.messages() - if not msgs: - self.stat('No messages.') - else: - clear_screen() - for i,msg in enumerate(msgs): - try: - self.stat(f'Showing message {i+1} of {len(msgs)}, from newest to oldest. Hit Ctrl+D to exit.') - print() - print(msg) - # self.print('DATA',msg.msg_d) - if msg.data.get('prompt_id')=='addcontact': - self.prompt_adduser(msg) - - self.prompt_msg(msg) - clear_screen() - except EOFError: - break - self.help() + return self.read(msgs) + + def feed(self,dat=''): + if self.with_required_login(): + posts=self.komrade.posts() + return self.read(posts) + + def read(self,msgs): + if not msgs: + self.stat('No messages.') + else: + clear_screen() + for i,msg in enumerate(msgs): + try: + self.stat(f'Showing message {i+1} of {len(msgs)}, from newest to oldest. Hit Ctrl+D to exit.') + print() + print(msg) + # self.print('DATA',msg.msg_d) + if msg.data.get('prompt_id')=='addcontact': + self.prompt_adduser(msg) + + self.prompt_msg(msg) + clear_screen() + except EOFError: + break + self.help() def post(self,msg_s): @@ -391,12 +398,6 @@ class CLI(Logger): msg_s=msg_s ) - def feed(self,dat=''): - if self.with_required_login(): - inbox_res = self.komrade.fetch_posts() - return self.read(inbox_res=inbox_res) - -