예제 #1
0
파일: commands.py 프로젝트: GMati13/chat
def send():
    chat_id = store.get_item('current_chat')['id']
    chat_type = store.get_item('current_chat')['type']
    if chat_id is None:
        return 'Error: chat has not selected'
    text = footer.message_line.get_edit_text()
    footer.message_line.clear()
    message = client.send_message(chat_id, text)
    chat.append_message(message, chat_type)
    body.history.scroll_end()
예제 #2
0
def on_message(c, message):
    current_chat = store.get_item('current_chat')
    if current_chat is None:
        return
    chat_id = current_chat['id']
    chat_type = current_chat['type']
    if message['chat']['id'] == chat_id:
        chat.append_message(message, chat_type)
        body.history.scroll_end()
예제 #3
0
파일: chats.py 프로젝트: GMati13/chat
def select_chat(chat_id):
    body.history.clear()
    dialog = list(
        filter(lambda d: d['chat']['id'] == chat_id,
               store.get_item('dialogs')['dialogs']))[0]
    app.mode.toggle_mode('chat')
    history = client.get_history(chat_id)
    store.set_item('current_chat', dialog['chat'])
    for message in history['messages'][::-1]:
        append_message(message, dialog['chat']['type'])
    body.history.scroll_end()
예제 #4
0
파일: chats.py 프로젝트: GMati13/chat
def append_message(message, chat_type):
    is_me = message['outgoing'] or store.get_item(
        'me')['id'] == message['from_user']['id']
    if chat_type == 'private':
        body.history.append_child(
            urwid.AttrMap(urwid.Message(message),
                          theme.green_light if is_me else theme.main_light,
                          theme.green_dark if is_me else theme.main_dark))
    elif chat_type in ['group', 'channel']:
        body.history.append_child(
            urwid.AttrMap(urwid.Message(message), theme.main_light,
                          theme.main_dark))
예제 #5
0
파일: chats.py 프로젝트: GMati13/chat
def show_dialog_info(position):
    dialog = store.get_item('dialogs')['dialogs'][position]
    if dialog['chat']['type'] == 'private':
        footer.info_line.left_column.set_text(
            status_line.info_dialog_private.format(
                username=dialog['chat']['username']
                if dialog['chat']['username'] else 'no username',
                fullname=formatter.formate_name(dialog['chat']['first_name'],
                                                dialog['chat']['last_name']),
            ))
    elif dialog['chat']['type'] in ['group', 'channel']:
        footer.info_line.left_column.set_text(
            status_line.info_dialog_public.format(
                type=dialog['chat']['type'], title=dialog['chat']['title']))
    else:
        footer.info_line.left_column.set_text(
            status_line.info_unsupported_channel)
예제 #6
0
파일: mode.py 프로젝트: GMati13/chat
def on_toggle(prev_mode, next_mode):
    me = store.get_item('me')
    footer.status_line.left_column.set_text(
        status_line.app_status_left.format(
            mode=next_mode,
            username=formatter.formate_name(me['first_name'], me['last_name']),
            online=formatter.format_status(me['status'])))
    if prev_mode in ['COMMAND']:
        footer.command_line.set_caption('')
    if next_mode in ['MESSAGE', 'NORMAL']:
        document.Document.set_focus('footer')
        footer.tools.set_focus(0)
        if prev_mode == 'COMMAND':
            footer.tools.set_focus(0)
    if next_mode in ['COMMAND']:
        document.Document.set_focus('footer')
        footer.tools.set_focus(2)
        footer.command_line.clear()
        footer.command_line.set_caption(':')
    if next_mode in ['DIALOGS', 'CHAT']:
        document.Document.set_focus('body')
    if next_mode in ['CHAT']:
        document.Document.set_focus('body')
예제 #7
0
def history_on_enter(position, List):
    if app.mode.current_mode == 'DIALOGS':
        chats.select_chat(
            store.get_item('dialogs')['dialogs'][position]['chat']['id'])