From bb416b520af7acb0dd3ba890bd50d72d2253cf0a Mon Sep 17 00:00:00 2001 From: John Preston Date: Tue, 27 Oct 2015 20:29:39 -0400 Subject: [PATCH] improved messages to self: always not unread, show sending clock icon --- Telegram/SourceFiles/app.cpp | 4 +-- Telegram/SourceFiles/history.cpp | 49 +++++++++++++++----------- Telegram/SourceFiles/history.h | 12 +++++-- Telegram/SourceFiles/historywidget.cpp | 2 +- Telegram/SourceFiles/mainwidget.cpp | 7 ++-- Telegram/SourceFiles/structs.h | 6 ++-- 6 files changed, 50 insertions(+), 30 deletions(-) diff --git a/Telegram/SourceFiles/app.cpp b/Telegram/SourceFiles/app.cpp index 4da05c653..e632db866 100644 --- a/Telegram/SourceFiles/app.cpp +++ b/Telegram/SourceFiles/app.cpp @@ -967,8 +967,8 @@ namespace App { } } - bool showPhone = !isServiceUser(user->id) && (user->input.type() != mtpc_inputPeerSelf) && !user->contact; - bool showPhoneChanged = !isServiceUser(user->id) && (user->input.type() != mtpc_inputPeerSelf) && ((showPhone && !wasShowPhone) || (!showPhone && wasShowPhone)); + bool showPhone = !isServiceUser(user->id) && !user->isSelf() && !user->contact; + bool showPhoneChanged = !isServiceUser(user->id) && !user->isSelf() && ((showPhone && !wasShowPhone) || (!showPhone && wasShowPhone)); if (showPhoneChanged) { user->setName(textOneLine(user->firstName), textOneLine(user->lastName), showPhone ? App::formatPhone(user->phone) : QString(), textOneLine(user->username)); } diff --git a/Telegram/SourceFiles/history.cpp b/Telegram/SourceFiles/history.cpp index f664c8ecc..8f8d41a0b 100644 --- a/Telegram/SourceFiles/history.cpp +++ b/Telegram/SourceFiles/history.cpp @@ -891,13 +891,7 @@ HistoryItem *ChannelHistory::addNewToBlocks(const MTPMessage &msg, NewMessageTyp if (item && isImportant) { setLastMessage(item); if (type == NewMessageUnread) { - if (item->unread()) { - newItemAdded(item); - } else if (item->out()) { - outboxRead(item); - } else { - inboxRead(item); - } + newItemAdded(item); } } return item; @@ -1565,13 +1559,7 @@ HistoryItem *History::addNewMessage(const MTPMessage &msg, NewMessageType type) if (item) { setLastMessage(item); if (type == NewMessageUnread) { - if (item->unread()) { - newItemAdded(item); - } else if (item->out()) { - outboxRead(item); - } else { - inboxRead(item); - } + newItemAdded(item); } } return item; @@ -1677,13 +1665,7 @@ HistoryItem *History::addNewItem(HistoryBlock *to, bool newBlock, HistoryItem *a height += dh; } if (newMsg) { - if (adding->unread()) { - newItemAdded(adding); - } else if (adding->out()) { - outboxRead(adding); - } else { - inboxRead(adding); - } + newItemAdded(adding); } if (!isChannel() || adding->fromChannel()) { @@ -1764,12 +1746,17 @@ void History::newItemAdded(HistoryItem *item) { } if (item->out()) { if (unreadBar) unreadBar->destroy(); + if (!item->unread()) { + outboxRead(item); + } } else if (item->unread()) { bool skip = false; if (!isChannel() || peer->asChannel()->amIn()) { notifies.push_back(item); App::main()->newUnreadMsg(this, item); } + } else { + inboxRead(item); } } @@ -6379,6 +6366,10 @@ void HistoryMessage::drawInfo(Painter &p, int32 right, int32 bottom, bool select } } p.drawPixmap(iconPos, App::sprite(), *iconRect); + } else if (id < 0 && history()->peer->isSelf()) { + iconPos = QPoint(infoRight - infoW, infoBottom - st::msgViewsImg.pxHeight() + st::msgViewsPos.y()); + iconRect = &(overimg ? st::msgInvSendingViewsImg : st::msgSendingViewsImg); + p.drawPixmap(iconPos, App::sprite(), *iconRect); } if (out() && !fromChannel()) { iconPos = QPoint(infoRight - st::msgCheckImg.pxWidth() + st::msgCheckPos.x(), infoBottom - st::msgCheckImg.pxHeight() + st::msgCheckPos.y()); @@ -6415,6 +6406,22 @@ void HistoryMessage::setViewsCount(int32 count) { } } +void HistoryMessage::setId(MsgId newId) { + bool wasPositive = (id > 0), positive = (newId > 0); + id = newId; + if (wasPositive == positive) { + if (App::main()) App::main()->msgUpdated(history()->peer->id, this); + } else { + if (_text.hasSkipBlock()) { + _text.setSkipBlock(HistoryMessage::skipBlockWidth(), HistoryMessage::skipBlockHeight()); + _textWidth = 0; + _textHeight = 0; + } + initDimensions(); + if (App::main()) App::main()->itemResized(this); + } +} + void HistoryMessage::draw(Painter &p, uint32 selection) const { bool outbg = out() && !fromChannel(); diff --git a/Telegram/SourceFiles/history.h b/Telegram/SourceFiles/history.h index 32d42af30..e5829e10a 100644 --- a/Telegram/SourceFiles/history.h +++ b/Telegram/SourceFiles/history.h @@ -831,7 +831,7 @@ public: } bool unread() const { if ((out() && (id > 0 && id < _history->outboxReadBefore)) || (!out() && id > 0 && id < _history->inboxReadBefore)) return false; - return (id > 0 && !out() && channelId() != NoChannel) ? true : (_flags & MTPDmessage_flag_unread); + return (id > 0 && !out() && channelId() != NoChannel) ? true : (history()->peer->isSelf() ? false : (_flags & MTPDmessage_flag_unread)); } bool notifyByFrom() const { return _flags & MTPDmessage_flag_notify_by_from; @@ -858,7 +858,7 @@ public: return _history->isChannel() && isImportantChannelMessage(id, _flags); } virtual bool needCheck() const { - return out(); + return out() || (id < 0 && history()->peer->isSelf()); } virtual bool hasPoint(int32 x, int32 y) const { return false; @@ -898,6 +898,9 @@ public: } virtual void setViewsCount(int32 count) { } + virtual void setId(MsgId newId) { + id = newId; + } virtual void drawInDialog(Painter &p, const QRect &r, bool act, const HistoryItem *&cacheFor, Text &cache) const = 0; virtual QString notificationHeader() const { return QString(); @@ -1524,6 +1527,7 @@ public: void drawInfo(Painter &p, int32 right, int32 bottom, bool selected, InfoDisplayType type) const; void setViewsCount(int32 count); + void setId(MsgId newId); void draw(Painter &p, uint32 selection) const; virtual void drawMessageText(Painter &p, const QRect &trect, uint32 selection) const; @@ -1564,6 +1568,8 @@ public: int32 result = _timeWidth; if (!_viewsText.isEmpty()) { result += st::msgDateViewsSpace + _viewsWidth + st::msgDateCheckSpace + st::msgViewsImg.pxWidth(); + } else if (id < 0 && history()->peer->isSelf()) { + result += st::msgDateCheckSpace + st::msgCheckImg.pxWidth(); } if (out() && !fromChannel()) { result += st::msgDateCheckSpace + st::msgCheckImg.pxWidth(); @@ -1574,6 +1580,8 @@ public: int32 result = 0; if (!_viewsText.isEmpty()) { result += st::msgDateViewsSpace + _viewsWidth + st::msgDateCheckSpace + st::msgViewsImg.pxWidth(); + } else if (id < 0 && history()->peer->isSelf()) { + result += st::msgDateCheckSpace + st::msgCheckImg.pxWidth(); } return result; } diff --git a/Telegram/SourceFiles/historywidget.cpp b/Telegram/SourceFiles/historywidget.cpp index 8fcefca4e..c13040fed 100644 --- a/Telegram/SourceFiles/historywidget.cpp +++ b/Telegram/SourceFiles/historywidget.cpp @@ -5765,7 +5765,7 @@ void HistoryWidget::onStickerSend(DocumentData *sticker) { bool lastKeyboardUsed = lastForceReplyReplied(); - bool out = (_peer->input.type() != mtpc_inputPeerSelf), unread = (_peer->input.type() != mtpc_inputPeerSelf); + bool out = !_peer->isSelf(), unread = !_peer->isSelf(); int32 flags = newMessageFlags(_peer) | MTPDmessage::flag_media; // unread, out int32 sendFlags = 0; if (replyToId()) { diff --git a/Telegram/SourceFiles/mainwidget.cpp b/Telegram/SourceFiles/mainwidget.cpp index 477af25ee..6bd4a026c 100644 --- a/Telegram/SourceFiles/mainwidget.cpp +++ b/Telegram/SourceFiles/mainwidget.cpp @@ -4318,7 +4318,10 @@ void MainWidget::feedUpdate(const MTPUpdate &update) { } } if (App::wnd()) App::wnd()->changingMsgId(msgRow, d.vid.v); - msgRow->id = d.vid.v; + msgRow->setId(d.vid.v); + if (msgRow->history()->peer->isSelf()) { + msgRow->history()->unregTyping(App::self()); + } if (!App::historyRegItem(msgRow)) { msgUpdated(h->peer->id, msgRow); } else { @@ -4560,7 +4563,7 @@ void MainWidget::feedUpdate(const MTPUpdate &update) { UserData *user = App::userLoaded(d.vuser_id.v); if (user) { user->setPhone(qs(d.vphone)); - user->setName(user->firstName, user->lastName, (user->contact || isServiceUser(user->id) || user->input.type() == mtpc_inputPeerSelf || user->phone.isEmpty()) ? QString() : App::formatPhone(user->phone), user->username); + user->setName(user->firstName, user->lastName, (user->contact || isServiceUser(user->id) || user->isSelf() || user->phone.isEmpty()) ? QString() : App::formatPhone(user->phone), user->username); App::markPeerUpdated(user); } } break; diff --git a/Telegram/SourceFiles/structs.h b/Telegram/SourceFiles/structs.h index 2014ebd39..ee4fd448e 100644 --- a/Telegram/SourceFiles/structs.h +++ b/Telegram/SourceFiles/structs.h @@ -207,6 +207,9 @@ public: bool isChannel() const { return peerIsChannel(id); } + bool isSelf() const { + return (input.type() == mtpc_inputPeerSelf); + } UserData *asUser(); const UserData *asUser() const; ChatData *asChat(); @@ -582,9 +585,8 @@ inline const QString &PeerData::userName() const { return isUser() ? asUser()->username : (isChannel() ? asChannel()->username : emptyUsername()); } - inline int32 newMessageFlags(PeerData *p) { - return (p->input.type() == mtpc_inputPeerSelf) ? 0 : (((p->isChat() || (p->isUser() && !p->asUser()->botInfo)) ? MTPDmessage_flag_unread : 0) | MTPDmessage_flag_out); + return p->isSelf() ? 0 : (((p->isChat() || (p->isUser() && !p->asUser()->botInfo)) ? MTPDmessage_flag_unread : 0) | MTPDmessage_flag_out); } typedef QMap PreparedPhotoThumbs;