Commit 70123947 authored by Thomas BOUTROUE's avatar Thomas BOUTROUE

Add an envvar to enable debug messages

Remove old useless logs
parent cc91e51e
......@@ -59,7 +59,6 @@ ApplicationWindow {
target: TD_Global;
onShowChatRequested: {
if (chatItem) {
console.log ("DISPLAY REQUESTED", chatItem, chatItem.id);
window.activate ();
while (pageStack.depth > 1) {
pageStack.navigateBack (PageStackAction.Immediate);
......
......@@ -8,7 +8,6 @@ Page {
id: page;
allowedOrientations: Orientation.All;
Component.onCompleted: {
console.log ("CHAT PAGE completed", currentChat);
TD_Global.openChat (currentChat);
if (currentChat.unreadCount > 0) {
// should wait for first unread msg to become valid and center on it
......@@ -19,7 +18,6 @@ Page {
}
}
Component.onDestruction: {
console.log ("CHAT PAGE destroyed", currentChat);
TD_Global.closeChat (currentChat);
}
onContainsFirstUnreadMsgChanged: {
......
......@@ -105,7 +105,6 @@ Page {
implicitHeight: Math.max (Theme.itemSizeSmall, lbl.height + Theme.paddingMedium * 2);
ExtraAnchors.horizontalFill: parent;
onClicked: {
console.log ("PRIVATE CHAT REQUESTED", pageUserInfo.userItem.id);
var chatItem = TD_Global.getChatItemById (userItem.id);
if (chatItem) {
TD_Global.showChat (chatItem);
......
......@@ -54,7 +54,6 @@ QtTdLibChat::QtTdLibChat (const qint64 id, QObject * parent)
}
});
connect (&m_notif, &Notification::clicked, this, [this] (void) {
qWarning () << "CLICKED" << this << get_id ();
emit displayRequested ();
});
connect (this, &QtTdLibChat::lastReadInboxMessageIdChanged, this, &QtTdLibChat::findFirstNewMessage);
......
......@@ -79,7 +79,7 @@ QtTdLibGlobal::QtTdLibGlobal (QObject * parent)
{ "application/x-executable", "executable" },
{ "application/x-ms-dos-executable", "executable" },
}
, m_tdLibJsonWrapper { new QtTdLibJsonWrapper { this } }
, m_tdLibJsonWrapper { new QtTdLibJsonWrapper { (qgetenv ("DEBUG_TDLIB") == QByteArrayLiteral ("1")), this } }
, m_audioRecorder { new QAudioRecorder { this } }
{
m_sortedChatsList->setSourceModel (m_chatsList);
......@@ -97,7 +97,6 @@ QtTdLibGlobal::QtTdLibGlobal (QObject * parent)
audioEncoderSettings.setSampleRate (22050);
m_audioRecorder->setEncodingSettings (audioEncoderSettings);
m_audioRecorder->setContainerFormat ("wav"); // "ogg"
qWarning () << "VOLUME" << m_audioRecorder->volume () << m_audioRecorder->audioInput () << m_audioRecorder->audioInputDescription (m_audioRecorder->audioInput ());
connect (m_audioRecorder, &QAudioRecorder::durationChanged, [this] (void) {
if (m_audioRecorder->status () == QMediaRecorder::RecordingStatus || m_audioRecorder->status () == QMediaRecorder::FinalizingStatus) {
set_recordingDuration (int (m_audioRecorder->duration ()));
......@@ -328,13 +327,11 @@ void QtTdLibGlobal::createPrivateChat (QtTdLibUser * userItem) {
void QtTdLibGlobal::showChat (QtTdLibChat * chatItem) {
if (chatItem != Q_NULLPTR) {
qWarning () << "SHOW CHAT" << chatItem << chatItem->get_id () << chatItem->get_title ();
emit showChatRequested (chatItem);
}
}
void QtTdLibGlobal::openChat (QtTdLibChat * chatItem) {
qWarning () << "openChat" << chatItem;
closeChat (m_currentChat);
if (chatItem != Q_NULLPTR) {
chatItem->set_isCurrentChat (true);
......@@ -348,7 +345,6 @@ void QtTdLibGlobal::openChat (QtTdLibChat * chatItem) {
}
void QtTdLibGlobal::closeChat (QtTdLibChat * chatItem) {
qWarning () << "closeChat" << chatItem;
if (chatItem != Q_NULLPTR && chatItem == m_currentChat) {
chatItem->messagesModel.clear ();
chatItem->set_oldestFetchedMessageId (0); // NOTE : reset lower boundary
......@@ -407,7 +403,6 @@ void QtTdLibGlobal::togglePinChat (QtTdLibChat * chatItem) {
void QtTdLibGlobal::loadSingleMessageRef (QtTdLibChat * chatItem, const qint64 messageId) {
if (chatItem != Q_NULLPTR) {
if (messageId != 0) {
qWarning () << "LOAD SINGLE MESSAGE..." << messageId;
send (QJsonObject {
{ "@type", "getMessage" },
{ "chat_id", chatItem->get_id_asJSON () },
......@@ -420,7 +415,6 @@ void QtTdLibGlobal::loadSingleMessageRef (QtTdLibChat * chatItem, const qint64 m
void QtTdLibGlobal::loadInitialMessage (QtTdLibChat * chatItem, const qint64 messageId) {
if (chatItem != Q_NULLPTR) {
if (messageId != 0) {
qWarning () << "LOAD INITIAL MESSAGE..." << messageId;
if (messageId < chatItem->get_oldestFetchedMessageId () || messageId > chatItem->get_newestFetchedMessageId ()) {
chatItem->messagesModel.clear (); // NOTE : need to clean current model
chatItem->set_oldestFetchedMessageId (0); // NOTE : reset lower boundary
......@@ -456,7 +450,6 @@ void QtTdLibGlobal::loadInitialMessage (QtTdLibChat * chatItem, const qint64 mes
void QtTdLibGlobal::loadOlderMessages (QtTdLibChat * chatItem, const int count) {
if (chatItem != Q_NULLPTR && chatItem->get_oldestFetchedMessageId () != 0 && count > 0) {
qWarning () << "LOAD" << count << "OLDER MESSAGES...";
send (QJsonObject {
{ "@type", "getChatHistory" },
{ "chat_id", chatItem->get_id_asJSON () },
......@@ -475,7 +468,6 @@ void QtTdLibGlobal::loadOlderMessages (QtTdLibChat * chatItem, const int count)
void QtTdLibGlobal::loadNewerMessages (QtTdLibChat * chatItem, const int count) {
if (chatItem != Q_NULLPTR && chatItem->get_newestFetchedMessageId () != 0 && count > 0) {
qWarning () << "LOAD" << count << "NEWER MESSAGES...";
send (QJsonObject {
{ "@type", "getChatHistory" },
{ "chat_id", chatItem->get_id_asJSON () },
......@@ -1157,7 +1149,6 @@ void QtTdLibGlobal::onFrame (const QJsonObject & json) {
const qint32 userId { QtTdLibId32Helper::fromJsonToCpp (tmpJson) };
if (QtTdLibUser * userItem = { getUserItemById (userId) }) {
m_contactsList->append (userItem);
qWarning () << "CONTACT" << userItem->get_firstName () << userItem->get_lastName ();
}
}
break;
......@@ -1236,7 +1227,6 @@ void QtTdLibGlobal::onFrame (const QJsonObject & json) {
(chatItem->get_newestFetchedMessageId () == 0)) {
chatItem->set_newestFetchedMessageId (newestMsgId);
}
qWarning () << "GOT" << newMessagesCounter << "MESSAGES" << mode << chatItem->get_oldestFetchedMessageId () << chatItem->get_newestFetchedMessageId ();
}
else {
if (mode == LOAD_OLDER) {
......@@ -1246,7 +1236,6 @@ void QtTdLibGlobal::onFrame (const QJsonObject & json) {
chatItem->set_hasReachedLast (true);
}
else { }
qWarning () << "GOT NO MESSAGES" << mode << chatItem->get_hasReachedFirst () << chatItem->get_hasReachedLast ();
}
if ((chatItem->get_oldestFetchedMessageId () <= chatItem->get_lastReceivedMessageId ()) &&
(chatItem->get_newestFetchedMessageId () >= chatItem->get_lastReceivedMessageId ())) {
......@@ -1426,7 +1415,6 @@ void QtTdLibGlobal::onFrame (const QJsonObject & json) {
break;
}
default: {
qWarning () << "UNHANDLED";
break;
}
}
......
......@@ -9,11 +9,12 @@
#include <td/telegram/td_json_client.h>
#include <td/telegram/td_log.h>
QtTdLibJsonWrapper::QtTdLibJsonWrapper (QObject * parent)
QtTdLibJsonWrapper::QtTdLibJsonWrapper (const bool debug, QObject * parent)
: QThread { parent }
, m_debug { debug }
, m_tdJsonClientHandle { td_json_client_create () }
{
td_set_log_verbosity_level (1);
td_set_log_verbosity_level (m_debug ? 2 : 1);
}
QtTdLibJsonWrapper::~QtTdLibJsonWrapper (void) {
......@@ -22,12 +23,17 @@ QtTdLibJsonWrapper::~QtTdLibJsonWrapper (void) {
void QtTdLibJsonWrapper::run (void) {
forever {
const QByteArray tmp { QByteArray (td_json_client_receive (m_tdJsonClientHandle, 1)) };
const QByteArray tmp { td_json_client_receive (m_tdJsonClientHandle, 1) };
if (!tmp.isEmpty ()) {
const QJsonObject json { QJsonDocument::fromJson (tmp).object () };
if (!json.isEmpty ()) {
qWarning () << "RECV" << json;
if (m_debug) {
qWarning () << "RECV [IN]" << json;
}
emit recv (json);
if (m_debug) {
qWarning () << "RECV [OUT]";
}
if (QtTdLibEnums::objectTypeEnumFromJson (json) == QtTdLibObjectType::UPDATE_AUTHORIZATION_STATE) {
if (QtTdLibEnums::objectTypeEnumFromJson (json ["authorization_state"].toObject ()) == QtTdLibObjectType::AUTHORIZATION_STATE_CLOSED) {
break;
......@@ -39,17 +45,25 @@ void QtTdLibJsonWrapper::run (void) {
}
QJsonObject QtTdLibJsonWrapper::exec (const QJsonObject & json) {
qWarning () << "EXEC [IN]" << json;
if (m_debug) {
qWarning () << "EXEC [IN]" << json;
}
const QByteArray tmp { (QJsonDocument (json).toJson (QJsonDocument::Compact) % '\0') };
const QByteArray str { QByteArray (td_json_client_execute (m_tdJsonClientHandle, tmp.constData ())) };
const QJsonObject ret { QJsonDocument::fromJson (str).object () };
qWarning () << "EXEC [OUT]" << ret;
if (m_debug) {
qWarning () << "EXEC [OUT]" << ret;
}
return ret;
}
void QtTdLibJsonWrapper::send (const QJsonObject & json) {
qWarning () << "SEND [IN]" << json;
if (m_debug) {
qWarning () << "SEND [IN]" << json;
}
const QByteArray tmp { (QJsonDocument (json).toJson (QJsonDocument::Compact) % '\0') };
td_json_client_send (m_tdJsonClientHandle, tmp.constData ());
qWarning () << "SEND [OUT]";
if (m_debug) {
qWarning () << "SEND [OUT]";
}
}
......@@ -9,7 +9,7 @@ class QtTdLibJsonWrapper : public QThread {
Q_OBJECT
public:
explicit QtTdLibJsonWrapper (QObject * parent = Q_NULLPTR);
explicit QtTdLibJsonWrapper (const bool debug, QObject * parent = Q_NULLPTR);
virtual ~QtTdLibJsonWrapper (void);
Q_INVOKABLE QJsonObject exec (const QJsonObject & json);
......@@ -24,6 +24,7 @@ protected:
void run (void) Q_DECL_FINAL;
private:
const bool m_debug;
void * m_tdJsonClientHandle;
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment