mirror of
https://github.com/telegramdesktop/tdesktop
synced 2025-02-04 06:11:17 +00:00
cloud synced report spam panel visibility
This commit is contained in:
parent
17aaa5ceab
commit
5aa5a62b74
@ -433,8 +433,8 @@ namespace App {
|
||||
data->setBotInfoVersion(-1);
|
||||
}
|
||||
data->contact = (d.is_contact() || d.is_mutual_contact()) ? 1 : (data->phone.isEmpty() ? -1 : 0);
|
||||
if (data->contact == 1 && cReportSpamStatuses().value(data->id, dbiprsNoButton) != dbiprsNoButton) {
|
||||
cRefReportSpamStatuses().insert(data->id, dbiprsNoButton);
|
||||
if (data->contact == 1 && cReportSpamStatuses().value(data->id, dbiprsHidden) != dbiprsHidden) {
|
||||
cRefReportSpamStatuses().insert(data->id, dbiprsHidden);
|
||||
Local::writeReportSpamStatuses();
|
||||
}
|
||||
if (d.is_self() && ::self != data) {
|
||||
@ -1158,8 +1158,8 @@ namespace App {
|
||||
switch (myLink.type()) {
|
||||
case mtpc_contactLinkContact:
|
||||
user->contact = 1;
|
||||
if (user->contact == 1 && cReportSpamStatuses().value(user->id, dbiprsNoButton) != dbiprsNoButton) {
|
||||
cRefReportSpamStatuses().insert(user->id, dbiprsNoButton);
|
||||
if (user->contact == 1 && cReportSpamStatuses().value(user->id, dbiprsHidden) != dbiprsHidden) {
|
||||
cRefReportSpamStatuses().insert(user->id, dbiprsHidden);
|
||||
Local::writeReportSpamStatuses();
|
||||
}
|
||||
break;
|
||||
|
@ -7417,9 +7417,6 @@ void HistoryServiceMsg::setMessageByAction(const MTPmessageAction &action) {
|
||||
text = lng_action_add_users_many(lt_from, from, lt_users, text);
|
||||
}
|
||||
if (foundSelf) {
|
||||
if (unread() && history()->peer->isChat() && !history()->peer->asChat()->inviterForSpamReport && _from->isUser()) {
|
||||
history()->peer->asChat()->inviterForSpamReport = peerToUser(_from->id);
|
||||
}
|
||||
if (history()->peer->isMegagroup()) {
|
||||
history()->peer->asChannel()->mgInfo->joinedMessageFound = true;
|
||||
}
|
||||
@ -7443,11 +7440,6 @@ void HistoryServiceMsg::setMessageByAction(const MTPmessageAction &action) {
|
||||
case mtpc_messageActionChatCreate: {
|
||||
const MTPDmessageActionChatCreate &d(action.c_messageActionChatCreate());
|
||||
text = lng_action_created_chat(lt_from, from, lt_title, textClean(qs(d.vtitle)));
|
||||
if (unread()) {
|
||||
if (history()->peer->isChat() && !history()->peer->asChat()->inviterForSpamReport && _from->isUser() && peerToUser(_from->id) != MTP::authedId()) {
|
||||
history()->peer->asChat()->inviterForSpamReport = peerToUser(_from->id);
|
||||
}
|
||||
}
|
||||
} break;
|
||||
|
||||
case mtpc_messageActionChannelCreate: {
|
||||
|
@ -2647,6 +2647,7 @@ HistoryWidget::HistoryWidget(QWidget *parent) : TWidget(parent)
|
||||
, _pinnedBar(0)
|
||||
, _saveEditMsgRequestId(0)
|
||||
, _reportSpamStatus(dbiprsUnknown)
|
||||
, _reportSpamSettingRequestId(ReportSpamRequestNeeded)
|
||||
, _previewData(0)
|
||||
, _previewRequest(0)
|
||||
, _previewCancelled(false)
|
||||
@ -3644,6 +3645,10 @@ void HistoryWidget::showHistory(const PeerId &peerId, MsgId showAtMsgId, bool re
|
||||
}
|
||||
|
||||
_unblockRequest = _reportSpamRequest = 0;
|
||||
if (_reportSpamSettingRequestId > 0) {
|
||||
MTP::cancel(_reportSpamSettingRequestId);
|
||||
}
|
||||
_reportSpamSettingRequestId = ReportSpamRequestNeeded;
|
||||
|
||||
_titlePeerText = QString();
|
||||
_titlePeerTextWidth = 0;
|
||||
@ -3789,96 +3794,94 @@ bool HistoryWidget::contentOverlapped(const QRect &globalRect) {
|
||||
|
||||
void HistoryWidget::updateReportSpamStatus() {
|
||||
if (!_peer || (_peer->isUser() && (peerToUser(_peer->id) == MTP::authedId() || isNotificationsUser(_peer->id) || isServiceUser(_peer->id) || _peer->asUser()->botInfo))) {
|
||||
_reportSpamStatus = dbiprsNoButton;
|
||||
_reportSpamStatus = dbiprsHidden;
|
||||
return;
|
||||
} else {
|
||||
ReportSpamStatuses::const_iterator i = cReportSpamStatuses().constFind(_peer->id);
|
||||
if (i != cReportSpamStatuses().cend()) {
|
||||
_reportSpamStatus = i.value();
|
||||
if (_reportSpamStatus == dbiprsNoButton) {
|
||||
_reportSpamStatus = dbiprsHidden;
|
||||
if (!_peer->isUser() || _peer->asUser()->contact < 1) {
|
||||
MTP::send(MTPmessages_HideReportSpam(_peer->input));
|
||||
}
|
||||
|
||||
cRefReportSpamStatuses().insert(_peer->id, _reportSpamStatus);
|
||||
Local::writeReportSpamStatuses();
|
||||
} else if (_reportSpamStatus == dbiprsShowButton) {
|
||||
requestReportSpamSetting();
|
||||
}
|
||||
_reportSpamPanel.setReported(_reportSpamStatus == dbiprsReportSent, _peer);
|
||||
return;
|
||||
} else if (_peer->migrateFrom()) { // migrate report status
|
||||
i = cReportSpamStatuses().constFind(_peer->migrateFrom()->id);
|
||||
if (i != cReportSpamStatuses().cend()) {
|
||||
_reportSpamStatus = i.value();
|
||||
_reportSpamPanel.setReported(_reportSpamStatus == dbiprsReportSent, _peer);
|
||||
if (_reportSpamStatus == dbiprsNoButton) {
|
||||
_reportSpamStatus = dbiprsHidden;
|
||||
if (!_peer->isUser() || _peer->asUser()->contact < 1) {
|
||||
MTP::send(MTPmessages_HideReportSpam(_peer->input));
|
||||
}
|
||||
} else if (_reportSpamStatus == dbiprsShowButton) {
|
||||
requestReportSpamSetting();
|
||||
}
|
||||
cRefReportSpamStatuses().insert(_peer->id, _reportSpamStatus);
|
||||
Local::writeReportSpamStatuses();
|
||||
|
||||
_reportSpamPanel.setReported(_reportSpamStatus == dbiprsReportSent, _peer);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!cContactsReceived() || _firstLoadRequest) {
|
||||
if (!cContactsReceived()) {
|
||||
_reportSpamStatus = dbiprsUnknown;
|
||||
} else if (!_history->loadedAtTop() && (_history->blocks.size() < 2 || (_history->blocks.size() == 2 && _history->blocks.at(1)->items.size() < 2))) {
|
||||
_reportSpamStatus = dbiprsUnknown;
|
||||
} else if (_peer->isUser()) {
|
||||
if (_peer->asUser()->contact > 0) {
|
||||
_reportSpamStatus = dbiprsNoButton;
|
||||
} else {
|
||||
bool anyFound = false, outFound = false;
|
||||
for (int32 i = 0, l = _history->blocks.size(); i < l; ++i) {
|
||||
for (int32 j = 0, c = _history->blocks.at(i)->items.size(); j < c; ++j) {
|
||||
anyFound = true;
|
||||
if (_history->blocks.at(i)->items.at(j)->out()) {
|
||||
outFound = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (anyFound) {
|
||||
if (outFound) {
|
||||
_reportSpamStatus = dbiprsNoButton;
|
||||
} else {
|
||||
_reportSpamStatus = dbiprsShowButton;
|
||||
}
|
||||
} else {
|
||||
_reportSpamStatus = dbiprsUnknown;
|
||||
}
|
||||
}
|
||||
} else if (_peer->isChat()) {
|
||||
if (_peer->asChat()->inviterForSpamReport > 0) {
|
||||
UserData *user = App::userLoaded(_peer->asChat()->inviterForSpamReport);
|
||||
if (user && user->contact > 0) {
|
||||
_reportSpamStatus = dbiprsNoButton;
|
||||
} else {
|
||||
_reportSpamStatus = dbiprsShowButton;
|
||||
}
|
||||
} else {
|
||||
_reportSpamStatus = dbiprsNoButton;
|
||||
}
|
||||
} else if (_peer->isChannel()) {
|
||||
if (_peer->migrateFrom() && _peer->migrateFrom()->isChat()) {
|
||||
if (_peer->migrateFrom()->asChat()->inviterForSpamReport > 0) {
|
||||
UserData *user = App::userLoaded(_peer->migrateFrom()->asChat()->inviterForSpamReport);
|
||||
if (user && user->contact > 0) {
|
||||
_reportSpamStatus = dbiprsNoButton;
|
||||
} else {
|
||||
_reportSpamStatus = dbiprsShowButton;
|
||||
}
|
||||
} else {
|
||||
_reportSpamStatus = dbiprsNoButton;
|
||||
}
|
||||
} else if (!_peer->asChannel()->inviter || _history->asChannelHistory()->maxReadMessageDate().isNull()) {
|
||||
_reportSpamStatus = dbiprsUnknown;
|
||||
} else if (_peer->asChannel()->inviter > 0) {
|
||||
UserData *user = App::userLoaded(_peer->asChannel()->inviter);
|
||||
if ((user && user->contact > 0) || (_peer->asChannel()->inviter == MTP::authedId()) || _history->asChannelHistory()->maxReadMessageDate() > _peer->asChannel()->inviteDate) {
|
||||
_reportSpamStatus = dbiprsNoButton;
|
||||
} else {
|
||||
_reportSpamStatus = dbiprsShowButton;
|
||||
}
|
||||
} else {
|
||||
_reportSpamStatus = dbiprsNoButton;
|
||||
}
|
||||
} else if (_peer->isUser() && _peer->asUser()->contact > 0) {
|
||||
_reportSpamStatus = dbiprsHidden;
|
||||
} else {
|
||||
_reportSpamStatus = dbiprsRequesting;
|
||||
requestReportSpamSetting();
|
||||
}
|
||||
if (_reportSpamStatus == dbiprsShowButton || _reportSpamStatus == dbiprsNoButton) {
|
||||
if (_reportSpamStatus == dbiprsHidden) {
|
||||
_reportSpamPanel.setReported(false, _peer);
|
||||
cRefReportSpamStatuses().insert(_peer->id, _reportSpamStatus);
|
||||
Local::writeReportSpamStatuses();
|
||||
}
|
||||
}
|
||||
|
||||
void HistoryWidget::requestReportSpamSetting() {
|
||||
if (_reportSpamSettingRequestId >= 0 || !_peer) return;
|
||||
|
||||
_reportSpamSettingRequestId = MTP::send(MTPmessages_GetPeerSettings(_peer->input), rpcDone(&HistoryWidget::reportSpamSettingDone), rpcFail(&HistoryWidget::reportSpamSettingFail));
|
||||
}
|
||||
|
||||
void HistoryWidget::reportSpamSettingDone(const MTPPeerSettings &result, mtpRequestId req) {
|
||||
if (req != _reportSpamSettingRequestId) return;
|
||||
|
||||
_reportSpamSettingRequestId = 0;
|
||||
if (result.type() == mtpc_peerSettings) {
|
||||
const MTPDpeerSettings &d(result.c_peerSettings());
|
||||
DBIPeerReportSpamStatus status = d.is_report_spam() ? dbiprsShowButton : dbiprsHidden;
|
||||
if (status != _reportSpamStatus) {
|
||||
_reportSpamStatus = status;
|
||||
_reportSpamPanel.setReported(false, _peer);
|
||||
|
||||
cRefReportSpamStatuses().insert(_peer->id, _reportSpamStatus);
|
||||
Local::writeReportSpamStatuses();
|
||||
|
||||
updateControlsVisibility();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool HistoryWidget::reportSpamSettingFail(const RPCError &error, mtpRequestId req) {
|
||||
if (mtpIsFlood(error)) return false;
|
||||
|
||||
if (req == _reportSpamSettingRequestId) {
|
||||
req = 0;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void HistoryWidget::updateControlsVisibility() {
|
||||
_topShadow.setVisible(_peer ? true : false);
|
||||
if (!_history || _a_show.animating()) {
|
||||
@ -4166,7 +4169,7 @@ void HistoryWidget::historyCleared(History *history) {
|
||||
bool HistoryWidget::messagesFailed(const RPCError &error, mtpRequestId requestId) {
|
||||
if (mtpIsFlood(error)) return false;
|
||||
|
||||
if (error.type() == qstr("CHANNEL_PRIVATE") || error.type() == qstr("CHANNEL_PUBLIC_GROUP_NA")) {
|
||||
if (error.type() == qstr("CHANNEL_PRIVATE") || error.type() == qstr("CHANNEL_PUBLIC_GROUP_NA") || error.type() == qstr("USER_BANNED_IN_CHANNEL")) {
|
||||
PeerData *was = _peer;
|
||||
Ui::showChatsList();
|
||||
Ui::showLayer(new InformBox(lang((was && was->isMegagroup()) ? lng_group_not_accessible : lng_channel_not_accessible)));
|
||||
@ -4762,7 +4765,7 @@ bool HistoryWidget::joinFail(const RPCError &error, mtpRequestId req) {
|
||||
if (mtpIsFlood(error)) return false;
|
||||
|
||||
if (_unblockRequest == req) _unblockRequest = 0;
|
||||
if (error.type() == qstr("CHANNEL_PRIVATE") || error.type() == qstr("CHANNEL_PUBLIC_GROUP_NA")) {
|
||||
if (error.type() == qstr("CHANNEL_PRIVATE") || error.type() == qstr("CHANNEL_PUBLIC_GROUP_NA") || error.type() == qstr("USER_BANNED_IN_CHANNEL")) {
|
||||
Ui::showLayer(new InformBox(lang((_peer && _peer->isMegagroup()) ? lng_group_not_accessible : lng_channel_not_accessible)));
|
||||
return true;
|
||||
}
|
||||
@ -6074,10 +6077,12 @@ bool HistoryWidget::reportSpamFail(const RPCError &error, mtpRequestId req) {
|
||||
|
||||
void HistoryWidget::onReportSpamHide() {
|
||||
if (_peer) {
|
||||
cRefReportSpamStatuses().insert(_peer->id, dbiprsNoButton);
|
||||
cRefReportSpamStatuses().insert(_peer->id, dbiprsHidden);
|
||||
Local::writeReportSpamStatuses();
|
||||
|
||||
MTP::send(MTPmessages_HideReportSpam(_peer->input));
|
||||
}
|
||||
_reportSpamStatus = dbiprsNoButton;
|
||||
_reportSpamStatus = dbiprsHidden;
|
||||
updateControlsVisibility();
|
||||
}
|
||||
|
||||
|
@ -759,7 +759,12 @@ private:
|
||||
bool saveEditMsgFail(History *history, const RPCError &error, mtpRequestId req);
|
||||
|
||||
DBIPeerReportSpamStatus _reportSpamStatus;
|
||||
mtpRequestId _reportSpamSettingRequestId;
|
||||
static const mtpRequestId ReportSpamRequestNeeded = -1;
|
||||
void updateReportSpamStatus();
|
||||
void requestReportSpamSetting();
|
||||
void reportSpamSettingDone(const MTPPeerSettings &result, mtpRequestId req);
|
||||
bool reportSpamSettingFail(const RPCError &error, mtpRequestId req);
|
||||
|
||||
QString _previewLinks;
|
||||
WebPageData *_previewData;
|
||||
|
@ -351,7 +351,14 @@ class PhotoData;
|
||||
class UserData : public PeerData {
|
||||
public:
|
||||
|
||||
UserData(const PeerId &id) : PeerData(id), access(0), flags(0), onlineTill(0), contact(-1), blocked(UserBlockUnknown), photosCount(-1), botInfo(0) {
|
||||
UserData(const PeerId &id) : PeerData(id)
|
||||
, access(0)
|
||||
, flags(0)
|
||||
, onlineTill(0)
|
||||
, contact(-1)
|
||||
, blocked(UserBlockUnknown)
|
||||
, photosCount(-1)
|
||||
, botInfo(0) {
|
||||
setName(QString(), QString(), QString(), QString());
|
||||
}
|
||||
void setPhoto(const MTPUserProfilePhoto &photo);
|
||||
@ -399,7 +406,16 @@ static UserData * const InlineBotLookingUpData = SharedMemoryLocation<UserData,
|
||||
class ChatData : public PeerData {
|
||||
public:
|
||||
|
||||
ChatData(const PeerId &id) : PeerData(id), inputChat(MTP_int(bareId())), migrateToPtr(0), count(0), date(0), version(0), creator(0), inviterForSpamReport(0), flags(0), isForbidden(false), botStatus(0) {
|
||||
ChatData(const PeerId &id) : PeerData(id)
|
||||
, inputChat(MTP_int(bareId()))
|
||||
, migrateToPtr(0)
|
||||
, count(0)
|
||||
, date(0)
|
||||
, version(0)
|
||||
, creator(0)
|
||||
, flags(0)
|
||||
, isForbidden(false)
|
||||
, botStatus(0) {
|
||||
}
|
||||
void setPhoto(const MTPChatPhoto &photo, const PhotoId &phId = UnknownPeerPhotoId);
|
||||
void invalidateParticipants() {
|
||||
@ -421,7 +437,6 @@ public:
|
||||
int32 date;
|
||||
int32 version;
|
||||
int32 creator;
|
||||
int32 inviterForSpamReport; // > 0 - user who invited me to chat in unread service msg, < 0 - have outgoing message
|
||||
|
||||
int32 flags;
|
||||
bool isForbidden;
|
||||
@ -477,14 +492,14 @@ enum PtsSkippedQueue {
|
||||
class PtsWaiter {
|
||||
public:
|
||||
|
||||
PtsWaiter() :
|
||||
_good(0),
|
||||
_last(0),
|
||||
_count(0),
|
||||
_applySkippedLevel(0),
|
||||
_requesting(false),
|
||||
_waitingForSkipped(false),
|
||||
_waitingForShortPoll(false) {
|
||||
PtsWaiter()
|
||||
: _good(0)
|
||||
, _last(0)
|
||||
, _count(0)
|
||||
, _applySkippedLevel(0)
|
||||
, _requesting(false)
|
||||
, _waitingForSkipped(false)
|
||||
, _waitingForShortPoll(false) {
|
||||
}
|
||||
void init(int32 pts) {
|
||||
_good = _last = _count = pts;
|
||||
@ -567,7 +582,19 @@ struct MegagroupInfo {
|
||||
class ChannelData : public PeerData {
|
||||
public:
|
||||
|
||||
ChannelData(const PeerId &id) : PeerData(id), access(0), inputChannel(MTP_inputChannel(MTP_int(bareId()), MTP_long(0))), count(1), adminsCount(1), date(0), version(0), flags(0), flagsFull(0), mgInfo(0), isForbidden(true), inviter(0), _lastFullUpdate(0) {
|
||||
ChannelData(const PeerId &id) : PeerData(id)
|
||||
, access(0)
|
||||
, inputChannel(MTP_inputChannel(MTP_int(bareId()), MTP_long(0)))
|
||||
, count(1)
|
||||
, adminsCount(1)
|
||||
, date(0)
|
||||
, version(0)
|
||||
, flags(0)
|
||||
, flagsFull(0)
|
||||
, mgInfo(nullptr)
|
||||
, isForbidden(true)
|
||||
, inviter(0)
|
||||
, _lastFullUpdate(0) {
|
||||
setName(QString(), QString());
|
||||
}
|
||||
void setPhoto(const MTPChatPhoto &photo, const PhotoId &phId = UnknownPeerPhotoId);
|
||||
|
@ -397,10 +397,12 @@ enum DBIPlatform {
|
||||
};
|
||||
|
||||
enum DBIPeerReportSpamStatus {
|
||||
dbiprsNoButton,
|
||||
dbiprsUnknown,
|
||||
dbiprsShowButton,
|
||||
dbiprsReportSent,
|
||||
dbiprsNoButton = 0, // hidden, but not in the cloud settings yet
|
||||
dbiprsUnknown = 1, // contacts not loaded yet
|
||||
dbiprsShowButton = 2, // show report spam button, each show peer request setting from cloud
|
||||
dbiprsReportSent = 3, // report sent, but the report spam panel is not hidden yet
|
||||
dbiprsHidden = 4, // hidden in the cloud or not needed (bots, contacts, etc), no more requests
|
||||
dbiprsRequesting = 5, // requesting the cloud setting right now
|
||||
};
|
||||
|
||||
typedef enum {
|
||||
|
Loading…
Reference in New Issue
Block a user