diff options
author | George Hazan <george.hazan@gmail.com> | 2024-09-05 18:38:28 +0300 |
---|---|---|
committer | George Hazan <george.hazan@gmail.com> | 2024-09-05 18:38:28 +0300 |
commit | a0382eb50077d124381be4f85cc699129c9e0651 (patch) | |
tree | 4ab2b5293b409271519b148ae1f9ca289aa1ee67 /protocols | |
parent | 8449b1715de83ee5c997c8aac613e7efac9460d3 (diff) |
fixes #4601 (Telegram: сделать генерацию превью для ссылок отключаемой)
Diffstat (limited to 'protocols')
-rw-r--r-- | protocols/Telegram/res/resource.rc | 7 | ||||
-rw-r--r-- | protocols/Telegram/src/options.cpp | 4 | ||||
-rw-r--r-- | protocols/Telegram/src/proto.cpp | 1 | ||||
-rw-r--r-- | protocols/Telegram/src/proto.h | 4 | ||||
-rw-r--r-- | protocols/Telegram/src/resource.h | 1 | ||||
-rw-r--r-- | protocols/Telegram/src/utils.cpp | 17 |
6 files changed, 25 insertions, 9 deletions
diff --git a/protocols/Telegram/res/resource.rc b/protocols/Telegram/res/resource.rc index 86d8258749..748f43f55a 100644 --- a/protocols/Telegram/res/resource.rc +++ b/protocols/Telegram/res/resource.rc @@ -95,8 +95,9 @@ BEGIN EDITTEXT IDC_DEVICE_NAME,87,60,211,12,ES_AUTOHSCROLL
CONTROL "Do not open chat windows on creation",IDC_HIDECHATS,
"Button",BS_AUTOCHECKBOX | WS_TABSTOP,4,83,294,10
- CONTROL "Compress files on send",IDC_COMPRESS_FILES,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,4,97,294,10
+ CONTROL "Compress files on send",IDC_COMPRESS_FILES,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,4,96,294,10
PUSHBUTTON "Log out",IDC_LOGOUT,212,168,86,14
+ CONTROL "Generate URL previews",IDC_USE_PREVIEW,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,4,109,294,10
END
IDD_OPTIONS_ADV DIALOGEX 0, 0, 310, 86
@@ -197,6 +198,10 @@ BEGIN BEGIN
END
+ IDD_OPTIONS_ADV, DIALOG
+ BEGIN
+ END
+
IDD_OPTIONS_SESSIONS, DIALOG
BEGIN
BOTTOMMARGIN, 95
diff --git a/protocols/Telegram/src/options.cpp b/protocols/Telegram/src/options.cpp index dedf868c01..bee31419c1 100644 --- a/protocols/Telegram/src/options.cpp +++ b/protocols/Telegram/src/options.cpp @@ -22,7 +22,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. class COptionsDlg : public CTelegramDlgBase
{
CCtrlButton btnLogout;
- CCtrlCheck chkHideChats, chkUsePopups, chkCompressFiles;
+ CCtrlCheck chkHideChats, chkUsePopups, chkCompressFiles, chkGenPreview;
CCtrlCombo cmbCountry;
CCtrlEdit edtGroup, edtPhone, edtDeviceName;
ptrW m_wszOldGroup;
@@ -34,6 +34,7 @@ public: cmbCountry(this, IDC_COUNTRY),
chkUsePopups(this, IDC_POPUPS),
chkHideChats(this, IDC_HIDECHATS),
+ chkGenPreview(this, IDC_USE_PREVIEW),
edtPhone(this, IDC_PHONE),
edtGroup(this, IDC_DEFGROUP),
edtDeviceName(this, IDC_DEVICE_NAME),
@@ -47,6 +48,7 @@ public: if (bFullDlg) {
CreateLink(chkUsePopups, ppro->m_bUsePopups);
+ CreateLink(chkGenPreview, ppro->m_bUrlPreview);
CreateLink(chkCompressFiles, ppro->m_bCompressFiles);
}
diff --git a/protocols/Telegram/src/proto.cpp b/protocols/Telegram/src/proto.cpp index 07cba42bc9..a87c824bde 100644 --- a/protocols/Telegram/src/proto.cpp +++ b/protocols/Telegram/src/proto.cpp @@ -55,6 +55,7 @@ CTelegramProto::CTelegramProto(const char* protoName, const wchar_t* userName) : m_wszDeviceName(this, "DeviceName", L"Miranda NG"), m_wszDefaultGroup(this, "DefaultGroup", L"Telegram"), m_bUsePopups(this, "UsePopups", true), + m_bUrlPreview(this, "UrlPreview", true), m_bCompressFiles(this, "CompressFiles", true), m_bHideGroupchats(this, "HideChats", true) { diff --git a/protocols/Telegram/src/proto.h b/protocols/Telegram/src/proto.h index 988c2071b8..f478dc7c82 100644 --- a/protocols/Telegram/src/proto.h +++ b/protocols/Telegram/src/proto.h @@ -295,7 +295,8 @@ class CTelegramProto : public PROTO<CTelegramProto> }; bool GetMessageFile(const EmbeddedFile &embed, TG_FILE_REQUEST::Type, const TD::file *pFile, const char *pszFileName, const char *pszCaption); - + + CMStringA GetFormattedText(TD::object_ptr<TD::formattedText> &pText); CMStringA GetMessagePreview(const TD::file *pFile); CMStringA GetMessageSticker(const TD::file *pFile, const char *pwszExtension); CMStringA GetMessageText(TG_USER *pUser, const TD::message *pMsg, bool bSkipJoin = false, bool bRead = false); @@ -433,6 +434,7 @@ public: CMOption<wchar_t*> m_wszDeviceName; // how do you see this session in Device List CMOption<bool> m_bHideGroupchats; // do not open chat windows on creation CMOption<bool> m_bUsePopups; + CMOption<bool> m_bUrlPreview; // embrace URLs into [url] tags CMOption<bool> m_bCompressFiles; // embed pictures & videos into a message on send CMOption<uint32_t> m_iTimeDiff1; // set this status to m_iStatus1 after this interval of secs CMOption<uint32_t> m_iStatus1; diff --git a/protocols/Telegram/src/resource.h b/protocols/Telegram/src/resource.h index 0332712efb..ba4fad485f 100644 --- a/protocols/Telegram/src/resource.h +++ b/protocols/Telegram/src/resource.h @@ -34,6 +34,7 @@ #define IDC_CLIST 1016
#define IDC_COMPRESS_FILES 1017
#define IDC_REACTIONS 1018
+#define IDC_USE_PREVIEW 1018
#define IDC_SESSIONS 1023
#define IDC_SOFTWARE 1025
#define IDC_LOGOUT 1025
diff --git a/protocols/Telegram/src/utils.cpp b/protocols/Telegram/src/utils.cpp index b2d114b1e9..ba7515cce6 100644 --- a/protocols/Telegram/src/utils.cpp +++ b/protocols/Telegram/src/utils.cpp @@ -82,7 +82,7 @@ TD::object_ptr<TD::formattedText> formatBbcodes(const char *pszText) return res;
}
-static CMStringA getFormattedText(TD::object_ptr<TD::formattedText> &pText)
+CMStringA CTelegramProto::GetFormattedText(TD::object_ptr<TD::formattedText> &pText)
{
if (pText->get_id() == TD::formattedText::ID) {
CMStringW ret(Utf2T(pText->text_.c_str()));
@@ -95,8 +95,12 @@ static CMStringA getFormattedText(TD::object_ptr<TD::formattedText> &pText) case TD::textEntityTypeItalic::ID: iCode = 1; break;
case TD::textEntityTypeStrikethrough::ID: iCode = 2; break;
case TD::textEntityTypeUnderline::ID: iCode = 3; break;
- case TD::textEntityTypeUrl::ID: iCode = 4; break;
case TD::textEntityTypeCode::ID: iCode = 5; break;
+ case TD::textEntityTypeUrl::ID:
+ if (!m_bUrlPreview)
+ continue;
+ iCode = 4;
+ break;
default:
continue;
}
@@ -712,17 +716,18 @@ CMStringA CTelegramProto::GetMessageText(TG_USER *pUser, const TD::message *pMsg ret.Format("%s: %.2lf %s", TranslateU("You received an invoice"), double(pInvoice->total_amount_)/100.0, pInvoice->currency_.c_str());
if (!pInvoice->title_.empty())
ret.AppendFormat("\r\n%s: %s", TranslateU("Title"), pInvoice->title_.c_str());
- if (auto pszText = getFormattedText(pInvoice->description_))
+ if (auto pszText = GetFormattedText(pInvoice->description_))
ret.AppendFormat("\r\n%s", pszText.c_str());
}
break;
case TD::messageText::ID:
if (auto *pText = ((TD::messageText *)pBody)) {
- ret = getFormattedText(pText->text_);
+ ret = GetFormattedText(pText->text_);
if (auto *pWeb = pText->web_page_.get()) {
- ret.AppendFormat("\r\n[url]%s[/url]", pWeb->embed_url_.c_str());
+ if (!pWeb->embed_url_.empty() && m_bUrlPreview)
+ ret.AppendFormat("\r\n[url]%s[/url]", pWeb->embed_url_.c_str());
if (pWeb->photo_) {
const TD::photoSize *pSize = nullptr;
@@ -737,7 +742,7 @@ CMStringA CTelegramProto::GetMessageText(TG_USER *pUser, const TD::message *pMsg ret.AppendFormat("\r\n[img=%s][/img]", szText.c_str());
}
- if (auto szText = getFormattedText(pWeb->description_))
+ if (auto szText = GetFormattedText(pWeb->description_))
ret.AppendFormat("\r\n%s", szText.c_str());
}
}
|