From 75a5ad67d7451f6d81cf822238fe653e38a1d8cf Mon Sep 17 00:00:00 2001 From: "scott%scott-macgregor.org" Date: Fri, 9 Jan 2004 06:51:44 +0000 Subject: [PATCH] Bug #75866 --> Mark a message as read in JS instead of once for each mail protocol to simplify code. Hookup the JS function to a timer to allow users to only mark messages as read after they have been viewed in the preview pane for a configurable number of seconds. sr=bienvenu --- mail/base/content/commandglue.js | 3 ++ mail/base/content/mail3PaneWindowCommands.js | 12 +++++++ mail/base/content/mailWindow.js | 1 + mail/base/content/mailWindowOverlay.js | 32 ++++++++++++++++++- mail/base/content/messageWindow.js | 1 + .../prefwindow/content/pref-advanced.xul | 2 -- 6 files changed, 48 insertions(+), 3 deletions(-) diff --git a/mail/base/content/commandglue.js b/mail/base/content/commandglue.js index d457e5d2e9b..220b44b8550 100644 --- a/mail/base/content/commandglue.js +++ b/mail/base/content/commandglue.js @@ -306,6 +306,9 @@ function RerootFolder(uri, newFolder, viewType, viewFlags, sortType, sortOrder) gDBView = null; } + // cancel the pending mark as read timer + ClearPendingReadTimer(); + // if this is the drafts, sent, or send later folder, // we show "Recipient" instead of "Author" SetSentFolderColumns(IsSpecialFolder(newFolder, MSG_FOLDER_FLAG_SENTMAIL | MSG_FOLDER_FLAG_DRAFTS | MSG_FOLDER_FLAG_QUEUE)); diff --git a/mail/base/content/mail3PaneWindowCommands.js b/mail/base/content/mail3PaneWindowCommands.js index dd6dbdcd4e8..5a5e12bbbb3 100644 --- a/mail/base/content/mail3PaneWindowCommands.js +++ b/mail/base/content/mail3PaneWindowCommands.js @@ -469,10 +469,22 @@ var DefaultController = break;// This does nothing because the createfilter is invoked from the popupnode oncommand. case "button_delete": case "cmd_delete": + // if the user deletes a message before its mark as read timer goes off, we should mark it as read + // this ensures that we clear the biff indicator from the system tray when the user deletes the new message + if (gMarkViewedMessageAsReadTimer) + { + MarkCurrentMessageAsRead(); + ClearPendingReadTimer(); + } SetNextMessageAfterDelete(); gDBView.doCommand(nsMsgViewCommandType.deleteMsg); break; case "cmd_shiftDelete": + if (gMarkViewedMessageAsReadTimer) + { + MarkCurrentMessageAsRead(); + ClearPendingReadTimer(); + } SetNextMessageAfterDelete(); gDBView.doCommand(nsMsgViewCommandType.deleteNoTrash); break; diff --git a/mail/base/content/mailWindow.js b/mail/base/content/mailWindow.js index 45fb58a0fbb..2aa87cf275e 100644 --- a/mail/base/content/mailWindow.js +++ b/mail/base/content/mailWindow.js @@ -72,6 +72,7 @@ var gLastKeywords = ""; function OnMailWindowUnload() { RemoveMailOfflineObserver(); + ClearPendingReadTimer(); var searchSession = GetSearchSession(); if (searchSession) diff --git a/mail/base/content/mailWindowOverlay.js b/mail/base/content/mailWindowOverlay.js index bac39ec5ebc..50022aff8b8 100644 --- a/mail/base/content/mailWindowOverlay.js +++ b/mail/base/content/mailWindowOverlay.js @@ -43,6 +43,7 @@ var gWindowManagerInterface; var gPrefs = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch); var gPrintSettings = null; var gWindowReuse = 0; +var gMarkViewedMessageAsReadTimer = null; // if the user has configured the app to mark a message as read if it is viewed for more than n seconds var gTimelineService = null; var gTimelineEnabled = ("@mozilla.org;timeline-service;1" in Components.classes); @@ -2069,6 +2070,20 @@ function SetUpJunkBar(aMsgHdr) goUpdateCommand('button_junk'); } +function MarkCurrentMessageAsRead() +{ + gDBView.doCommand(nsMsgViewCommandType.markMessagesRead); +} + +function ClearPendingReadTimer() +{ + if (gMarkViewedMessageAsReadTimer) + { + clearTimeout(gMarkViewedMessageAsReadTimer); + gMarkViewedMessageAsReadTimer = null; + } +} + function OnMsgLoaded(aUrl) { if (!aUrl) @@ -2076,6 +2091,7 @@ function OnMsgLoaded(aUrl) var folder = aUrl.folder; var msgURI = GetLoadedMessage(); + var msgHdr = null; if (!folder || !msgURI) return; @@ -2084,10 +2100,24 @@ function OnMsgLoaded(aUrl) SetUpJunkBar(null); else { - var msgHdr = messenger.messageServiceFromURI(msgURI).messageURIToMsgHdr(msgURI); + msgHdr = messenger.messageServiceFromURI(msgURI).messageURIToMsgHdr(msgURI); SetUpJunkBar(msgHdr); } + // we just finished loading a message. set a timer to actually mark the message is read after n seconds + // where n can be configured by the user. + + var markReadOnADelay = gPrefs.getBoolPref("mailnews.mark_message_read.delay"); + + if (msgHdr && !msgHdr.isRead) + { + var wintype = document.firstChild.getAttribute('windowtype'); + if (markReadOnADelay && wintype == "mail:3pane") // only use the timer if viewing using the 3-pane preview pane and the user has set the pref + gMarkViewedMessageAsReadTimer = setTimeout(MarkCurrentMessageAsRead, gPrefs.getIntPref("mailnews.mark_message_read.delay.interval") * 1000); + else + MarkCurrentMessageAsRead(); + } + // See if MDN was requested but has not been sent. HandleMDNResponse(aUrl); diff --git a/mail/base/content/messageWindow.js b/mail/base/content/messageWindow.js index 85158225aac..8638b6495bd 100644 --- a/mail/base/content/messageWindow.js +++ b/mail/base/content/messageWindow.js @@ -172,6 +172,7 @@ nsMsgDBViewCommandUpdater.prototype = displayMessageChanged : function(aFolder, aSubject, aKeywords) { setTitleFromFolder(aFolder, aSubject); + ClearPendingReadTimer(); // we are loading / selecting a new message so kill the mark as read timer for the currently viewed message gCurrentMessageUri = gDBView.URIForFirstSelectedMessage; UpdateStandAloneMessageCounts(); SetKeywords(aKeywords); diff --git a/mail/components/prefwindow/content/pref-advanced.xul b/mail/components/prefwindow/content/pref-advanced.xul index 9fec8fd4c33..5fb8394c6dc 100644 --- a/mail/components/prefwindow/content/pref-advanced.xul +++ b/mail/components/prefwindow/content/pref-advanced.xul @@ -125,13 +125,11 @@ -#ifdef 0 -#endif