2222#include < cassert>
2323
2424#include < QClipboard>
25+ #include < QCryptographicHash>
2526#include < QDebug>
2627#include < QDesktopServices>
2728#include < QDesktopWidget>
@@ -2073,7 +2074,7 @@ void Widget::onGroupMessageReceived(int groupnumber, int peernumber, const QStri
20732074 groupMessageDispatchers[groupId]->onMessageReceived (author, isAction, isPrivate, message, hasIdType);
20742075}
20752076
2076- void Widget::onGroupMessageReceivedImage (int groupnumber, int peernumber, const uint8_t *image_data ,
2077+ void Widget::onGroupMessageReceivedImage (int groupnumber, int peernumber, const QByteArray& image_bytes ,
20772078 size_t length, bool isAction, const int hasIdType)
20782079{
20792080 const GroupId& groupId = groupList->id2Key (groupnumber);
@@ -2084,25 +2085,28 @@ void Widget::onGroupMessageReceivedImage(int groupnumber, int peernumber, const
20842085 std::ignore = isAction;
20852086 std::ignore = hasIdType;
20862087
2087- QByteArray image_data_bytes = QByteArray (reinterpret_cast <const char *>(image_data), length);
2088- // qDebug() << "onGroupMessageReceivedImage:image_data_bytes:"
2089- // << QString::fromUtf8(image_data_bytes.toHex()).toUpper().rightJustified((length * 2), '0')
2088+ QByteArray shaBa = QCryptographicHash::hash (image_bytes, QCryptographicHash::Sha256);
2089+ QString sha256hash = QString::fromUtf8 (shaBa.toHex ()).toUpper ();
2090+ qDebug () << " onGroupMessageReceivedImage:SHA256:" << sha256hash << " length" << length;
2091+
2092+ // qDebug() << "onGroupMessageReceivedImage:image_bytes:"
2093+ // << QString::fromUtf8(image_bytes.toHex()).toUpper().rightJustified((length * 2), '0')
20902094 // << "len:" << length;
20912095
20922096 QPixmap mpixmap;
2093- bool result = mpixmap.loadFromData (image_data_bytes );
2097+ bool result = mpixmap.loadFromData (image_bytes );
20942098 if (!result)
20952099 {
20962100 qDebug () << " onGroupMessageReceivedImage:loadFromData:trying with hardcoded WEBP type" ;
2097- result = mpixmap.loadFromData (image_data_bytes , " WEBP" );
2101+ result = mpixmap.loadFromData (image_bytes , " WEBP" );
20982102 }
20992103 qDebug () << " onGroupMessageReceivedImage:loadFromData:res=" << result;
21002104
21012105 // if (result)
21022106 // {
21032107 // HINT: image could be loaded OK, so save hex data into DB
21042108 // add message even if image could not be loaded
2105- QString message = QString::fromUtf8 (image_data_bytes .toHex ()).toUpper ().rightJustified ((length * 2 ), ' 0' ) + QString (" :" ) + QString (" ___" );
2109+ QString message = QString::fromUtf8 (image_bytes .toHex ()).toUpper ().rightJustified ((length * 2 ), ' 0' ) + QString (" :" ) + QString (" ___" );
21062110 groupMessageDispatchers[groupId]->onMessageReceived (author, isAction, false , message, hasIdType);
21072111 // }
21082112}
0 commit comments