mirror of
https://github.com/ComradCollective/Comrad
synced 2024-11-05 21:20:51 +00:00
updates
This commit is contained in:
parent
8bf5d2398e
commit
2e25d862ad
@ -390,19 +390,32 @@ class KomradeX(Caller):
|
||||
self.log('->',res)
|
||||
return res
|
||||
|
||||
def save_inbox(self,post_ids):
|
||||
self.crypt_keys.set(
|
||||
self.uri,
|
||||
BSEP.join(post_ids),
|
||||
'/inbox/',
|
||||
def save_inbox(self,
|
||||
post_ids,
|
||||
uri=None,
|
||||
encrypted=False):
|
||||
self.log('<-',post_ids)
|
||||
newval = BSEP.join(post_ids)
|
||||
|
||||
res = self.crypt_keys.set(
|
||||
self.uri if not uri else uri,
|
||||
newval,
|
||||
prefix='/inbox/',
|
||||
override=True
|
||||
)
|
||||
assert newval == self.crypt_keys.get(
|
||||
self.uri,
|
||||
prefix='/inbox/'
|
||||
)
|
||||
self.log('->',res)
|
||||
return res
|
||||
|
||||
def delete_msg(self,post_id):
|
||||
return self.delete_msgs([post_id])
|
||||
|
||||
def delete_msgs(self,post_ids):
|
||||
#inbox_ids = self.get_inbox_ids().get('inbox',[])
|
||||
inbox_ids = self.get_inbox_ids().get('inbox',[])
|
||||
#print(inbox_ids,'v1',len(inbox_ids))
|
||||
deleted=[]
|
||||
for post_id in post_ids:
|
||||
#print('deleting post:',post_id)
|
||||
@ -411,16 +424,22 @@ class KomradeX(Caller):
|
||||
prefix='/post/',
|
||||
)
|
||||
deleted+=[post_id]
|
||||
return {
|
||||
|
||||
#print(post_id,inbox_ids,post_id in inbox_ids,'???')
|
||||
# stop
|
||||
if post_id in inbox_ids:
|
||||
print('removing from inbox...')
|
||||
inbox_ids.remove(post_id)
|
||||
self.save_inbox(inbox_ids)
|
||||
#print(inbox_ids,'v2',len(inbox_ids))
|
||||
|
||||
res= {
|
||||
'success':not bool(set(post_ids) - set(deleted)),
|
||||
'status':f'Deleted {len(deleted)} messages.',
|
||||
'deleted':deleted
|
||||
}
|
||||
# print(post_id,inbox_ids,post_id in inbox_ids,'???')
|
||||
# stop
|
||||
#if post_id in inbox_ids:
|
||||
# inbox_ids.remove(post_id)
|
||||
#self.save_inbox(inbox_ids)
|
||||
self.log('delete_msgs ->',res)
|
||||
return res
|
||||
|
||||
def inbox(self,topn=100,only_unread=False,delete_malformed=False):
|
||||
# refreshing inbox
|
||||
@ -606,6 +625,18 @@ class KomradeX(Caller):
|
||||
if not name and not pubkey:
|
||||
return {'success':False,'status':'Meet whom?'}
|
||||
|
||||
|
||||
keystr=self.name+'->'+name
|
||||
|
||||
if self.crypt_keys.get(
|
||||
keystr,
|
||||
prefix='/met/'
|
||||
):
|
||||
return {
|
||||
'success':False,
|
||||
'status':f'You have already sent an introduction to @{name}. It would be rude to send another.'
|
||||
}
|
||||
|
||||
msg_to_op = {
|
||||
'name':self.name,
|
||||
'secret_login':self.secret_login,
|
||||
@ -623,6 +654,13 @@ class KomradeX(Caller):
|
||||
)
|
||||
# print('res from op',res)
|
||||
|
||||
# record that I've already tried this
|
||||
self.crypt_keys.set(
|
||||
keystr,
|
||||
b'y',
|
||||
prefix='/met/'
|
||||
)
|
||||
|
||||
return res
|
||||
|
||||
|
||||
|
@ -485,7 +485,7 @@ from_komrade = {from_komrade}
|
||||
'pubkey',
|
||||
'post_ids',
|
||||
],
|
||||
delete_afterward=False):
|
||||
delete_afterward=True):
|
||||
|
||||
# logged in?
|
||||
login_res = self.login(msg_to_op)
|
||||
@ -506,21 +506,68 @@ from_komrade = {from_komrade}
|
||||
self.log(f'I {self} found {len(posts)} for {msg_to_op.from_name}')
|
||||
|
||||
# delete?
|
||||
if delete_afterward:
|
||||
# @hack: this a bit dangerous?
|
||||
for post_id in posts:
|
||||
self.crypt_keys.delete(
|
||||
post_id,
|
||||
prefix='/post/'
|
||||
)
|
||||
self.log('deleting post id',post_id,'...')
|
||||
|
||||
return {
|
||||
res = {
|
||||
'status':'Succeeded in downloading new messages.' + (' I\'ve already deleted these messages from the server.' if delete_afterward else ''),
|
||||
'success':True,
|
||||
'data_encr':posts
|
||||
}
|
||||
|
||||
# delete?
|
||||
if delete_afterward:
|
||||
res['res_delete_msgs'] = self.delete_msgs(
|
||||
post_ids,
|
||||
inbox_uri = b64enc(
|
||||
msg_to_op.data.get('pubkey')
|
||||
)
|
||||
)
|
||||
|
||||
# show res
|
||||
self.log('->',res)
|
||||
return res
|
||||
|
||||
|
||||
|
||||
def delete_msgs(self,post_ids,inbox_uri=None):
|
||||
# @hack: this a bit dangerous?
|
||||
for post_id in post_ids:
|
||||
self.crypt_keys.delete(
|
||||
post_id,
|
||||
prefix='/post/'
|
||||
)
|
||||
self.log('deleting post id',post_id,'...')
|
||||
|
||||
# if inbox, remove these posts from it
|
||||
if inbox_uri:
|
||||
# unwrap
|
||||
inbox_encr = self.crypt_keys.get(
|
||||
inbox_uri,
|
||||
prefix='/inbox/'
|
||||
)
|
||||
inbox = SMessage(
|
||||
self.privkey.data,
|
||||
b64dec(inbox_uri)
|
||||
).unwrap(inbox_encr)
|
||||
self.log('unwrapped inbox_encr:',inbox)
|
||||
inbox_l = inbox.split(BSEP)
|
||||
self.log('length v1:',len(inbox_l))
|
||||
|
||||
# alter
|
||||
inbox_l = [pid for pid in inbox_l if pid not in post_ids]
|
||||
self.log('length v2:',len(inbox_l))
|
||||
|
||||
# rewrap
|
||||
inbox = inbox_l.split(BSEP)
|
||||
inbox_encr = SMessage(
|
||||
self.privkey.data,
|
||||
b64dec(inbox_uri)
|
||||
).wrap(inbox)
|
||||
|
||||
return {
|
||||
'success':True,
|
||||
'deleted':post_ids,
|
||||
}
|
||||
|
||||
|
||||
def introduce_komrades(self,msg_to_op):
|
||||
# # logged in?
|
||||
# self.log('introduce got:',msg_to_op)
|
||||
|
@ -337,15 +337,18 @@ class CLI(Logger):
|
||||
else:
|
||||
clear_screen()
|
||||
for i,msg in enumerate(msgs):
|
||||
self.stat(f'Showing message {i+1} of {len(msgs)}.')
|
||||
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()
|
||||
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()
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user