From 8715459d63e42b5b27cab8259d084ec6475a373f Mon Sep 17 00:00:00 2001 From: Wilfried Goesgens Date: Mon, 29 Dec 2014 16:17:14 +0100 Subject: [PATCH] Adjust the folder counters when reading / deleting / moving messages --- webcit/messages.c | 24 ++++++++++++++------- webcit/messages.h | 1 + webcit/static/summaryview.js | 30 ++++++++++++++++++++++++--- webcit/static/t/mailsummary_json.html | 1 + webcit/static/t/roombanner.html | 1 + 5 files changed, 47 insertions(+), 10 deletions(-) diff --git a/webcit/messages.c b/webcit/messages.c index fd886f415..16293a64c 100644 --- a/webcit/messages.c +++ b/webcit/messages.c @@ -650,10 +650,11 @@ int load_msg_ptrs(const char *servcmd, * \param MatchMSet MSet we want to flag * \param FlagToSet Flag to set on each BasicMsgStruct->Flags if in MSet */ -void SetFlagsFromMSet(HashList *ScanMe, MSet *MatchMSet, int FlagToSet, int Reverse) +long SetFlagsFromMSet(HashList *ScanMe, MSet *MatchMSet, int FlagToSet, int Reverse) { const char *HashKey; long HKLen; + long count = 0; HashPos *at; void *vMsg; message_summary *Msg; @@ -664,17 +665,21 @@ void SetFlagsFromMSet(HashList *ScanMe, MSet *MatchMSet, int FlagToSet, int Reve Msg = (message_summary*) vMsg; if (Reverse && IsInMSetList(MatchMSet, Msg->msgnum)) { Msg->Flags = Msg->Flags | FlagToSet; + count++; } else if (!Reverse && !IsInMSetList(MatchMSet, Msg->msgnum)) { Msg->Flags = Msg->Flags | FlagToSet; + count++; } } DeleteHashPos(&at); + return count; } -void load_seen_flags(void) +long load_seen_flags(void) { + long count = 0; StrBuf *OldMsg; wcsession *WCC = WC; MSet *MatchMSet; @@ -687,15 +692,16 @@ void load_seen_flags(void) } else { FreeStrBuf(&OldMsg); - return; + return 0; } if (ParseMSet(&MatchMSet, OldMsg)) { - SetFlagsFromMSet(WCC->summ, MatchMSet, MSGFLAG_READ, 0); + count = SetFlagsFromMSet(WCC->summ, MatchMSet, MSGFLAG_READ, 0); } DeleteMSet(&MatchMSet); FreeStrBuf(&OldMsg); + return count; } extern readloop_struct rlid[]; @@ -814,7 +820,7 @@ void readloop(long oper, eCustomRoomRenderer ForceRenderer) Stat.startmsg = 0; } - if (Stat.load_seen) load_seen_flags(); + if (Stat.load_seen) Stat.numNewmsgs = load_seen_flags(); /* * Print any inforation above the message list... @@ -832,9 +838,13 @@ void readloop(long oper, eCustomRoomRenderer ForceRenderer) Foo = NewStrBuf (); StrBufPrintf(Foo, "%ld", Stat.nummsgs); - PutBstr(HKEY("__READLOOP:TOTALMSGS"), NewStrBufDup(Foo)); + PutBstr(HKEY("__READLOOP:TOTALMSGS"), NewStrBufDup(Foo)); // keep Foo! + + StrBufPrintf(Foo, "%ld", Stat.numNewmsgs); + PutBstr(HKEY("__READLOOP:NEWMSGS"), NewStrBufDup(Foo)); // keep Foo! + StrBufPrintf(Foo, "%ld", Stat.startmsg); - PutBstr(HKEY("__READLOOP:STARTMSG"), Foo); + PutBstr(HKEY("__READLOOP:STARTMSG"), Foo); // store Foo elsewhere, descope it here. } /* diff --git a/webcit/messages.h b/webcit/messages.h index 0738e947e..3c0145b9a 100644 --- a/webcit/messages.h +++ b/webcit/messages.h @@ -155,6 +155,7 @@ typedef struct _SharedMessageStatus { long startmsg; /* which is the start message? */ long nummsgs; /* How many messages are available to your view? */ + long numNewmsgs; /* if you load the seen-status, this is the count of them. */ long num_displayed; /* counted up for LoadMsgFromServer */ /* TODO: unclear who should access this and why */ long lowest_found; /* smallest Message ID found; */ diff --git a/webcit/static/summaryview.js b/webcit/static/summaryview.js index 1e1e2d94e..a57ecef70 100644 --- a/webcit/static/summaryview.js +++ b/webcit/static/summaryview.js @@ -62,6 +62,14 @@ var toggles = {}; var nummsgs = 0; var startmsg = 0; +var newmsgs = 0; + +function refreshMessageCounter() { + var templStr = document.getElementById("nummsgs_template").innerHTML; + templStr = templStr.replace(/UNREADMSGS/, newmsgs); + templStr = templStr.replace(/TOTALMSGS/, nummsgs); + document.getElementById("nummsgs").innerHTML = templStr; +} function createMessageView() { message_view = document.getElementById("message_list_body"); @@ -148,6 +156,7 @@ function loadMessages(transport) { alert("Message loading failed"); } nummsgs = data['nummsgs']; + newmsgs = data['newmsgs']; msgs = data['msgs']; var length = msgs.length; rowArray = new Array(length); // store so they can be sorted @@ -172,6 +181,7 @@ function loadMessages(transport) { loadingMsg.parentNode.removeChild(loadingMsg); } sizePreviewPane(); + refreshMessageCounter(); } function resortAndDisplay(sortMode) { WCLog("Begin resortAndDisplay"); @@ -271,6 +281,8 @@ function CtdlMessageListClick(evt) { var msgId = parent.getAttribute("citadel:msgid"); var is_shift_pressed = event.shiftKey; var is_ctrl_pressed = event.ctrlKey; + var rowclass = parent.getAttribute("class"); + var msgUnseen = rowclass.search("new_message") >= 0; /* debugging str = '.'; @@ -295,12 +307,15 @@ function CtdlMessageListClick(evt) { document.getElementById("preview_pane").innerHTML = ""; new Ajax.Updater('preview_pane', 'msg/'+msgId, {method: 'get'}); markRow(parent); - var p = encodeURI('g_cmd=SEEN ' + msgId + '|1'); - new Ajax.Request('ajax_servcmd', { + + if (msgUnseen) { + var p = encodeURI('g_cmd=SEEN ' + msgId + '|1'); + new Ajax.Request('ajax_servcmd', { method: 'post', parameters: p, onComplete: CtdlMarkRowAsRead(parent) - }); + }); + } // If the shift key modifier is used, mark a range... } else if (event.button != 2 && is_shift_pressed) { if (originalMarkedRow == null) { @@ -344,6 +359,8 @@ function CtdlMarkRowAsRead(rowElement) { var classes = rowElement.className; classes = classes.replace("new_message",""); rowElement.className = classes; + newmsgs--; + refreshMessageCounter(); } function ApplySort(event) { var target = event.target; @@ -406,10 +423,16 @@ function unmarkAllRows() { function deleteAllMarkedRows() { for(msgId in currentlyMarkedRows) { var row = currentlyMarkedRows[msgId]; + var rowclass = row.getAttribute("class"); + var msgUnseen = rowclass.search("new_message") >= 0; + var rowArrayId = row.getAttribute("citadel:ctdlrowid"); row.parentNode.removeChild(row); delete currentlyMarkedRows[msgId]; delete msgs[rowArrayId]; + if (msgUnseen) + newmsgs--; + nummsgs--; } // Now we have to reconstruct rowarray as the array length has changed */ var newMsgs = new Array(msgs.length-1); @@ -423,6 +446,7 @@ function deleteAllMarkedRows() { } msgs = newMsgs; resortAndDisplay(null); + refreshMessageCounter(); } function deleteAllSelectedMessages() { var mvCommand = ""; diff --git a/webcit/static/t/mailsummary_json.html b/webcit/static/t/mailsummary_json.html index 4329d3ab0..0129a48ca 100644 --- a/webcit/static/t/mailsummary_json.html +++ b/webcit/static/t/mailsummary_json.html @@ -1,4 +1,5 @@ { "nummsgs": , +"newmsgs": , "startmsg": , "roomname": "", "msgs": [