pull/20/head
quadrismegistus 4 years ago
parent 4a493fe3d3
commit 0e4ad88e8a

@ -337,7 +337,7 @@ class MainApp(MDApp):
if data_piece is not None:
of.write(data_piece)
async def post(self, content='', file_id=None, file_ext=None, anonymous=False,channels=['world']):
async def post(self, content='', file_id=None, file_ext=None, anonymous=False,channel='world'):
#timestamp=time.time()
jsond={}
#jsond['timestamp']=
@ -349,12 +349,12 @@ class MainApp(MDApp):
file_id={file_id},
file_ext={file_ext},
anonymous={anonymous},
channels={channels},
channel={channel},
[username={self.username}]'''
)
if not anonymous and self.username:
jsond['author']=self.username
jsond['to_channels']=channels
jsond['channel']=channel
self.log('posting:',jsond)
res=await self.api.post(jsond)
if 'success' in res:

@ -99,12 +99,16 @@ class LoginScreen(BaseScreen):
self.layout.add_widget(self.login_status)
self.label_title.font_size='22sp'
self.label_title.font_size='18sp'
# self.label_password.font_size='18sp'
self.label_username.font_size='18sp'
self.label_username.font_size='20sp'
# self.login_button.font_size='12sp'
self.register_button.font_size='12sp'
self.register_button.font_size='9sp'
self.register_button.text='enter'
self.username_field.font_size='20sp'
self.label_username.padding_x=(10,20)
self.username_field.padding_x=(20,10)
self.username_field.padding_y=(25,0)

@ -286,11 +286,14 @@ class PostScreen(ProtectedScreen):
return
#channels = [k[1:] for k,v in self.to_channels.items() if v]
if not hasattr(self,'recipient') or not self.recipient or self.app.username==self.recipient:
recipient = self.to_whom_btn.ids.txt_input.text
self.log('RECIPIENT:',recipient)
if not recipient: ##not hasattr(self,'recipient') or not self.recipient or self.app.username==self.recipient:
self.log('no recipient was selected')
# self.='No place was selected'
return
channels = [self.recipient]
self.recipient = recipient
channel = recipient
# log('?????????????????'+self.media_uid)
# if not hasattr(self,'img_id') and self.upload_button.selection:
@ -300,11 +303,11 @@ class PostScreen(ProtectedScreen):
async def do_post():
file_id = self.img_id if hasattr(self,'img_id') else None
file_ext = self.img_ext if hasattr(self,'img_ext') else None
await self.app.post(content=content, channels = channels, file_id=file_id, file_ext=file_ext)
await self.app.post(content=content, channel = channel, file_id=file_id, file_ext=file_ext)
import time
self.close_dialog()
self.open_dialog('posting')
self.open_dialog('')
#Thread(target=do_post).start()
asyncio.create_task(do_post())

@ -709,41 +709,43 @@ class Api(object):
# ## add to inbox
post_id = get_random_id()
author_privkey = self.keys[data.get('author')]
channels = data.get('to_channels',[])
for channel in channels:
self.log('ADDING TO CHANNEL??',channel)
pubkey_channel = self.keys[channel].public_key()
data_channel = dict(data.items())
data_channel['to_name']=channel
## add per channel
# encrypt and post
uri = '/'+os.path.join('inbox',channel,post_id)
self.log('setting',uri,'????',type(data_channel),data_channel)
channel = data.get('channel')
if not channel:
raise Exception('channel not given')
json_res = await self.set_json(
uri,
data_channel,
encode_data=True,
encrypt_for_pubkey=pubkey_channel,
private_signature_key=author_privkey
)
self.log(f'json_res() <- {json_res}')
##tasks.append(task)
self.log('ADDING TO CHANNEL??',channel)
pubkey_channel = self.keys[channel].public_key()
data_channel = dict(data.items())
data_channel['to_name']=channel
## add per channel
# encrypt and post
uri = '/'+os.path.join('inbox',channel,post_id)
self.log('setting',uri,'????',type(data_channel),data_channel)
json_res = await self.set_json(
uri,
data_channel,
encode_data=True,
encrypt_for_pubkey=pubkey_channel,
private_signature_key=author_privkey
)
# add to inbox
append_res=await self.append_json(f'/inbox/{channel}',post_id)
self.log(f'json_res.append_json({channel}) <- {append_res}')
#tasks.append(task)
# add to outbox
if add_to_outbox:
un=data.get('author')
if un:
append_res = await self.append_json(f'/outbox/{un}', post_id)
self.log(f'json_res.append_json({un}) <- {append_res}')
#tasks.append(task)
self.log(f'json_res() <- {json_res}')
##tasks.append(task)
# add to inbox
append_res=await self.append_json(f'/inbox/{channel}',post_id)
self.log(f'json_res.append_json({channel}) <- {append_res}')
#tasks.append(task)
# add to outbox
if add_to_outbox:
un=data.get('author')
if un:
append_res = await self.append_json(f'/outbox/{un}', post_id)
self.log(f'json_res.append_json({un}) <- {append_res}')
#tasks.append(task)
#asyncio.create_task(self.flush())
return {'success':'Posted! %s' % post_id, 'post_id':post_id}

Loading…
Cancel
Save