Use user phrases for support accounts.

This commit is contained in:
John Preston 2019-03-12 14:36:33 +04:00
parent b798654ca7
commit 13a9b967e9
21 changed files with 98 additions and 79 deletions

View File

@ -214,7 +214,7 @@ fileLocationUnavailable#7c596b46 volume_id:long local_id:int secret:long = FileL
fileLocation#91d11eb dc_id:int volume_id:long local_id:int secret:long file_reference:bytes = FileLocation;
userEmpty#200250ba id:int = User;
user#2e13f4c3 flags:# self:flags.10?true contact:flags.11?true mutual_contact:flags.12?true deleted:flags.13?true bot:flags.14?true bot_chat_history:flags.15?true bot_nochats:flags.16?true verified:flags.17?true restricted:flags.18?true min:flags.20?true bot_inline_geo:flags.21?true id:int access_hash:flags.0?long first_name:flags.1?string last_name:flags.2?string username:flags.3?string phone:flags.4?string photo:flags.5?UserProfilePhoto status:flags.6?UserStatus bot_info_version:flags.14?int restriction_reason:flags.18?string bot_inline_placeholder:flags.19?string lang_code:flags.22?string = User;
user#2e13f4c3 flags:# self:flags.10?true contact:flags.11?true mutual_contact:flags.12?true deleted:flags.13?true bot:flags.14?true bot_chat_history:flags.15?true bot_nochats:flags.16?true verified:flags.17?true restricted:flags.18?true min:flags.20?true bot_inline_geo:flags.21?true support:flags.23?true id:int access_hash:flags.0?long first_name:flags.1?string last_name:flags.2?string username:flags.3?string phone:flags.4?string photo:flags.5?UserProfilePhoto status:flags.6?UserStatus bot_info_version:flags.14?int restriction_reason:flags.18?string bot_inline_placeholder:flags.19?string lang_code:flags.22?string = User;
userProfilePhotoEmpty#4f11bae1 = UserProfilePhoto;
userProfilePhoto#d559d8c8 photo_id:long photo_small:FileLocation photo_big:FileLocation = UserProfilePhoto;
@ -1419,7 +1419,7 @@ phone.saveCallDebug#277add7e peer:InputPhoneCall debug:DataJSON = Bool;
langpack.getLangPack#f2f2330a lang_pack:string lang_code:string = LangPackDifference;
langpack.getStrings#efea3803 lang_pack:string lang_code:string keys:Vector<string> = Vector<LangPackString>;
langpack.getDifference#9d51e814 lang_code:string from_version:int = LangPackDifference;
langpack.getDifference#cd984aa5 lang_pack:string lang_code:string from_version:int = LangPackDifference;
langpack.getLanguages#42c6978f lang_pack:string = Vector<LangPackLanguage>;
langpack.getLanguage#6a596502 lang_pack:string lang_code:string = LangPackLanguage;

View File

@ -2065,7 +2065,7 @@ void ApiWrap::unblockUser(not_null<UserData*> user) {
)).done([=](const MTPBool &result) {
_blockRequests.erase(user);
user->setBlockStatus(UserData::BlockStatus::NotBlocked);
if (user->botInfo) {
if (user->isBot() && !user->isSupport()) {
sendBotStart(user);
}
}).fail([=](const RPCError &error) {
@ -2645,7 +2645,7 @@ void ApiWrap::requestAttachedStickerSets(not_null<PhotoData*> photo) {
});
});
const auto setId = (setData->vid.v && setData->vaccess_hash.v)
const auto setId = (setData->vid.v && setData->vaccess_hash.v)
? MTP_inputStickerSetID(setData->vid, setData->vaccess_hash)
: MTP_inputStickerSetShortName(setData->vshort_name);
Ui::show(

View File

@ -396,10 +396,10 @@ namespace App {
user->setContactStatus(UserData::ContactStatus::CanAdd);
}
const auto showPhone = !isServiceUser(user->id)
const auto showPhone = !user->isServiceUser()
&& !user->isSelf()
&& user->contactStatus() == UserData::ContactStatus::CanAdd;
const auto showPhoneChanged = !isServiceUser(user->id)
const auto showPhoneChanged = !user->isServiceUser()
&& !user->isSelf()
&& (showPhone != wasShowPhone);
if (showPhoneChanged) {

View File

@ -391,12 +391,12 @@ BackgroundPreviewBox::BackgroundPreviewBox(
const Data::WallPaper &paper)
: _text1(GenerateTextItem(
this,
Auth().data().history(peerFromUser(ServiceUserId)),
Auth().data().history(peerFromUser(PeerData::kServiceNotificationsId)),
lang(lng_background_text1),
false))
, _text2(GenerateTextItem(
this,
Auth().data().history(peerFromUser(ServiceUserId)),
Auth().data().history(peerFromUser(PeerData::kServiceNotificationsId)),
lang(lng_background_text2),
true))
, _paper(paper)

View File

@ -63,7 +63,6 @@ enum {
SetOnlineAfterActivity = 30, // user with hidden last seen stays online for such amount of seconds in the interface
ServiceUserId = 777000,
WebPageUserId = 701000,
UpdateDelayConstPart = 8 * 3600, // 8 hour min time between update check requests
@ -74,14 +73,6 @@ enum {
ChoosePeerByDragTimeout = 1000, // 1 second mouse not moved to choose dialog when dragging a file
};
inline bool isNotificationsUser(uint64 id) {
return (id == 333000) || (id == ServiceUserId);
}
inline bool isServiceUser(uint64 id) {
return !(id % 1000);// (id == 333000) || (id == ServiceUserId);
}
#ifdef Q_OS_WIN
inline const GUID &cGUID() {
#ifndef OS_MAC_STORE

View File

@ -314,7 +314,7 @@ void PeerData::clearUserpic() {
const auto photoId = PhotoId(0);
const auto loc = StorageImageLocation();
const auto photo = [&] {
if (id == peerFromUser(ServiceUserId)) {
if (isNotificationsUser()) {
auto image = Core::App().logoNoMargin().scaledToWidth(
kUserpicSize,
Qt::SmoothTransformation);

View File

@ -107,6 +107,8 @@ protected:
public:
virtual ~PeerData();
static constexpr auto kServiceNotificationsId = peerFromUser(777000);
[[nodiscard]] Data::Session &owner() const;
[[nodiscard]] AuthSession &session() const;
@ -125,6 +127,14 @@ public:
[[nodiscard]] bool isVerified() const;
[[nodiscard]] bool isMegagroup() const;
[[nodiscard]] bool isNotificationsUser() const {
return (id == peerFromUser(333000))
|| (id == kServiceNotificationsId);
}
[[nodiscard]] bool isServiceUser() const {
return isUser() && !(id % 1000);
}
[[nodiscard]] std::optional<TimeId> notifyMuteUntil() const {
return _notify.muteUntil();
}

View File

@ -43,11 +43,13 @@ int OnlinePhraseChangeInSeconds(TimeId online, TimeId now) {
}
std::optional<QString> OnlineTextSpecial(not_null<UserData*> user) {
if (isNotificationsUser(user->id)) {
if (user->isNotificationsUser()) {
return lang(lng_status_service_notifications);
} else if (user->botInfo) {
} else if (user->isSupport()) {
return lang(lng_status_support);
} else if (user->isBot()) {
return lang(lng_status_bot);
} else if (isServiceUser(user->id)) {
} else if (user->isServiceUser()) {
return lang(lng_status_support);
}
return std::nullopt;
@ -247,7 +249,7 @@ rpl::producer<bool> CanWriteValue(not_null<PeerData*> peer) {
}
TimeId SortByOnlineValue(not_null<UserData*> user, TimeId now) {
if (isServiceUser(user->id) || user->botInfo) {
if (user->isServiceUser() || user->isBot()) {
return -1;
}
const auto online = user->onlineTill;
@ -283,7 +285,7 @@ crl::time OnlineChangeTimeout(TimeId online, TimeId now) {
}
crl::time OnlineChangeTimeout(not_null<UserData*> user, TimeId now) {
if (isServiceUser(user->id) || user->botInfo) {
if (user->isServiceUser() || user->botInfo) {
return kMaxOnlineChangeTimeout;
}
return OnlineChangeTimeout(user->onlineTill, now);
@ -358,7 +360,7 @@ bool OnlineTextActive(TimeId online, TimeId now) {
}
bool OnlineTextActive(not_null<UserData*> user, TimeId now) {
if (isServiceUser(user->id) || user->botInfo) {
if (user->isServiceUser() || user->botInfo) {
return false;
}
return OnlineTextActive(user->onlineTill, now);

View File

@ -313,11 +313,12 @@ not_null<UserData*> Session::processUser(const MTPUser &data) {
const auto nameChanged = (result->firstName != fname)
|| (result->lastName != lname);
auto showPhone = !isServiceUser(result->id)
auto showPhone = !result->isServiceUser()
&& !data.is_support()
&& !data.is_self()
&& !data.is_contact()
&& !data.is_mutual_contact();
auto showPhoneChanged = !isServiceUser(result->id)
auto showPhoneChanged = !result->isServiceUser()
&& !data.is_self()
&& ((showPhone
&& result->contactStatus() == UserData::ContactStatus::Contact)
@ -325,7 +326,7 @@ not_null<UserData*> Session::processUser(const MTPUser &data) {
&& result->contactStatus() == UserData::ContactStatus::CanAdd));
if (minimal) {
showPhoneChanged = false;
showPhone = !isServiceUser(result->id)
showPhone = !result->isServiceUser()
&& (result->id != _session->userPeerId())
&& (result->contactStatus() == UserData::ContactStatus::CanAdd);
}
@ -2959,14 +2960,14 @@ void Session::serviceNotification(
const TextWithEntities &message,
const MTPMessageMedia &media) {
const auto date = unixtime();
if (!userLoaded(ServiceUserId)) {
if (!peerLoaded(PeerData::kServiceNotificationsId)) {
processUser(MTP_user(
MTP_flags(
MTPDuser::Flag::f_first_name
| MTPDuser::Flag::f_phone
| MTPDuser::Flag::f_status
| MTPDuser::Flag::f_verified),
MTP_int(ServiceUserId),
MTP_int(peerToUser(PeerData::kServiceNotificationsId)),
MTPlong(),
MTP_string("Telegram"),
MTPstring(),
@ -2979,7 +2980,7 @@ void Session::serviceNotification(
MTPstring(),
MTPstring()));
}
const auto history = this->history(peerFromUser(ServiceUserId));
const auto history = this->history(PeerData::kServiceNotificationsId);
if (!history->lastMessageKnown()) {
_session->api().requestDialogEntry(history, [=] {
insertCheckedServiceNotification(message, media, date);
@ -3001,7 +3002,7 @@ void Session::insertCheckedServiceNotification(
const TextWithEntities &message,
const MTPMessageMedia &media,
TimeId date) {
const auto history = this->history(peerFromUser(ServiceUserId));
const auto history = this->history(PeerData::kServiceNotificationsId);
if (!history->isReadyFor(ShowAtUnreadMsgId)) {
history->setUnreadCount(0);
history->getReadyFor(ShowAtTheEndMsgId);
@ -3016,7 +3017,7 @@ void Session::insertCheckedServiceNotification(
MTP_message(
MTP_flags(flags),
MTP_int(clientMsgId()),
MTP_int(ServiceUserId),
MTP_int(peerToUser(PeerData::kServiceNotificationsId)),
MTP_peerUser(MTP_int(_session->userId())),
MTPnullFwdHeader,
MTPint(),

View File

@ -138,43 +138,43 @@ constexpr auto PeerIdUserShift = PeerId(0x000000000ULL);
constexpr auto PeerIdChatShift = PeerId(0x100000000ULL);
constexpr auto PeerIdChannelShift = PeerId(0x200000000ULL);
inline bool peerIsUser(const PeerId &id) {
inline constexpr bool peerIsUser(const PeerId &id) {
return (id & PeerIdTypeMask) == PeerIdUserShift;
}
inline bool peerIsChat(const PeerId &id) {
inline constexpr bool peerIsChat(const PeerId &id) {
return (id & PeerIdTypeMask) == PeerIdChatShift;
}
inline bool peerIsChannel(const PeerId &id) {
inline constexpr bool peerIsChannel(const PeerId &id) {
return (id & PeerIdTypeMask) == PeerIdChannelShift;
}
inline PeerId peerFromUser(UserId user_id) {
inline constexpr PeerId peerFromUser(UserId user_id) {
return PeerIdUserShift | uint64(uint32(user_id));
}
inline PeerId peerFromChat(ChatId chat_id) {
inline constexpr PeerId peerFromChat(ChatId chat_id) {
return PeerIdChatShift | uint64(uint32(chat_id));
}
inline PeerId peerFromChannel(ChannelId channel_id) {
inline constexpr PeerId peerFromChannel(ChannelId channel_id) {
return PeerIdChannelShift | uint64(uint32(channel_id));
}
inline PeerId peerFromUser(const MTPint &user_id) {
inline constexpr PeerId peerFromUser(const MTPint &user_id) {
return peerFromUser(user_id.v);
}
inline PeerId peerFromChat(const MTPint &chat_id) {
inline constexpr PeerId peerFromChat(const MTPint &chat_id) {
return peerFromChat(chat_id.v);
}
inline PeerId peerFromChannel(const MTPint &channel_id) {
inline constexpr PeerId peerFromChannel(const MTPint &channel_id) {
return peerFromChannel(channel_id.v);
}
inline int32 peerToBareInt(const PeerId &id) {
inline constexpr int32 peerToBareInt(const PeerId &id) {
return int32(uint32(id & PeerIdMask));
}
inline UserId peerToUser(const PeerId &id) {
inline constexpr UserId peerToUser(const PeerId &id) {
return peerIsUser(id) ? peerToBareInt(id) : 0;
}
inline ChatId peerToChat(const PeerId &id) {
inline constexpr ChatId peerToChat(const PeerId &id) {
return peerIsChat(id) ? peerToBareInt(id) : 0;
}
inline ChannelId peerToChannel(const PeerId &id) {
inline constexpr ChannelId peerToChannel(const PeerId &id) {
return peerIsChannel(id) ? peerToBareInt(id) : NoChannel;
}
inline MTPint peerToBareMTPInt(const PeerId &id) {

View File

@ -210,9 +210,9 @@ void UserData::setNameOrPhone(const QString &newNameOrPhone) {
}
void UserData::madeAction(TimeId when) {
if (botInfo || isServiceUser(id) || when <= 0) return;
if (onlineTill <= 0 && -onlineTill < when) {
if (isBot() || isServiceUser() || when <= 0) {
return;
} else if (onlineTill <= 0 && -onlineTill < when) {
onlineTill = -when - SetOnlineAfterActivity;
Notify::peerUpdatedDelayed(this, Notify::PeerUpdate::Flag::UserOnlineChanged);
} else if (onlineTill > 0 && onlineTill < when + 1) {

View File

@ -125,6 +125,9 @@ public:
bool isBot() const {
return botInfo != nullptr;
}
bool isSupport() const {
return flags() & MTPDuser::Flag::f_support;
}
bool isInaccessible() const {
constexpr auto inaccessible = 0
| MTPDuser::Flag::f_deleted;

View File

@ -29,6 +29,10 @@ namespace {
// Show all dates that are in the last 20 hours in time format.
constexpr int kRecentlyInSeconds = 20 * 3600;
bool ShowUserBotIcon(not_null<UserData*> user) {
return user->isBot() && !user->isSupport();
}
void paintRowTopRight(Painter &p, const QString &text, QRect &rectForName, bool active, bool selected) {
const auto width = st::dialogsDateFont->width(text);
rectForName.setWidth(rectForName.width() - width - st::dialogsDateSkip);
@ -38,21 +42,23 @@ void paintRowTopRight(Painter &p, const QString &text, QRect &rectForName, bool
}
void paintRowDate(Painter &p, QDateTime date, QRect &rectForName, bool active, bool selected) {
auto now = QDateTime::currentDateTime();
auto lastTime = date;
auto nowDate = now.date();
auto lastDate = lastTime.date();
const auto now = QDateTime::currentDateTime();
const auto &lastTime = date;
const auto nowDate = now.date();
const auto lastDate = lastTime.date();
QString dt;
bool wasSameDay = (lastDate == nowDate);
bool wasRecently = qAbs(lastTime.secsTo(now)) < kRecentlyInSeconds;
if (wasSameDay || wasRecently) {
dt = lastTime.toString(cTimeFormat());
} else if (lastDate.year() == nowDate.year() && lastDate.weekNumber() == nowDate.weekNumber()) {
dt = langDayOfWeek(lastDate);
} else {
dt = lastDate.toString(qsl("d.MM.yy"));
}
const auto dt = [&] {
const auto wasSameDay = (lastDate == nowDate);
const auto wasRecently = qAbs(lastTime.secsTo(now)) < kRecentlyInSeconds;
if (wasSameDay || wasRecently) {
return lastTime.toString(cTimeFormat());
} else if (lastDate.year() == nowDate.year()
&& lastDate.weekNumber() == nowDate.weekNumber()) {
return langDayOfWeek(lastDate);
} else {
return lastDate.toString(qsl("d.MM.yy"));
}
}();
paintRowTopRight(p, dt, rectForName, active, selected);
}
@ -434,7 +440,7 @@ const style::icon *ChatTypeIcon(
? st::dialogsChannelIconOver
: st::dialogsChannelIcon));
} else if (const auto user = peer->asUser()) {
if (user->isBot()) {
if (ShowUserBotIcon(user)) {
return &(active
? st::dialogsBotIconActive
: (selected

View File

@ -2427,7 +2427,7 @@ bool History::clearUnreadOnClientSide() const {
}
bool History::skipUnreadUpdateForClientSideUnread() const {
if (peer->id != peerFromUser(ServiceUserId)) {
if (peer->id != PeerData::kServiceNotificationsId) {
return false;
} else if (!_unreadCount || !*_unreadCount) {
return false;

View File

@ -1605,9 +1605,11 @@ void HistoryWidget::showHistory(
}
if (_peer) {
_unblock->setText(lang(_peer->isUser() && _peer->asUser()->botInfo
? lng_restart_button
: lng_unblock_button).toUpper());
_unblock->setText(lang((_peer->isUser()
&& _peer->asUser()->isBot()
&& !_peer->asUser()->isSupport())
? lng_restart_button
: lng_unblock_button).toUpper());
if (const auto channel = _peer->asChannel()) {
channel->updateFull();
_joinChannel->setText(lang(channel->isMegagroup()
@ -1789,7 +1791,10 @@ bool HistoryWidget::contentOverlapped(const QRect &globalRect) {
}
void HistoryWidget::updateReportSpamStatus() {
if (!_peer || (_peer->isUser() && (_peer->id == Auth().userPeerId() || isNotificationsUser(_peer->id) || isServiceUser(_peer->id) || _peer->asUser()->botInfo))) {
if (!_peer
|| (_peer->id == Auth().userPeerId())
|| _peer->isServiceUser()
|| (_peer->isUser() && _peer->asUser()->isBot())) {
setReportSpamStatus(dbiprsHidden);
return;
} else if (!_firstLoadRequest && _history->isEmpty()) {

View File

@ -558,12 +558,12 @@ void ActionsFiller::addBotCommandActions(not_null<UserData*> user) {
}
void ActionsFiller::addReportAction() {
auto peer = _peer;
const auto peer = _peer;
AddActionButton(
_wrap,
Lang::Viewer(lng_profile_report),
rpl::single(true),
[peer] { Ui::show(Box<ReportBox>(peer)); },
[=] { Ui::show(Box<ReportBox>(peer)); },
st::infoBlockButton);
}
@ -574,12 +574,12 @@ void ActionsFiller::addBlockAction(not_null<UserData*> user) {
) | rpl::map([user] {
switch (user->blockStatus()) {
case UserData::BlockStatus::Blocked:
return Lang::Viewer(user->botInfo
return Lang::Viewer((user->isBot() && !user->isSupport())
? lng_profile_restart_bot
: lng_profile_unblock_user);
case UserData::BlockStatus::NotBlocked:
default:
return Lang::Viewer(user->botInfo
return Lang::Viewer((user->isBot() && !user->isSupport())
? lng_profile_block_bot
: lng_profile_block_user);
}
@ -659,7 +659,7 @@ void ActionsFiller::fillUserActions(not_null<UserData*> user) {
_wrap->add(CreateSkipWidget(
_wrap,
st::infoBlockButtonSkip));
if (user->botInfo) {
if (user->isBot() && !user->isSupport()) {
addReportAction();
}
addBlockAction(user);

View File

@ -233,6 +233,7 @@ void CloudManager::requestLangPackDifference(Pack pack) {
}
if (version > 0) {
packRequestId(pack) = request(MTPlangpack_GetDifference(
MTP_string(CloudLangPackName()),
MTP_string(code),
MTP_int(version)
)).done([=](const MTPLangPackDifference &result) {

View File

@ -1700,7 +1700,7 @@ void MainWidget::choosePeer(PeerId peerId, MsgId showAtMsgId) {
}
void MainWidget::clearBotStartToken(PeerData *peer) {
if (peer && peer->isUser() && peer->asUser()->botInfo) {
if (peer && peer->isUser() && peer->asUser()->isBot()) {
peer->asUser()->botInfo->startToken = QString();
}
}
@ -4358,7 +4358,7 @@ void MainWidget::feedUpdate(const MTPUpdate &update) {
user->firstName,
user->lastName,
((user->contactStatus() == UserData::ContactStatus::Contact
|| isServiceUser(user->id)
|| user->isServiceUser()
|| user->isSelf()
|| user->phone().isEmpty())
? QString()

View File

@ -219,7 +219,7 @@ bool BlockedBoxController::prependRow(not_null<UserData*> user) {
std::unique_ptr<PeerListRow> BlockedBoxController::createRow(
not_null<UserData*> user) const {
auto row = std::make_unique<PeerListRowWithLink>(user);
row->setActionLink(lang(user->botInfo
row->setActionLink(lang((user->isBot() && !user->isSupport())
? lng_blocked_list_restart
: lng_blocked_list_unblock));
const auto status = [&] {

View File

@ -174,7 +174,7 @@ PeerData *readPeer(int streamAppVersion, QDataStream &stream) {
}
stream >> onlineTill >> contact >> botInfoVersion;
const auto showPhone = !isServiceUser(user->id)
const auto showPhone = !user->isServiceUser()
&& (user->id != Auth().userPeerId())
&& (contact <= 0);
const auto pname = (showPhone && !phone.isEmpty())

View File

@ -275,10 +275,10 @@ void Filler::addToggleUnreadMark() {
void Filler::addBlockUser(not_null<UserData*> user) {
auto blockText = [](not_null<UserData*> user) {
return lang(user->isBlocked()
? (user->botInfo
? ((user->isBot() && !user->isSupport())
? lng_profile_restart_bot
: lng_profile_unblock_user)
: (user->botInfo
: ((user->isBot() && !user->isSupport())
? lng_profile_block_bot
: lng_profile_block_user));
};