From 3d8b3afe4f9b20bf8b393987e4f618ba3159b79d Mon Sep 17 00:00:00 2001 From: George Hazan Date: Tue, 16 Jun 2020 18:04:35 +0300 Subject: Clist_Modern: fix for sorting by last message time --- plugins/Clist_modern/src/modern_clc.cpp | 4 +++- plugins/Clist_modern/src/modern_contact.cpp | 7 ++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/plugins/Clist_modern/src/modern_clc.cpp b/plugins/Clist_modern/src/modern_clc.cpp index 27b0dbbbdb..828ee36779 100644 --- a/plugins/Clist_modern/src/modern_clc.cpp +++ b/plugins/Clist_modern/src/modern_clc.cpp @@ -162,8 +162,10 @@ static int clcHookDbEventAdded(WPARAM hContact, LPARAM hDbEvent) if ((dbei.eventType == EVENTTYPE_MESSAGE || dbei.eventType == EVENTTYPE_FILE) && !(dbei.flags & DBEF_SENT)) { g_plugin.setDword(hContact, "mf_lastmsg", dbei.timestamp); ClcCacheEntry *pdnce = Clist_GetCacheEntry(hContact); - if (pdnce) + if (pdnce) { pdnce->dwLastMsgTime = dbei.timestamp; + Clist_Broadcast(CLM_AUTOREBUILD, hContact, 0); + } } } return 0; diff --git a/plugins/Clist_modern/src/modern_contact.cpp b/plugins/Clist_modern/src/modern_contact.cpp index 53a4ba2e22..eb4285f2eb 100644 --- a/plugins/Clist_modern/src/modern_contact.cpp +++ b/plugins/Clist_modern/src/modern_contact.cpp @@ -119,7 +119,12 @@ int cliCompareContacts(const ClcContact *contact1, const ClcContact *contact2) break; case SORTBY_LASTMSG: // last message - r = (int)CompareContacts2_getLMTime(contact2->hContact) - (int)CompareContacts2_getLMTime(contact1->hContact); + if (c1->dwLastMsgTime == -1) c1->dwLastMsgTime = CompareContacts2_getLMTime(contact1->hContact); + if (c2->dwLastMsgTime == -1) c2->dwLastMsgTime = CompareContacts2_getLMTime(contact2->hContact); + if (c1->dwLastMsgTime == c2->dwLastMsgTime) + continue; + + r = (c1->dwLastMsgTime < c2->dwLastMsgTime) ? 1 : -1; // reverse sort order break; case SORTBY_PROTO: -- cgit v1.2.3