mirror of
https://github.com/vale981/tdesktop
synced 2025-03-06 10:11:41 -05:00
addOlderSlice and addNewerSlice should work well with items changing inside them
This commit is contained in:
parent
dc72800a5e
commit
9a72293e0a
4 changed files with 91 additions and 78 deletions
|
@ -945,9 +945,11 @@ void ChannelHistory::switchMode() {
|
|||
item->attach(block);
|
||||
prev = addItemAfterPrevToBlock(item, prev, block);
|
||||
}
|
||||
block->y = height;
|
||||
blocks.push_back(block);
|
||||
height += block->height;
|
||||
if (width) {
|
||||
block->y = height;
|
||||
height += block->height;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1632,14 +1634,16 @@ void History::createInitialDateBlock(const QDateTime &date) {
|
|||
HistoryItem *dayItem = createDayServiceMsg(this, dateBlock, date);
|
||||
dateBlock->items.push_back(dayItem);
|
||||
if (width) {
|
||||
int32 dh = dayItem->resize(width);
|
||||
dateBlock->height = dh;
|
||||
height += dh;
|
||||
for (int32 i = 0, l = blocks.size(); i < l; ++i) {
|
||||
blocks[i]->y += dh;
|
||||
dateBlock->height += dayItem->resize(width);
|
||||
}
|
||||
|
||||
blocks.push_front(dateBlock);
|
||||
if (width) {
|
||||
height += dateBlock->height;
|
||||
for (int32 i = 1, l = blocks.size(); i < l; ++i) {
|
||||
blocks.at(i)->y += dateBlock->height;
|
||||
}
|
||||
}
|
||||
blocks.push_front(dateBlock);
|
||||
}
|
||||
|
||||
void History::addToOverview(HistoryItem *item, MediaOverviewType type) {
|
||||
|
@ -1676,8 +1680,9 @@ HistoryItem *History::addNewItem(HistoryBlock *to, bool newBlock, HistoryItem *a
|
|||
} else if (to->items.back()->date.date() != adding->date.date()) {
|
||||
HistoryItem *dayItem = createDayServiceMsg(this, to, adding->date);
|
||||
to->items.push_back(dayItem);
|
||||
dayItem->y = to->height;
|
||||
if (width) {
|
||||
dayItem->y = to->height;
|
||||
|
||||
int32 dh = dayItem->resize(width);
|
||||
to->height += dh;
|
||||
height += dh;
|
||||
|
@ -1857,8 +1862,10 @@ HistoryItem *History::addMessageGroupAfterPrev(HistoryItem *newItem, HistoryItem
|
|||
createInitialDateBlock(date);
|
||||
|
||||
block = new HistoryBlock(this);
|
||||
block->y = height;
|
||||
blocks.push_back(block);
|
||||
if (width) {
|
||||
block->y = height;
|
||||
}
|
||||
}
|
||||
return addItemAfterPrevToBlock(regItem(new HistoryGroup(this, block, newItem, date)), prev, block);
|
||||
}
|
||||
|
@ -1877,13 +1884,11 @@ void History::addOlderSlice(const QVector<MTPMessage> &slice, const QVector<MTPM
|
|||
|
||||
const MTPMessageGroup *groupsBegin = (isChannel() && collapsed) ? collapsed->constData() : 0, *groupsIt = groupsBegin, *groupsEnd = (isChannel() && collapsed) ? (groupsBegin + collapsed->size()) : 0;
|
||||
|
||||
int32 addToH = 0, skip = 0;
|
||||
if (!blocks.isEmpty()) { // remove date block
|
||||
if (width) addToH = -blocks.front()->height;
|
||||
delete blocks.front();
|
||||
blocks.pop_front();
|
||||
HistoryItem *oldFirst = 0, *last = 0;
|
||||
if (!blocks.isEmpty()) {
|
||||
t_assert(blocks.size() > 1);
|
||||
oldFirst = blocks.at(1)->items.front();
|
||||
}
|
||||
HistoryItem *till = blocks.isEmpty() ? 0 : blocks.front()->items.front(), *prev = 0;
|
||||
|
||||
HistoryBlock *block = new HistoryBlock(this);
|
||||
block->items.reserve(slice.size() + (collapsed ? collapsed->size() : 0));
|
||||
|
@ -1897,36 +1902,58 @@ void History::addOlderSlice(const QVector<MTPMessage> &slice, const QVector<MTPM
|
|||
const MTPDmessageGroup &group(groupsIt->c_messageGroup());
|
||||
if (group.vmin_id.v >= adding->id) break;
|
||||
|
||||
prev = addMessageGroupAfterPrevToBlock(group, prev, block);
|
||||
last = addMessageGroupAfterPrevToBlock(group, last, block);
|
||||
}
|
||||
|
||||
prev = addItemAfterPrevToBlock(adding, prev, block);
|
||||
last = addItemAfterPrevToBlock(adding, last, block);
|
||||
}
|
||||
for (; groupsIt != groupsEnd; ++groupsIt) {
|
||||
if (groupsIt->type() != mtpc_messageGroup) continue;
|
||||
const MTPDmessageGroup &group(groupsIt->c_messageGroup());
|
||||
|
||||
prev = addMessageGroupAfterPrevToBlock(group, prev, block);
|
||||
last = addMessageGroupAfterPrevToBlock(group, last, block);
|
||||
}
|
||||
|
||||
while (till && prev && till->type() == HistoryItemGroup && prev->type() == HistoryItemGroup) {
|
||||
static_cast<HistoryGroup*>(prev)->uniteWith(static_cast<HistoryGroup*>(till));
|
||||
till->destroy();
|
||||
till = blocks.isEmpty() ? 0 : blocks.front()->items.front();
|
||||
while (oldFirst && last && oldFirst->type() == HistoryItemGroup && last->type() == HistoryItemGroup) {
|
||||
static_cast<HistoryGroup*>(last)->uniteWith(static_cast<HistoryGroup*>(oldFirst));
|
||||
oldFirst->destroy();
|
||||
if (blocks.isEmpty()) {
|
||||
oldFirst = 0;
|
||||
} else {
|
||||
t_assert(blocks.size() > 1);
|
||||
oldFirst = blocks.at(1)->items.front();
|
||||
}
|
||||
}
|
||||
if (till && prev && prev->date.date() != till->date.date()) {
|
||||
HistoryItem *dayItem = createDayServiceMsg(this, block, till->date);
|
||||
if (oldFirst && last && last->date.date() != oldFirst->date.date()) {
|
||||
HistoryItem *dayItem = createDayServiceMsg(this, block, oldFirst->date);
|
||||
block->items.push_back(dayItem);
|
||||
if (width) {
|
||||
dayItem->y = block->height;
|
||||
block->height += dayItem->resize(width);
|
||||
}
|
||||
}
|
||||
if (!block->items.isEmpty()) {
|
||||
blocks.push_front(block);
|
||||
if (width) {
|
||||
addToH += block->height;
|
||||
++skip;
|
||||
if (block->items.isEmpty()) {
|
||||
oldLoaded = true;
|
||||
delete block;
|
||||
} else {
|
||||
if (oldFirst) {
|
||||
HistoryBlock *initial = blocks.at(0);
|
||||
blocks[0] = block;
|
||||
blocks.push_front(initial);
|
||||
if (width) {
|
||||
block->y = initial->height;
|
||||
for (int32 i = 2, l = blocks.size(); i < l; ++i) {
|
||||
blocks.at(i)->y += block->height;
|
||||
}
|
||||
height += block->height;
|
||||
}
|
||||
initial->items.at(0)->setDate(block->items.at(0)->date);
|
||||
} else {
|
||||
blocks.push_front(block);
|
||||
if (width) {
|
||||
height = block->height;
|
||||
}
|
||||
createInitialDateBlock(block->items.at(0)->date);
|
||||
}
|
||||
|
||||
if (loadedAtBottom()) { // add photos to overview and authors to lastAuthors / lastParticipants
|
||||
|
@ -2018,33 +2045,6 @@ void History::addOlderSlice(const QVector<MTPMessage> &slice, const QVector<MTPM
|
|||
if ((mask & (1 << t)) && App::wnd()) App::wnd()->mediaOverviewUpdated(peer, MediaOverviewType(t));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
delete block;
|
||||
}
|
||||
if (!blocks.isEmpty()) {
|
||||
HistoryBlock *dateBlock = new HistoryBlock(this);
|
||||
HistoryItem *dayItem = createDayServiceMsg(this, dateBlock, blocks.front()->items.front()->date);
|
||||
dateBlock->items.push_back(dayItem);
|
||||
if (width) {
|
||||
int32 dh = dayItem->resize(width);
|
||||
dateBlock->height = dh;
|
||||
if (skip) {
|
||||
blocks.front()->y += dh;
|
||||
}
|
||||
addToH += dh;
|
||||
++skip;
|
||||
}
|
||||
blocks.push_front(dateBlock); // date block
|
||||
}
|
||||
if (width && addToH) {
|
||||
for (Blocks::iterator i = blocks.begin(), e = blocks.end(); i != e; ++i) {
|
||||
if (skip) {
|
||||
--skip;
|
||||
} else {
|
||||
(*i)->y += addToH;
|
||||
}
|
||||
}
|
||||
height += addToH;
|
||||
}
|
||||
|
||||
if (isChannel()) {
|
||||
|
@ -2091,16 +2091,22 @@ void History::addNewerSlice(const QVector<MTPMessage> &slice, const QVector<MTPM
|
|||
prev = addMessageGroupAfterPrevToBlock(group, prev, block);
|
||||
}
|
||||
|
||||
if (block->items.size()) {
|
||||
block->y = height;
|
||||
blocks.push_back(block);
|
||||
height += block->height;
|
||||
} else {
|
||||
if (block->items.isEmpty()) {
|
||||
newLoaded = true;
|
||||
setLastMessage(lastImportantMessage());
|
||||
delete block;
|
||||
} else {
|
||||
blocks.push_back(block);
|
||||
if (width) {
|
||||
block->y = height;
|
||||
height += block->height;
|
||||
}
|
||||
if (blocks.size() == 1) {
|
||||
createInitialDateBlock(block->items.at(0)->date);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!wasLoadedAtBottom && loadedAtBottom()) { // add all loaded photos to overview
|
||||
int32 mask = 0;
|
||||
for (int32 i = 0; i < OverviewCount; ++i) {
|
||||
|
@ -2153,18 +2159,6 @@ void History::addNewerSlice(const QVector<MTPMessage> &slice, const QVector<MTPM
|
|||
if ((mask & (1 << t)) && App::wnd()) App::wnd()->mediaOverviewUpdated(peer, MediaOverviewType(t));
|
||||
}
|
||||
}
|
||||
if (wasEmpty && !isEmpty()) {
|
||||
HistoryBlock *dateBlock = new HistoryBlock(this);
|
||||
HistoryItem *dayItem = createDayServiceMsg(this, dateBlock, blocks.front()->items.front()->date);
|
||||
dateBlock->items.push_back(dayItem);
|
||||
int32 dh = dayItem->resize(width);
|
||||
dateBlock->height = dh;
|
||||
for (Blocks::iterator i = blocks.begin(), e = blocks.end(); i != e; ++i) {
|
||||
(*i)->y += dh;
|
||||
}
|
||||
blocks.push_front(dateBlock); // date block
|
||||
height += dh;
|
||||
}
|
||||
|
||||
if (isChannel()) asChannelHistory()->checkJoinedMessage();
|
||||
}
|
||||
|
@ -7271,6 +7265,13 @@ HistoryDateMsg::HistoryDateMsg(History *history, HistoryBlock *block, const QDat
|
|||
HistoryServiceMsg(history, block, clientMsgId(), QDateTime(date), langDayOfMonthFull(date)) {
|
||||
}
|
||||
|
||||
void HistoryDateMsg::setDate(const QDateTime &date) {
|
||||
if (this->date.date() != date.date()) {
|
||||
setServiceText(langDayOfMonthFull(date.date()));
|
||||
}
|
||||
HistoryServiceMsg::setDate(date);
|
||||
}
|
||||
|
||||
HistoryItem *createDayServiceMsg(History *history, HistoryBlock *block, QDateTime date) {
|
||||
return regItem(new HistoryDateMsg(history, block, date.date()));
|
||||
}
|
||||
|
|
|
@ -937,6 +937,9 @@ public:
|
|||
virtual void setViewsCount(int32 count) {
|
||||
}
|
||||
virtual void setId(MsgId newId);
|
||||
virtual void setDate(const QDateTime &date) { // for date items
|
||||
this->date = date;
|
||||
}
|
||||
virtual void drawInDialog(Painter &p, const QRect &r, bool act, const HistoryItem *&cacheFor, Text &cache) const = 0;
|
||||
virtual QString notificationHeader() const {
|
||||
return QString();
|
||||
|
@ -2229,6 +2232,7 @@ public:
|
|||
after = false;
|
||||
upon = false;
|
||||
}
|
||||
void setDate(const QDateTime &date);
|
||||
QString selectedText(uint32 selection) const {
|
||||
return QString();
|
||||
}
|
||||
|
|
|
@ -77,10 +77,17 @@ class MTPlong;
|
|||
QString logVectorLong(const QVector<MTPlong> &ids);
|
||||
QString logVectorLong(const QVector<uint64> &ids);
|
||||
|
||||
void logWrite(const QString &v);
|
||||
|
||||
#define LOG(msg) (logWrite(QString msg))
|
||||
//usage LOG(("log: %1 %2").arg(1).arg(2))
|
||||
|
||||
void logWrite(const QString &v);
|
||||
inline void t_noop() {}
|
||||
inline void t_assert_fail(const char *condition, const char *file, int32 line) {
|
||||
LOG(("Assertion Failed! \"%1\" %2:%3").arg(condition).arg(file).arg(line));
|
||||
abort();
|
||||
}
|
||||
#define t_assert(cond) ((!(cond)) ? t_assert_fail(#cond, __FILE__, __LINE__) : t_noop())
|
||||
|
||||
void logsInit();
|
||||
void logsInitDebug();
|
||||
|
|
|
@ -1215,9 +1215,6 @@ void OverviewInner::leaveEvent(QEvent *e) {
|
|||
}
|
||||
|
||||
void OverviewInner::resizeEvent(QResizeEvent *e) {
|
||||
_search.setGeometry(_rowsLeft, st::linksSearchMargin.top(), _rowWidth, _search.height());
|
||||
_cancelSearch.moveToLeft(_rowsLeft + _rowWidth - _cancelSearch.width(), _search.y());
|
||||
|
||||
onUpdateSelected();
|
||||
update();
|
||||
}
|
||||
|
@ -1372,6 +1369,10 @@ int32 OverviewInner::resizeToWidth(int32 nwidth, int32 scrollTop, int32 minHeigh
|
|||
_rowWidth = qMin(_width - st::profilePadding.left() - st::profilePadding.right(), int32(st::profileMaxWidth));
|
||||
}
|
||||
_rowsLeft = (_width - _rowWidth) / 2;
|
||||
|
||||
_search.setGeometry(_rowsLeft, st::linksSearchMargin.top(), _rowWidth, _search.height());
|
||||
_cancelSearch.moveToLeft(_rowsLeft + _rowWidth - _cancelSearch.width(), _search.y());
|
||||
|
||||
if (_type == OverviewPhotos || _type == OverviewVideos) {
|
||||
for (int32 i = 0, l = _items.size(); i < l; ++i) {
|
||||
_items.at(i)->resizeGetHeight(_rowWidth);
|
||||
|
|
Loading…
Add table
Reference in a new issue