fixed crash in showNextNotify, started reportspam button

This commit is contained in:
John Preston 2015-09-07 18:53:46 +03:00
parent 42d297f192
commit c45d9e9860
12 changed files with 123 additions and 8 deletions

View File

@ -566,10 +566,17 @@ namespace App {
int32 pversion = chat->participants.isEmpty() ? 1 : (chat->participants.begin().value() + 1); int32 pversion = chat->participants.isEmpty() ? 1 : (chat->participants.begin().value() + 1);
chat->cankick = ChatData::CanKick(); chat->cankick = ChatData::CanKick();
for (QVector<MTPChatParticipant>::const_iterator i = v.cbegin(), e = v.cend(); i != e; ++i) { for (QVector<MTPChatParticipant>::const_iterator i = v.cbegin(), e = v.cend(); i != e; ++i) {
UserData *user = App::userLoaded(i->c_chatParticipant().vuser_id.v); if (i->type() != mtpc_chatParticipant) continue;
const MTPDchatParticipant &p(i->c_chatParticipant());
//if (p.vuser_id.v == MTP::authedId()) {
// chat->inviter = p.vinviter_id.v; // we use inviter only from service msgs
// chat->inviteDate = p.vdate.v;
//}
UserData *user = App::userLoaded(p.vuser_id.v);
if (user) { if (user) {
chat->participants[user] = pversion; chat->participants[user] = pversion;
if (i->c_chatParticipant().vinviter_id.v == MTP::authedId()) { if (p.vinviter_id.v == MTP::authedId()) {
chat->cankick[user] = true; chat->cankick[user] = true;
} }
} else { } else {
@ -619,6 +626,10 @@ namespace App {
ChatData *chat = App::chat(d.vchat_id.v); ChatData *chat = App::chat(d.vchat_id.v);
if (chat->version <= d.vversion.v && chat->count >= 0) { if (chat->version <= d.vversion.v && chat->count >= 0) {
chat->version = d.vversion.v; chat->version = d.vversion.v;
//if (d.vuser_id.v == MTP::authedId()) {
// chat->inviter = d.vinviter_id.v; // we use inviter only from service msgs
// chat->inviteDate = unixtime(); // no event date here :(
//}
UserData *user = App::userLoaded(d.vuser_id.v); UserData *user = App::userLoaded(d.vuser_id.v);
if (user) { if (user) {
if (chat->participants.isEmpty() && chat->count) { if (chat->participants.isEmpty() && chat->count) {

View File

@ -814,7 +814,6 @@ void DialogsListWidget::peopleReceived(const QString &query, const QVector<MTPCo
} }
void DialogsListWidget::contactsReceived(const QVector<MTPContact> &contacts) { void DialogsListWidget::contactsReceived(const QVector<MTPContact> &contacts) {
cSetContactsReceived(true);
for (QVector<MTPContact>::const_iterator i = contacts.cbegin(), e = contacts.cend(); i != e; ++i) { for (QVector<MTPContact>::const_iterator i = contacts.cbegin(), e = contacts.cend(); i != e; ++i) {
int32 uid = i->c_contact().vuser_id.v; int32 uid = i->c_contact().vuser_id.v;
addNewContact(uid); addNewContact(uid);
@ -1739,11 +1738,13 @@ void DialogsWidget::loadDialogs() {
} }
void DialogsWidget::contactsReceived(const MTPcontacts_Contacts &contacts) { void DialogsWidget::contactsReceived(const MTPcontacts_Contacts &contacts) {
cSetContactsReceived(true);
if (contacts.type() == mtpc_contacts_contacts) { if (contacts.type() == mtpc_contacts_contacts) {
const MTPDcontacts_contacts &d(contacts.c_contacts_contacts()); const MTPDcontacts_contacts &d(contacts.c_contacts_contacts());
App::feedUsers(d.vusers); App::feedUsers(d.vusers);
list.contactsReceived(d.vcontacts.c_vector().v); list.contactsReceived(d.vcontacts.c_vector().v);
} }
if (App::main()) App::main()->contactsReceived();
} }
bool DialogsWidget::contactsFailed(const RPCError &error) { bool DialogsWidget::contactsFailed(const RPCError &error) {

View File

@ -2198,6 +2198,7 @@ HistoryWidget::HistoryWidget(QWidget *parent) : TWidget(parent)
, _replyTo(0) , _replyTo(0)
, _replyToNameVersion(0) , _replyToNameVersion(0)
, _replyForwardPreviewCancel(this, st::replyCancel) , _replyForwardPreviewCancel(this, st::replyCancel)
, _reportSpamStatus(ReportSpamUnknown)
, _previewData(0) , _previewData(0)
, _previewRequest(0) , _previewRequest(0)
, _previewCancelled(false) , _previewCancelled(false)
@ -2905,6 +2906,76 @@ void HistoryWidget::clearAllLoadRequests() {
_preloadRequest = _preloadDownRequest = _firstLoadRequest = 0; _preloadRequest = _preloadDownRequest = _firstLoadRequest = 0;
} }
void HistoryWidget::contactsReceived() {
if (!_peer) return;
updateReportSpamStatus();
updateControlsVisibility();
}
void HistoryWidget::updateReportSpamStatus() {
if (!_peer || cNoReportSpamButton().contains(_peer->id)) {
_reportSpamStatus = ReportSpamNoButton;
return;
} else if (cShowReportSpamButton().contains(_peer->id)) {
_reportSpamStatus = ReportSpamShowButton;
return;
}
if (!cContactsReceived()) {
_reportSpamStatus = ReportSpamUnknown;
} else if (_peer->chat) {
if (_firstLoadRequest && !_peer->asChat()->inviterForSpamReport) {
_reportSpamStatus = ReportSpamUnknown;
} else if (_peer->asChat()->inviterForSpamReport > 0) {
UserData *user = App::userLoaded(_peer->asChat()->inviterForSpamReport);
if (user && user->contact > 0) {
_reportSpamStatus = ReportSpamNoButton;
} else {
_reportSpamStatus = ReportSpamShowButton;
}
} else {
_reportSpamStatus = ReportSpamNoButton;
}
} else {
if (_peer->asUser()->contact > 0) {
_reportSpamStatus = ReportSpamNoButton;
} else {
if (_firstLoadRequest) {
_reportSpamStatus = ReportSpamUnknown;
} else {
bool anyFound = false, outFound = false;
for (int32 i = 0, l = _history->size(); i < l; ++i) {
for (int32 j = 0, c = _history->at(i)->size(); j < c; ++j) {
anyFound = true;
if (_history->at(i)->at(j)->out()) {
outFound = true;
break;
}
}
}
if (anyFound) {
if (outFound) {
_reportSpamStatus = ReportSpamNoButton;
} else {
_reportSpamStatus = ReportSpamShowButton;
}
} else {
_reportSpamStatus = ReportSpamUnknown;
}
}
}
}
if (_reportSpamStatus == ReportSpamShowButton || _reportSpamStatus == ReportSpamNoButton) {
if (_reportSpamStatus == ReportSpamShowButton) {
cRefNoReportSpamButton().remove(_peer->id);
cRefShowReportSpamButton().insert(_peer->id, true);
} else {
cRefNoReportSpamButton().insert(_peer->id, true);
cRefShowReportSpamButton().remove(_peer->id);
}
Local::writeReportSpamStatuses();
}
}
void HistoryWidget::updateControlsVisibility() { void HistoryWidget::updateControlsVisibility() {
if (!_history || _showAnim.animating()) { if (!_history || _showAnim.animating()) {
_scroll.hide(); _scroll.hide();
@ -3519,6 +3590,7 @@ bool HistoryWidget::showStep(float64 ms) {
} }
void HistoryWidget::doneShow() { void HistoryWidget::doneShow() {
updateReportSpamStatus();
updateBotKeyboard(); updateBotKeyboard();
updateControlsVisibility(); updateControlsVisibility();
updateListSize(0, true); updateListSize(0, true);
@ -5167,6 +5239,7 @@ void HistoryWidget::onFullPeerUpdated(PeerData *data) {
int32 newScrollTop = _scroll.scrollTop(); int32 newScrollTop = _scroll.scrollTop();
if (_list && data == _peer) { if (_list && data == _peer) {
checkMentionDropdown(); checkMentionDropdown();
updateReportSpamStatus();
int32 lh = _list->height(), st = _scroll.scrollTop(); int32 lh = _list->height(), st = _scroll.scrollTop();
_list->updateBotInfo(); _list->updateBotInfo();
newScrollTop = st + _list->height() - lh; newScrollTop = st + _list->height() - lh;

View File

@ -478,6 +478,8 @@ public:
void clearDelayedShowAt(); void clearDelayedShowAt();
void clearAllLoadRequests(); void clearAllLoadRequests();
void contactsReceived();
~HistoryWidget(); ~HistoryWidget();
signals: signals:
@ -585,6 +587,14 @@ private:
void drawRecording(Painter &p); void drawRecording(Painter &p);
void updateField(); void updateField();
enum ReportSpamStatus {
ReportSpamNoButton,
ReportSpamUnknown,
ReportSpamShowButton,
};
ReportSpamStatus _reportSpamStatus;
void updateReportSpamStatus();
QString _previewLinks; QString _previewLinks;
WebPageData *_previewData; WebPageData *_previewData;
typedef QMap<QString, WebPageId> PreviewCache; typedef QMap<QString, WebPageId> PreviewCache;

View File

@ -2944,6 +2944,10 @@ namespace Local {
} }
} }
void writeReportSpamStatuses() {
}
struct ClearManagerData { struct ClearManagerData {
QThread *thread; QThread *thread;
StorageMap images, stickers, audios; StorageMap images, stickers, audios;

View File

@ -147,4 +147,6 @@ namespace Local {
void removeSavedPeer(PeerData *peer); void removeSavedPeer(PeerData *peer);
void readSavedPeers(); void readSavedPeers();
void writeReportSpamStatuses();
}; };

View File

@ -1967,6 +1967,10 @@ void MainWidget::clearBotStartToken(PeerData *peer) {
} }
} }
void MainWidget::contactsReceived() {
history.contactsReceived();
}
void MainWidget::showPeerHistory(quint64 peerId, qint32 showAtMsgId, bool back) { void MainWidget::showPeerHistory(quint64 peerId, qint32 showAtMsgId, bool back) {
if (!back && (!peerId || (_stack.size() == 1 && _stack[0]->type() == HistoryStackItem && _stack[0]->peer->id == peerId))) { if (!back && (!peerId || (_stack.size() == 1 && _stack[0]->type() == HistoryStackItem && _stack[0]->peer->id == peerId))) {
back = true; back = true;

View File

@ -377,6 +377,8 @@ public:
void choosePeer(PeerId peerId, MsgId showAtMsgId); // does offerPeer or showPeerHistory void choosePeer(PeerId peerId, MsgId showAtMsgId); // does offerPeer or showPeerHistory
void clearBotStartToken(PeerData *peer); void clearBotStartToken(PeerData *peer);
void contactsReceived();
~MainWidget(); ~MainWidget();
signals: signals:

View File

@ -160,6 +160,9 @@ float64 gSongVolume = 0.9;
SavedPeers gSavedPeers; SavedPeers gSavedPeers;
SavedPeersByTime gSavedPeersByTime; SavedPeersByTime gSavedPeersByTime;
ReportSpamButtons gShowReportSpamButton;
ReportSpamButtons gNoReportSpamButton;
void settingsParseArgs(int argc, char *argv[]) { void settingsParseArgs(int argc, char *argv[]) {
#ifdef Q_OS_MAC #ifdef Q_OS_MAC
if (QSysInfo::macVersion() < QSysInfo::MV_10_8) { if (QSysInfo::macVersion() < QSysInfo::MV_10_8) {

View File

@ -317,4 +317,8 @@ typedef QMultiMap<QDateTime, PeerData*> SavedPeersByTime;
DeclareRefSetting(SavedPeers, SavedPeers); DeclareRefSetting(SavedPeers, SavedPeers);
DeclareRefSetting(SavedPeersByTime, SavedPeersByTime); DeclareRefSetting(SavedPeersByTime, SavedPeersByTime);
typedef QMap<uint64, bool> ReportSpamButtons;
DeclareRefSetting(ReportSpamButtons, ShowReportSpamButton);
DeclareRefSetting(ReportSpamButtons, NoReportSpamButton);
void settingsParseArgs(int argc, char *argv[]); void settingsParseArgs(int argc, char *argv[]);

View File

@ -208,13 +208,14 @@ struct UserData : public PeerData {
}; };
struct ChatData : public PeerData { struct ChatData : public PeerData {
ChatData(const PeerId &id) : PeerData(id), count(0), date(0), version(0), left(false), forbidden(true), botStatus(0) { ChatData(const PeerId &id) : PeerData(id), count(0), date(0), version(0), inviterForSpamReport(0), left(false), forbidden(true), botStatus(0) {
} }
void setPhoto(const MTPChatPhoto &photo, const PhotoId &phId = UnknownPeerPhotoId); void setPhoto(const MTPChatPhoto &photo, const PhotoId &phId = UnknownPeerPhotoId);
int32 count; int32 count;
int32 date; int32 date;
int32 version; int32 version;
int32 admin; int32 admin;
int32 inviterForSpamReport; // > 0 - user who invited me to chat in unread service msg, < 0 - have outgoing message
bool left; bool left;
bool forbidden; bool forbidden;
typedef QMap<UserData*, int32> Participants; typedef QMap<UserData*, int32> Participants;

View File

@ -1418,7 +1418,7 @@ void Window::notifyShowNext(NotifyWindow *remove) {
HistoryItem *notifyItem = 0; HistoryItem *notifyItem = 0;
History *notifyHistory = 0; History *notifyHistory = 0;
NotifyWaiters::iterator notifyWaiter = notifyWaiters.end(); NotifyWaiters::iterator notifyWaiter = notifyWaiters.end();
for (NotifyWaiters::iterator i = notifyWaiters.begin(); i != notifyWaiters.end(); ++i) { for (NotifyWaiters::iterator i = notifyWaiters.begin(); i != notifyWaiters.end();) {
History *history = i.key(); History *history = i.key();
if (history->currentNotification() && history->currentNotification()->id != i.value().msg) { if (history->currentNotification() && history->currentNotification()->id != i.value().msg) {
NotifyWhenMaps::iterator j = notifyWhenMaps.find(history); NotifyWhenMaps::iterator j = notifyWhenMaps.find(history);
@ -1451,6 +1451,7 @@ void Window::notifyShowNext(NotifyWindow *remove) {
notifyHistory = history; notifyHistory = history;
notifyWaiter = i; notifyWaiter = i;
} }
++i;
} }
if (notifyItem) { if (notifyItem) {
if (next > ms) { if (next > ms) {
@ -1467,8 +1468,7 @@ void Window::notifyShowNext(NotifyWindow *remove) {
uint64 ms = getms(true); uint64 ms = getms(true);
History *history = notifyItem->history(); History *history = notifyItem->history();
NotifyWhenMaps::iterator j = notifyWhenMaps.find(history); NotifyWhenMaps::iterator j = notifyWhenMaps.find(history);
bool notifyWhenFound = (j != notifyWhenMaps.cend()); if (j == notifyWhenMaps.cend()) {
if (!notifyWhenFound) {
history->clearNotifications(); history->clearNotifications();
} else { } else {
HistoryItem *nextNotify = 0; HistoryItem *nextNotify = 0;
@ -1516,7 +1516,7 @@ void Window::notifyShowNext(NotifyWindow *remove) {
if (!history->hasNotification()) { if (!history->hasNotification()) {
if (notifyWaiter != notifyWaiters.cend()) notifyWaiters.erase(notifyWaiter); if (notifyWaiter != notifyWaiters.cend()) notifyWaiters.erase(notifyWaiter);
if (notifyWhenFound) notifyWhenMaps.erase(j); notifyWhenMaps.remove(history);
continue; continue;
} }
} }