Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to display self-destruct messages anyway #159

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/cmake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ on: [push, pull_request]
env:
# Must be updated manually. Increment 'TD_MARK' to invalidate the cache.
# Must not contain spaces, minuses, or any special characters.
TD_TAG: "v1.6.0"
TD_TAG: "v1.8.0"
TD_MARK: "m1"

jobs:
Expand Down
12 changes: 7 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,18 @@ project(tdlib-purple VERSION ${VERSION} LANGUAGES CXX)

find_package(Td REQUIRED)
math(EXPR TDLIB_VERSION_NUMBER "10000*${Td_VERSION_MAJOR} + 100*${Td_VERSION_MINOR} + ${Td_VERSION_PATCH}")
if (NOT(${TDLIB_VERSION_NUMBER} EQUAL 10709))
if (${TDLIB_VERSION_NUMBER} LESS 10800)
# Error message must begin with "tdlib version" for a grep command from readme
message(FATAL_ERROR "tdlib version 1.7.9 is required
message(FATAL_ERROR "at least tdlib version 1.8.0 is required
(version found: ${Td_VERSION_MAJOR}.${Td_VERSION_MINOR}.${Td_VERSION_PATCH})")
endif (NOT(${TDLIB_VERSION_NUMBER} EQUAL 10709))
endif (${TDLIB_VERSION_NUMBER} LESS 10800)

set(NoPkgConfig FALSE CACHE BOOL "Do not use pkg-config")
set(NoWebp FALSE CACHE BOOL "Do not decode webp stickers")
set(NoBundledLottie FALSE CACHE BOOL "Do not use bundled rlottie library")
set(NoLottie FALSE CACHE BOOL "Disable animated sticker conversion")
set(NoTranslations FALSE CACHE BOOL "Disable translation support")
set(NoVoip FALSE CACHE BOOL "Disable voice call support")
set(tgvoip_INCLUDE_DIRS "" CACHE STRING "Path to libtgvoip headers")
set(tgvoip_LIBRARIES "tgvoip" CACHE STRING "tgvoip library to link against")
set(API_ID 94575 CACHE STRING "API id")
set(API_HASH a3406de8d171bb422bb6ddf3bbd800e2 CACHE STRING "API hash")
set(STUFF "" CACHE STRING "")
Expand All @@ -31,6 +29,10 @@ if (NOT NoPkgConfig)
pkg_check_modules(libwebp libwebp)
pkg_check_modules(libpng libpng)
endif (NOT NoWebp)
if (NOT NoVoip)
pkg_check_modules(tgvoip tgvoip)
endif(NOT NoVoip)

pkg_get_variable(PURPLE_PLUGIN_DIR purple plugindir)
pkg_get_variable(PURPLE_DATA_DIR purple datarootdir)
endif (NOT NoPkgConfig)
Expand Down
24 changes: 24 additions & 0 deletions build_and_install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/bash

set -e

JOBS="$(nproc || echo 1)"

rm -rf build
mkdir build
pushd build
git clone https://github.com/tdlib/td.git
pushd td
git checkout v1.8.0
mkdir build
pushd build
cmake -DCMAKE_BUILD_TYPE=Release ..
make -j "${JOBS}"
make install DESTDIR=destdir
popd
popd
cmake -DTd_DIR="$(realpath .)"/td/build/destdir/usr/local/lib/cmake/Td/ -DNoVoip=True ..
make -j "${JOBS}"
echo "Now calling sudo make install"
sudo make install
popd
2 changes: 1 addition & 1 deletion client-utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ bool isInviteLinkActive(const td::td_api::chatInviteLink &linkInfo)
{
return !linkInfo.is_revoked_ &&
((linkInfo.member_limit_ == 0) || (linkInfo.member_count_ < linkInfo.member_limit_)) &&
((linkInfo.expire_date_ == 0) || (std::time(NULL) < static_cast<time_t>(linkInfo.expire_date_)));
((linkInfo.expiration_date_ == 0) || (std::time(NULL) < static_cast<time_t>(linkInfo.expiration_date_)));
}

static std::string lastMessageSetting(ChatId chatId)
Expand Down
24 changes: 12 additions & 12 deletions identifiers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,7 @@ UserId getUserId(const td::td_api::chatTypePrivate &privType)

UserId getUserId(const td::td_api::chatMember &member)
{
if (member.member_id_ && (member.member_id_->get_id() == td::td_api::messageSenderUser::ID)) {
const td::td_api::messageSenderUser &userInfo = static_cast<const td::td_api::messageSenderUser &>(*member.member_id_);
return UserId(userInfo.user_id_);
}
return UserId::invalid;
return getUserId(member.member_id_);
}

UserId getUserId(const td::td_api::call &call)
Expand All @@ -59,10 +55,7 @@ UserId getUserId(const td::td_api::call &call)

UserId getSenderUserId(const td::td_api::message &message)
{
if (message.sender_ && (message.sender_->get_id() == td::td_api::messageSenderUser::ID))
return UserId(static_cast<const td::td_api::messageSenderUser &>(*message.sender_).user_id_);
else
return UserId::invalid;
return getUserId(message.sender_id_);
}

UserId getSenderUserId(const td::td_api::messageForwardOriginUser &forwardOrigin)
Expand All @@ -80,9 +73,9 @@ UserId getUserId(const td::td_api::updateUserStatus &update)
return UserId(update.user_id_);
}

UserId getUserId(const td::td_api::updateUserChatAction &update)
UserId getUserId(const td::td_api::updateChatAction &update)
{
return UserId(update.user_id_);
return getUserId(update.sender_id_);
}

UserId getUserId(const td::td_api::importedContacts &contacts, unsigned index)
Expand All @@ -95,6 +88,13 @@ UserId getUserId(const td::td_api::users &users, unsigned index)
return UserId(users.user_ids_[index]);
}

UserId getUserId(const td::td_api::object_ptr<td::td_api::MessageSender>& sender) {
if(sender && (sender->get_id() == td::td_api::messageSenderUser::ID)) {
return UserId(static_cast<const td::td_api::messageSenderUser &>(*sender.get()).user_id_);
}
return UserId::invalid;
}

ChatId getChatId(const td::td_api::updateChatPosition &update)
{
return ChatId(update.chat_id_);
Expand All @@ -115,7 +115,7 @@ ChatId getChatId(const td::td_api::message &message)
return ChatId(message.chat_id_);
}

ChatId getChatId(const td::td_api::updateUserChatAction &update)
ChatId getChatId(const td::td_api::updateChatAction &update)
{
return ChatId(update.chat_id_);
}
Expand Down
10 changes: 6 additions & 4 deletions identifiers.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,10 @@ DEFINE_ID_CLASS(UserId, int64_t)
friend UserId getSenderUserId(const td::td_api::messageForwardOriginUser &forwardOrigin);
friend UserId getUserId(const td::td_api::secretChat &secretChat);
friend UserId getUserId(const td::td_api::updateUserStatus &update);
friend UserId getUserId(const td::td_api::updateUserChatAction &update);
friend UserId getUserId(const td::td_api::updateChatAction &update);
friend UserId getUserId(const td::td_api::importedContacts &contacts, unsigned index);
friend UserId getUserId(const td::td_api::users &users, unsigned index);
friend UserId getUserId(const td::td_api::object_ptr<td::td_api::MessageSender>& sender);
};

DEFINE_ID_CLASS(ChatId, int64_t)
Expand All @@ -74,7 +75,7 @@ DEFINE_ID_CLASS(ChatId, int64_t)
friend ChatId getChatId(const td::td_api::updateChatTitle &update);
friend ChatId getChatId(const td::td_api::messageForwardOriginChannel &forwardOrigin);
friend ChatId getChatId(const td::td_api::message &message);
friend ChatId getChatId(const td::td_api::updateUserChatAction &update);
friend ChatId getChatId(const td::td_api::updateChatAction &update);
friend ChatId getChatId(const td::td_api::updateChatLastMessage &update);
};

Expand Down Expand Up @@ -116,15 +117,16 @@ UserId getSenderUserId(const td::td_api::message &message);
UserId getSenderUserId(const td::td_api::messageForwardOriginUser &forwardOrigin);
UserId getUserId(const td::td_api::secretChat &secretChat);
UserId getUserId(const td::td_api::updateUserStatus &update);
UserId getUserId(const td::td_api::updateUserChatAction &update);
UserId getUserId(const td::td_api::updateChatAction &update);
UserId getUserId(const td::td_api::importedContacts &contacts, unsigned index);
UserId getUserId(const td::td_api::users &users, unsigned index);
UserId getUserId(const td::td_api::object_ptr<td::td_api::MessageSender>& sender);

ChatId getChatId(const td::td_api::updateChatPosition &update);
ChatId getChatId(const td::td_api::updateChatTitle &update);
ChatId getChatId(const td::td_api::messageForwardOriginChannel &forwardOrigin);
ChatId getChatId(const td::td_api::message &message);
ChatId getChatId(const td::td_api::updateUserChatAction &update);
ChatId getChatId(const td::td_api::updateChatAction &update);
ChatId getChatId(const td::td_api::updateChatLastMessage &update);

BasicGroupId getBasicGroupId(const td::td_api::updateBasicGroupFullInfo &update);
Expand Down
2 changes: 2 additions & 0 deletions purple-info.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ namespace AccountOptions {
constexpr gboolean EnableSecretChatsDefault = TRUE;
constexpr const char *AnimatedStickers = "animated-stickers";
constexpr gboolean AnimatedStickersDefault = TRUE;
constexpr const char *ShowSelfDestruct = "show-self-destruct";
constexpr gboolean ShowSelfDestructDefault = FALSE;
constexpr const char *DownloadBehaviour = "download-behaviour";
constexpr const char *DownloadBehaviourHyperlink = "hyperlink";
constexpr const char *DownloadBehaviourStandard = "file-transfer";
Expand Down
37 changes: 26 additions & 11 deletions receiving.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -634,22 +634,37 @@ void showMessage(const td::td_api::chat &chat, IncomingMessage &fullMessage,
messageInfo.repliedMessage = std::move(fullMessage.repliedMessage);

if (message.ttl_ != 0) {
// TRANSLATOR: In-chat warning message
const char *text = _("Received self-destructing message, not displayed due to lack of support");
std::string notice = makeNoticeWithSender(chat, messageInfo, text, account.purpleAccount);
showMessageText(account, chat, messageInfo, NULL, notice.c_str());
return;
if (purple_account_get_bool(account.purpleAccount, AccountOptions::ShowSelfDestruct, AccountOptions::ShowSelfDestructDefault)) {
// TRANSLATOR: In-chat warning message
const char *text = _("Received self-destructing message, displaying anyway");
std::string notice = makeNoticeWithSender(chat, messageInfo, text, account.purpleAccount);
showMessageText(account, chat, messageInfo, NULL, notice.c_str());
} else {
// TRANSLATOR: In-chat warning message
const char *text = _("Received self-destructing message, not displayed due to lack of support");
std::string notice = makeNoticeWithSender(chat, messageInfo, text, account.purpleAccount);
showMessageText(account, chat, messageInfo, NULL, notice.c_str());
return;
}
}

FileInfo fileInfo;
getFileFromMessage(fullMessage, fileInfo);
if (fileInfo.secret) {
// TRANSLATOR: In-chat warning message
std::string notice = formatMessage("Ignoring secret file ({})", fileInfo.description);
notice = makeNoticeWithSender(chat, messageInfo, notice.c_str(), account.purpleAccount);
showMessageText(account, chat, messageInfo, !fileInfo.caption.empty() ? fileInfo.caption.c_str() : nullptr,
notice.c_str());
return;
if (purple_account_get_bool(account.purpleAccount, AccountOptions::ShowSelfDestruct, AccountOptions::ShowSelfDestructDefault)) {
// TRANSLATOR: In-chat warning message
std::string notice = formatMessage("Received secret file {}, displaying anyway", fileInfo.description);
notice = makeNoticeWithSender(chat, messageInfo, notice.c_str(), account.purpleAccount);
showMessageText(account, chat, messageInfo, !fileInfo.caption.empty() ? fileInfo.caption.c_str() : nullptr,
notice.c_str());
} else {
// TRANSLATOR: In-chat warning message
std::string notice = formatMessage("Ignoring secret file ({})", fileInfo.description);
notice = makeNoticeWithSender(chat, messageInfo, notice.c_str(), account.purpleAccount);
showMessageText(account, chat, messageInfo, !fileInfo.caption.empty() ? fileInfo.caption.c_str() : nullptr,
notice.c_str());
return;
}
}

switch (message.content_->get_id()) {
Expand Down
15 changes: 7 additions & 8 deletions td-client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ void PurpleTdClient::processUpdate(td::td_api::Object &update)
break;
}

case td::td_api::updateUserChatAction::ID: {
auto &updateChatAction = static_cast<td::td_api::updateUserChatAction &>(update);
case td::td_api::updateChatAction::ID: {
auto &updateChatAction = static_cast<td::td_api::updateChatAction &>(update);
purple_debug_misc(config::pluginId, "Incoming update: chat action %d\n",
updateChatAction.action_ ? updateChatAction.action_->get_id() : 0);
handleUserChatAction(updateChatAction);
Expand Down Expand Up @@ -1276,7 +1276,7 @@ void PurpleTdClient::addChat(td::td_api::object_ptr<td::td_api::chat> chat)
updateChat(m_data.getChat(chatId));
}

void PurpleTdClient::handleUserChatAction(const td::td_api::updateUserChatAction &updateChatAction)
void PurpleTdClient::handleUserChatAction(const td::td_api::updateChatAction &updateChatAction)
{
const td::td_api::chat *chat = m_data.getChat(getChatId(updateChatAction));
if (!chat) {
Expand All @@ -1295,19 +1295,18 @@ void PurpleTdClient::handleUserChatAction(const td::td_api::updateUserChatAction
if (chatUserId != getUserId(updateChatAction)) {
purpleDebug("Got user action for private chat {} (with user {}) for another user {}", {
std::to_string(updateChatAction.chat_id_), std::to_string(chatUserId.value()),
std::to_string(updateChatAction.user_id_)
std::to_string(getUserId(updateChatAction))
});
} else if (updateChatAction.action_) {
if (updateChatAction.action_->get_id() == td::td_api::chatActionCancel::ID) {
purpleDebug("User (id {}) stopped chat action", updateChatAction.user_id_);
purpleDebug("User (id {}) stopped chat action", getUserId(updateChatAction));
showUserChatAction(getUserId(updateChatAction), false);
} else if (updateChatAction.action_->get_id() == td::td_api::chatActionStartPlayingGame::ID) {
purpleDebug("User (id %d): treating chatActionStartPlayingGame as cancel",
updateChatAction.user_id_);
purpleDebug("User (id %d): treating chatActionStartPlayingGame as cancel", getUserId(updateChatAction));
showUserChatAction(getUserId(updateChatAction), false);
} else {
purpleDebug("User (id {}) started chat action (id {})", {
std::to_string(updateChatAction.user_id_), std::to_string(updateChatAction.action_->get_id())
std::to_string(getUserId(updateChatAction)), std::to_string(updateChatAction.action_->get_id())
});
showUserChatAction(getUserId(updateChatAction), true);
}
Expand Down
2 changes: 1 addition & 1 deletion td-client.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ class PurpleTdClient {
void addContactById(UserId userId, const std::string &phoneNumber, const std::string &alias,
const std::string &groupName);
void addChat(td::td_api::object_ptr<td::td_api::chat> chat);
void handleUserChatAction(const td::td_api::updateUserChatAction &updateChatAction);
void handleUserChatAction(const td::td_api::updateChatAction &updateChatAction);
void showUserChatAction(UserId userId, bool isTyping);
void addBuddySearchChatResponse(uint64_t requestId, td::td_api::object_ptr<td::td_api::Object> object);
void importContactResponse(uint64_t requestId, td::td_api::object_ptr<td::td_api::Object> object);
Expand Down
5 changes: 5 additions & 0 deletions tdlib-purple.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1020,6 +1020,11 @@ static void tgprpl_init (PurplePlugin *plugin)
prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, opt);
#endif

// TRANSLATOR: Account settings, key (boolean)
opt = purple_account_option_bool_new(_("Show self-destructing messages anyway"), AccountOptions::ShowSelfDestruct,
AccountOptions::ShowSelfDestructDefault);
prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, opt);

if (canDisableReadReceipts()) {
opt = purple_account_option_bool_new ("Send read receipts",
AccountOptions::ReadReceipts,
Expand Down