TelegramTUI/src/viewchat.cpp

57 lines
1.1 KiB
C++

#include "viewchat.h"
#include <memory>
#include <ncurses.h>
#include <Log.h>
#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<Message> 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<int>(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<std::shared_ptr<Message>>& msgs) {
// TODO: force a repaint somehow?
messages = msgs;
}