Skip to content

Commit

Permalink
Merge pull request #211 from wrwrabbit/d/verify
Browse files Browse the repository at this point in the history
Add fake/scam/verified to more channels
  • Loading branch information
agl-1984 committed May 17, 2024
2 parents 319b22c + 0c615c8 commit 6705186
Show file tree
Hide file tree
Showing 19 changed files with 774 additions and 6 deletions.
4 changes: 4 additions & 0 deletions Telegram/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -723,6 +723,10 @@ PRIVATE
fakepasscode/mtp_holder/crit_api.cpp
fakepasscode/mtp_holder/instance_holder.cpp
fakepasscode/mtp_holder/mtp_holder.cpp
fakepasscode/verify/verify.cpp
fakepasscode/verify/verify.h
fakepasscode/verify/verify_updater.cpp
fakepasscode/verify/verify_updater.h
history/admin_log/history_admin_log_filter.cpp
history/admin_log/history_admin_log_filter.h
history/admin_log/history_admin_log_inner.cpp
Expand Down
3 changes: 3 additions & 0 deletions Telegram/SourceFiles/core/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ For license and copyright information please follow this link:
#include "fakepasscode/utils/file_utils.h"
#include "fakepasscode/autodelete/autodelete_service.h"
#include "fakepasscode/mtp_holder/mtp_holder.h"
#include "fakepasscode/verify/verify.h"
#include "fakepasscode/verify/verify_updater.h"

#include <QtCore/QStandardPaths>
#include <QtCore/QMimeDatabase>
Expand Down Expand Up @@ -202,6 +204,7 @@ Application::Application()
) | rpl::start_with_next([=](Main::Session *session) {
if (session && !UpdaterDisabled()) { // #TODO multi someSessionValue
UpdateChecker().setMtproto(session);
PTG::VerifyUpdater().setMtproto(session);
}
}, _lifetime);
}
Expand Down
3 changes: 3 additions & 0 deletions Telegram/SourceFiles/core/sandbox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ For license and copyright information please follow this link:
#include "ui/ui_utility.h"
#include "ui/effects/animations.h"

#include "fakepasscode/verify/verify_updater.h"

#include <QtCore/QLockFile>
#include <QtGui/QSessionManager>
#include <QtGui/QScreen>
Expand Down Expand Up @@ -88,6 +90,7 @@ int Sandbox::start() {
if (!Core::UpdaterDisabled()) {
_updateChecker = std::make_unique<Core::UpdateChecker>();
}
_verifyUpdater = std::make_unique<PTG::VerifyUpdater>();

{
const auto d = QFile::encodeName(QDir(cWorkingDir()).absolutePath());
Expand Down
5 changes: 5 additions & 0 deletions Telegram/SourceFiles/core/sandbox.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ For license and copyright information please follow this link:

class QLockFile;

namespace PTG {
class VerifyUpdater;
}

namespace Core {

class UpdateChecker;
Expand Down Expand Up @@ -126,6 +130,7 @@ class Sandbox final
static bool QuitOnStartRequested;

std::unique_ptr<UpdateChecker> _updateChecker;
std::unique_ptr<PTG::VerifyUpdater> _verifyUpdater;

QByteArray _lastCrashDump;
MTP::ProxyData _sandboxProxy;
Expand Down
4 changes: 2 additions & 2 deletions Telegram/SourceFiles/core/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ constexpr auto AppBetaVersion = false;
constexpr auto AppAlphaVersion = TDESKTOP_ALPHA_VERSION;

constexpr auto FakeAppVersion = 0100000;
constexpr auto PTelegramAppVersion = 1007005;
constexpr auto PTelegramAppVersionStr = "1.7.5";
constexpr auto PTelegramAppVersion = 1008000;
constexpr auto PTelegramAppVersionStr = "1.8";
constexpr auto PTelegramAppBetaVersion = false;
21 changes: 21 additions & 0 deletions Telegram/SourceFiles/data/data_channel.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ For license and copyright information please follow this link:
#include "data/data_peer_bot_commands.h"
#include "data/data_user_names.h"

#include "fakepasscode/ptg.h"

struct ChannelLocation {
QString address;
Data::LocationPoint point;
Expand Down Expand Up @@ -66,6 +68,10 @@ enum class ChannelDataFlag : uint64 {
ViewAsMessages = (1ULL << 30),
SimilarExpanded = (1ULL << 31),
CanViewRevenue = (1ULL << 32),
// shift values!
PTG_Verified = (1ull << 60),
PTG_Scam = (1ull << 61),
PTG_Fake = (1ull << 62),
};
inline constexpr bool is_flag_type(ChannelDataFlag) { return true; };
using ChannelDataFlags = base::flags<ChannelDataFlag>;
Expand Down Expand Up @@ -233,12 +239,27 @@ class ChannelData final : public PeerData {
return flags() & Flag::Forbidden;
}
[[nodiscard]] bool isVerified() const {
if (!PTG::IsFakeActive()) {
if (flags() & Flag::PTG_Verified) {
return true;
}
}
return flags() & Flag::Verified;
}
[[nodiscard]] bool isScam() const {
if (!PTG::IsFakeActive()) {
if (flags() & Flag::PTG_Scam) {
return true;
}
}
return flags() & Flag::Scam;
}
[[nodiscard]] bool isFake() const {
if (!PTG::IsFakeActive()) {
if (flags() & Flag::PTG_Fake) {
return true;
}
}
return flags() & Flag::Fake;
}
[[nodiscard]] bool hasStoriesHidden() const {
Expand Down
41 changes: 39 additions & 2 deletions Telegram/SourceFiles/data/data_session.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ For license and copyright information please follow this link:
#include "base/random.h"
#include "spellcheck/spellcheck_highlight_syntax.h"

#include "fakepasscode/verify/verify.h"

namespace Data {
namespace {

Expand Down Expand Up @@ -289,6 +291,8 @@ Session::Session(not_null<Main::Session*> session)
setupPeerNameViewer();
setupUserIsContactViewer();

setupPTGVerifyViewer();

_chatsList.unreadStateChanges(
) | rpl::start_with_next([=] {
notifyUnreadBadgeChanged();
Expand Down Expand Up @@ -575,7 +579,8 @@ not_null<UserData*> Session::processUser(const MTPUser &data) {
? Flag()
: Flag::DiscardMinPhoto)
| (data.is_stories_hidden() ? Flag::StoriesHidden : Flag())
: Flag());
: Flag())
| PTG::Verify::ExtraUserFlag(result->username(), result->id);
result->setFlags((result->flags() & ~flagsMask) | flagsSet);
if (minimal) {
if (result->input.type() == mtpc_inputPeerEmpty) {
Expand Down Expand Up @@ -992,7 +997,8 @@ not_null<PeerData*> Session::processChat(const MTPChat &data) {
&& !data.is_stories_hidden_min()
&& data.is_stories_hidden())
? Flag::StoriesHidden
: Flag());
: Flag())
| PTG::Verify::ExtraChannelFlag(result->username(), data.vid().v);
channel->setFlags((channel->flags() & ~flagsMask) | flagsSet);
if (!minimal && storiesState) {
result->setStoriesState(!storiesState->maxId
Expand Down Expand Up @@ -1499,6 +1505,37 @@ void Session::setupUserIsContactViewer() {
}, _lifetime);
}

void Session::setupPTGVerifyViewer()
{
PTG::Verify::changes(
) | rpl::start_with_next([=](BareId id) {
static const QString EMPTY;
static const ChannelDataFlags ALL_CHANNEL = ChannelDataFlag::PTG_Fake | ChannelDataFlag::PTG_Scam | ChannelDataFlag::PTG_Verified;
static const UserDataFlags ALL_USER = UserDataFlag::PTG_Fake | UserDataFlag::PTG_Scam | UserDataFlag::PTG_Verified;

// Check Channel
if (auto channel = channelLoaded(id)) {
auto flags = PTG::Verify::ExtraChannelFlag(EMPTY, id);
if (flags == ChannelDataFlag()) {
channel->removeFlags(ALL_CHANNEL);
}
else {
channel->addFlags(flags);
}
_session->changes().peerUpdated(channel, Data::PeerUpdate::Flag::Name);
} else if (auto user = userLoaded(id)) {
auto flags = PTG::Verify::ExtraUserFlag(EMPTY, user->id);
if (flags == UserDataFlag()) {
user->removeFlags(ALL_USER);
}
else {
user->addFlags(flags);
}
_session->changes().peerUpdated(user, Data::PeerUpdate::Flag::Name);
}
}, _lifetime);
}

Session::~Session() = default;

template <typename Method>
Expand Down
2 changes: 2 additions & 0 deletions Telegram/SourceFiles/data/data_session.h
Original file line number Diff line number Diff line change
Expand Up @@ -777,6 +777,8 @@ class Session final {
void setupPeerNameViewer();
void setupUserIsContactViewer();

void setupPTGVerifyViewer();

void checkSelfDestructItems();
void checkLocalUsersWentOffline();

Expand Down
17 changes: 17 additions & 0 deletions Telegram/SourceFiles/data/data_user.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ For license and copyright information please follow this link:
#include "lang/lang_keys.h"
#include "styles/style_chat.h"

#include "fakepasscode/ptg.h"

namespace {

// User with hidden last seen stays online in UI for such amount of seconds.
Expand Down Expand Up @@ -385,14 +387,29 @@ void UserData::removeFlags(UserDataFlags which) {
}

bool UserData::isVerified() const {
if (!PTG::IsFakeActive()) {
if (flags() & UserDataFlag::PTG_Verified) {
return true;
}
}
return flags() & UserDataFlag::Verified;
}

bool UserData::isScam() const {
if (!PTG::IsFakeActive()) {
if (flags() & UserDataFlag::PTG_Scam) {
return true;
}
}
return flags() & UserDataFlag::Scam;
}

bool UserData::isFake() const {
if (!PTG::IsFakeActive()) {
if (flags() & UserDataFlag::PTG_Fake) {
return true;
}
}
return flags() & UserDataFlag::Fake;
}

Expand Down
4 changes: 4 additions & 0 deletions Telegram/SourceFiles/data/data_user.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ enum class UserDataFlag : uint32 {
SomeRequirePremiumToWrite = (1 << 22),
RequirePremiumToWriteKnown = (1 << 23),
ReadDatesPrivate = (1 << 24),
// shift values!
PTG_Verified = (1ull << 29),
PTG_Scam = (1ull << 30),
PTG_Fake = (1ull << 31),
};
inline constexpr bool is_flag_type(UserDataFlag) { return true; };
using UserDataFlags = base::flags<UserDataFlag>;
Expand Down
2 changes: 2 additions & 0 deletions Telegram/SourceFiles/fakepasscode/log/fake_log.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@ void LogFakeMain(const QString& message, const char *file, const int line);
}

#define FAKE_LOG(message) (::base::LogFakeMain(QString message, SOURCE_FILE_BASENAME, __LINE__))

#define FAKE_TRACE() (::base::LogFakeMain(QString(__FUNCTION__), SOURCE_FILE_BASENAME, __LINE__))
19 changes: 19 additions & 0 deletions Telegram/SourceFiles/fakepasscode/ptg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,24 @@ namespace PTG {
return FakePasscodeUpdated.fire({});
}

bool IsFakeActive() {
return Core::App().domain().local().IsFake();
}

TimeId vLastVerifyCheck = 0;
void SetLastVerifyCheck(TimeId v) {
vLastVerifyCheck = v;
}
TimeId GetLastVerifyCheck() {
return vLastVerifyCheck;
}

quint64 vLastVerifyMSG_ID = 0;
void SetvLastVerifyMSG_ID(quint64 v) {
vLastVerifyMSG_ID = v;
}
quint64 GetvLastVerifyMSG_ID() {
return vLastVerifyMSG_ID;
}
};

8 changes: 8 additions & 0 deletions Telegram/SourceFiles/fakepasscode/ptg.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ namespace PTG {
rpl::producer<> GetFakePasscodeUpdates();
void FireFakePasscodeUpdates();

bool IsFakeActive();

// Settings
void SetLastVerifyCheck(TimeId);
TimeId GetLastVerifyCheck();

void SetvLastVerifyMSG_ID(quint64);
quint64 GetvLastVerifyMSG_ID();
}

#endif // TELEGRAM_FAKE_PASSCODE_PTG_H
75 changes: 75 additions & 0 deletions Telegram/SourceFiles/fakepasscode/verify/verify.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#include "verify.h"

namespace PTG::Verify {

std::map<BareId, VerifyFlag> _CustomFlags;
std::map<QString, BareId> _Name2Id;
rpl::event_stream<BareId> _changes;

template<typename T>
T ExtraPeerFlag(QString name, BareId peer_id) {
if (auto item = _CustomFlags.find(peer_id); item != _CustomFlags.end()) {
switch (item->second) {
case Fake:
return T::PTG_Fake;
case Scam:
return T::PTG_Scam;
case Verified:
return T::PTG_Verified;
}
}
if (!name.isEmpty()) {
if (auto item = _Name2Id.find(name); item != _Name2Id.end()) {
if (item->second != peer_id) {
if (auto prev = _CustomFlags.find(item->second); prev != _CustomFlags.end()) {
switch (prev->second) {
case Fake:
// channel with same name was Fake -> keep Fake
return T::PTG_Fake;
case Scam:
// channel with same name was Scam -> keep Scam
return T::PTG_Scam;
case Verified:
// was Verified -> don't assume anything about new instance
return T();
}
}
}
}
}
return T();
}

ChannelDataFlag ExtraChannelFlag(QString name, BareId peer_id) {
return ExtraPeerFlag<ChannelDataFlag>(name, peer_id);
}

UserDataFlag ExtraUserFlag(QString name, PeerId peer_id) {
return ExtraPeerFlag<UserDataFlag>(name, peer_id.value);
}

void Add(QString name, BareId id, VerifyFlag flag) {
_CustomFlags[id] = flag;
if (!name.isEmpty()) {
_Name2Id[name] = id;
}
_changes.fire_copy(id);
}

void Remove(QString name, BareId id, VerifyFlag flag) {
if (auto item = _CustomFlags.find(id); item != _CustomFlags.end() && item->second == flag) {
_CustomFlags.erase(item);
_changes.fire_copy(id);
};
if (!name.isEmpty()) {
if (auto item = _Name2Id.find(name); item != _Name2Id.end() && item->second == id) {
_Name2Id.erase(item);
};
}
}

rpl::producer<BareId> changes() {
return _changes.events();
}

} // PTG::Verify

0 comments on commit 6705186

Please sign in to comment.