2018-01-10 16:13:33 +03:00
|
|
|
/*
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2018-01-11 16:07:29 +03:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2018-01-10 16:13:33 +03:00
|
|
|
} // namespace HistoryView
|