#include "viewchat.h" #include #include #include #include "message.h" #include "tgtui.h" ViewChat::ViewChat(TgTUI& tgtui) : View(tgtui) {} ViewChat::~ViewChat() {} void ViewChat::setChat(const SlimChat* chat) { this->chat = chat; } int64_t ViewChat::getChat() const { return this->chat->chatId; } void ViewChat::paint() { getmaxyx(stdscr, maxRows, maxCols); ::printw("Chat: %s (%li)\n", chat->name.c_str(), chat->chatId); Log::info << "messages: " << messages.size() << " maxRows: " << maxRows; for(int row = 0; row < maxRows-1 && row < messages.size(); ++row) { Log::debug << "print msg at: " << row; std::shared_ptr msg = messages.at(row); const char direction = ( msg->isOutgoing ? '>' : '<' ); ::mvprintw(maxRows - row, 0, "[%lu] %c (%li) %*s\n", msg->sendDate, direction, msg->sender, std::min(msg->text.size(), maxCols), msg->text.c_str()); } } int ViewChat::keyIn(int key) { switch (key) { case KEY_LEFT: case 'q': return 0; } return -1; } void ViewChat::updateMessages(const std::vector>& msgs) { // TODO: force a repaint somehow? messages = msgs; }