andreas-mausch / whatsapp-viewer

Small tool to display chats from the Android msgstore.db database (crypt12)
https://andreas-mausch.de/whatsapp-viewer/
MIT License
1.23k stars 381 forks source link

Misplaced messages in exportation #102

Open Rourke101 opened 3 years ago

Rourke101 commented 3 years ago

I have an old conversation, where I was in one time zone and the other person was in another time zone. Whatsapp used to print the dates as they were in each place, or somehow there was a 1h delay, so when I export the conversation with whatsapp-viewer, the messages sent and the messages received are completely mismatched.

However, Whatsapp shows them correctly.

Example:

05:16  Hello how are you
      I am fine, thanks  04:16
05:16  Can you send me the contact?
      Yes, of course 04:17

This conversation is in my Whastapp exactly like this. However, it gets totally messed up by whatsapp-viewer, because it re-orders the messages according to the time. So it places the "05:16" received messages next to the "05:16" sent messages, which is wrong in this case.

Is there an easy fix for this? Like ordering messages as Whatsapp recorded them instead of time based.


Note: I also tried v1.2 where chat messages seems to be obtained in a different way, but it didn't work either. Messages are still located according to the time Whatsapp recorded instead of according to the actual time they were sent/received. The thing is that Whatsapp must use a different system (not time-based) to display the messages in the correct order

Rourke101 commented 3 years ago

I have solved the problem by modifying a query and recompiling the solution.

So the "ORDER BY messages.timestamp asc" must be removed (--) in this query:

void QueryMessagesThread::run()
{
    const char *query = "SELECT messages.key_id, messages.key_remote_jid, messages.key_from_me, messages.status, messages.data, messages.timestamp, messages.media_url, messages.media_mime_type, messages.media_wa_type, messages.media_size, messages.media_name, messages.media_caption, messages.media_duration, messages.latitude, messages.longitude, messages.thumb_image, messages.remote_resource, messages.raw_data, message_thumbnails.thumbnail, messages_quotes.key_id, messages_links._id " \
                "FROM messages " \
                "LEFT JOIN message_thumbnails on messages.key_id = message_thumbnails.key_id " \
                "LEFT JOIN messages_quotes on messages.quoted_row_id > 0 AND messages.quoted_row_id = messages_quotes._id " \
                "LEFT JOIN messages_links on messages._id = messages_links.message_row_id " \
                "WHERE messages.key_remote_jid = ? " \
                "ORDER BY messages.timestamp asc";

File: https://github.com/andreas-mausch/whatsapp-viewer/blob/master/source/WhatsApp/QueryMessagesThread.cpp

This way, the messages will be displayed as WhatsApp sees them.

If someone has the same problem, my recompiled version can be found here: https://mega.nz/file/lUwDTYhI#y8SQfHoNShAJe6ggkyhYWWpxrAaRy2r_VwD_sW15pXU