async def user_details( user_id: int, db: Session = Depends(get_db), current_user: models.User = Depends(get_current_active_superuser), ): """ Get any user details """ user = get_user(db=db, user_id=user_id) return user
async def user_details( request: Request, user_id: int, db=Depends(get_db), current_user=Depends(get_current_active_superuser), ): """ Get any user details """ user = get_user(db, user_id) return user
async def notify_about_new_msg(letter, from_id, to_id, content, chat_id, db): ws_conn = WS_POOL_CONNECTS.get(to_id, None) if ws_conn is None: return from_user = get_user(db, from_id) to_user = get_user(db, to_id) msg = Message(id=letter.id, from_name=f'{from_user.first_name} {from_user.last_name}', to_name=f'{to_user.first_name} {to_user.last_name}', letter=content, data=letter.received, mark_as_read=letter.as_read, is_your_message=False, chat_id=chat_id, to_addr_id=to_id) await ws_conn.send_text(json.dumps({ 'type': 'message', 'data': msg.json() }))
async def list_messages(to_addr: Optional[int] = None, current_user=Depends(get_current_user), db=Depends(get_db)) -> \ List[Message]: str_name = lambda x: '%s %s' % (x.first_name, x.last_name) from_id = current_user.id messages = get_sorted_messages(db, from_id, to_addr) from_name = str_name(get_user(db, from_id)) id2username = {m.to_addr: get_user(db, m.to_addr) for m, _ in messages} res = [] for m, chat_id in messages: is_your_message = True if m.from_addr == from_id else False res.append( Message(id=m.id, from_name=from_name, to_name=str_name(id2username[m.to_addr]), to_addr_id=m.to_addr, letter=m.message, data=m.received, mark_as_read=m.as_read, is_your_message=is_your_message, chat_id=chat_id)) return res
def read_user(user_id: int, db: Session = Depends(get_db)): db_user = crud.get_user(db, user_id) if not db_user: raise HTTPException(status_code=404, detail="User not found") return db_user