tdesktop/Telegram/SourceFiles/history/view/history_view_message.cpp

70 lines
1.6 KiB
C++
Raw Normal View History

/*
This file is part of Telegram Desktop,
the official desktop application for the Telegram messaging service.
For license and copyright information please follow this link:
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/
#include "history/view/history_view_message.h"
namespace HistoryView {
Message::Message(not_null<HistoryItem*> data, Context context)
: _data(data)
, _context(context) {
}
not_null<HistoryItem*> Message::data() const {
return _data;
}
void Message::attachToBlock(not_null<HistoryBlock*> block, int index) {
Expects(!_data->isLogEntry());
Expects(_block == nullptr);
Expects(_indexInBlock < 0);
Expects(index >= 0);
_block = block;
_indexInBlock = index;
_data->setMainView(this);
_data->setPendingResize();
}
void Message::removeFromBlock() {
Expects(_block != nullptr);
_block->remove(this);
}
Message *Message::previousInBlocks() const {
if (_block && _indexInBlock >= 0) {
if (_indexInBlock > 0) {
return _block->messages[_indexInBlock - 1].get();
}
if (auto previous = _block->previousBlock()) {
Assert(!previous->messages.empty());
return previous->messages.back().get();
}
}
return nullptr;
}
Message *Message::nextInBlocks() const {
if (_block && _indexInBlock >= 0) {
if (_indexInBlock + 1 < _block->messages.size()) {
return _block->messages[_indexInBlock + 1].get();
}
if (auto next = _block->nextBlock()) {
Assert(!next->messages.empty());
return next->messages.front().get();
}
}
return nullptr;
}
Message::~Message() {
App::messageViewDestroyed(this);
}
} // namespace HistoryView