first e2e working

This commit is contained in:
mrbesen 2023-11-26 18:32:38 +01:00
parent 99dd9c112c
commit bc95a6e403
Signed by: MrBesen
GPG Key ID: 596B2350DCD67504
5 changed files with 24 additions and 5 deletions

1
.gitignore vendored
View File

@ -18,3 +18,4 @@ log.txt
tdlib/ tdlib/
thirdparty/td/tdlib thirdparty/td/tdlib
assignment.conf

View File

@ -86,6 +86,7 @@ public:
void downloadFile(int32_t file_id); void downloadFile(int32_t file_id);
void sendTextMessage(int64_t chatid, const std::string& text);
void sendTextMessageToSelf(const std::string& text); void sendTextMessageToSelf(const std::string& text);
void getMessage(int64_t chatid, int64_t messageid, std::function<void(objptr<td_api::message>)> f); void getMessage(int64_t chatid, int64_t messageid, std::function<void(objptr<td_api::message>)> f);

View File

@ -46,8 +46,11 @@ std::string Crypt::encryptForChat(int64_t chat, const std::string& message) {
proc->waitFor(std::chrono::seconds(4)); proc->waitFor(std::chrono::seconds(4));
out.resize(out.size() - Footer.size()); if(out.size() > Footer.size() + Header.size() ) {
return MyHeader + out.substr(Header.size()); out.resize(out.size() - Footer.size());
return MyHeader + out.substr(Header.size());
}
return "<encryption failed>";
} }
std::string Crypt::decryptFromChat(int64_t chat, const std::string& message) { std::string Crypt::decryptFromChat(int64_t chat, const std::string& message) {

View File

@ -285,9 +285,9 @@ void TGClient::downloadFile(int32_t file_id) {
send_staticquery(td::make_tl_object<td_api::downloadFile>(file_id, /* prio */ 15, 0, 0, false), HANDLER_NULL); send_staticquery(td::make_tl_object<td_api::downloadFile>(file_id, /* prio */ 15, 0, 0, false), HANDLER_NULL);
} }
void TGClient::sendTextMessageToSelf(const std::string& text) { void TGClient:: sendTextMessage(int64_t chatid, const std::string& text) {
auto sendmsg = td::make_tl_object<td_api::sendMessage>(); auto sendmsg = td::make_tl_object<td_api::sendMessage>();
sendmsg->chat_id_ = me; sendmsg->chat_id_ = chatid;
sendmsg->message_thread_id_ = 0; sendmsg->message_thread_id_ = 0;
sendmsg->reply_to_ = nullptr; sendmsg->reply_to_ = nullptr;
sendmsg->options_ = nullptr; sendmsg->options_ = nullptr;
@ -297,6 +297,10 @@ void TGClient::sendTextMessageToSelf(const std::string& text) {
send_staticquery(std::move(sendmsg), HANDLER_NULL); send_staticquery(std::move(sendmsg), HANDLER_NULL);
} }
void TGClient::sendTextMessageToSelf(const std::string& text) {
sendTextMessage(me, text);
}
void TGClient::getMessage(int64_t chatid, int64_t messageid, std::function<void(objptr<td_api::message>)> f) { void TGClient::getMessage(int64_t chatid, int64_t messageid, std::function<void(objptr<td_api::message>)> f) {
send_wrappedquery<td_api::message>(td::make_tl_object<td_api::getMessage>(chatid, messageid), f); send_wrappedquery<td_api::message>(td::make_tl_object<td_api::getMessage>(chatid, messageid), f);
} }

View File

@ -45,9 +45,12 @@ static void clearVec(std::vector<char*> v) {
v.clear(); v.clear();
} }
TgTUI::TgTUI() : tgclient(std::bind(&TgTUI::initDoneCB, this)), crypt(std::make_unique<Crypt>()) {} TgTUI::TgTUI() : tgclient(std::bind(&TgTUI::initDoneCB, this)), crypt(std::make_unique<Crypt>()) {
crypt->load();
}
TgTUI::~TgTUI() { TgTUI::~TgTUI() {
crypt->save();
stop(); stop();
} }
@ -146,6 +149,13 @@ void TgTUI::threadLoop() {
if(chatScroll->exitType == vNORMAL) { if(chatScroll->exitType == vNORMAL) {
activateCDKEntry(textEntry, nullptr); activateCDKEntry(textEntry, nullptr);
if(textEntry->exitType == vNORMAL) {
char* value = getCDKEntryValue(textEntry);
const std::string msg(value);
const std::string encMsg = crypt->encryptForChat(chat.chatId, msg);
tgclient.sendTextMessage(chat.chatId, encMsg);
}
} }
tgclient.closeChat(chat.chatId); tgclient.closeChat(chat.chatId);