diff --git a/app/main.py b/app/main.py index e806976..b6de9ce 100644 --- a/app/main.py +++ b/app/main.py @@ -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: diff --git a/app/screens/login/login.py b/app/screens/login/login.py index 623c8ae..13ef49c 100644 --- a/app/screens/login/login.py +++ b/app/screens/login/login.py @@ -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) diff --git a/app/screens/post/post.py b/app/screens/post/post.py index f89f26f..a11a44c 100644 --- a/app/screens/post/post.py +++ b/app/screens/post/post.py @@ -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()) diff --git a/p2p/api.py b/p2p/api.py index 892f0fc..5db1e0f 100644 --- a/p2p/api.py +++ b/p2p/api.py @@ -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}