← Back to team overview

linuxdcpp-team team mailing list archive

[Branch ~dcplusplus-team/dcplusplus/trunk] Rev 3372: Added /lastmessage in PMs to show the time of the last message

 

------------------------------------------------------------
revno: 3372
committer: Fredrik Ullner <ullner@xxxxxxxxx>
branch nick: dcplusplus
timestamp: Fri 2013-11-29 21:41:48 +0100
message:
  Added /lastmessage in PMs to show the time of the last message
modified:
  changelog.txt
  dcpp/Util.cpp
  dcpp/Util.h
  help/chat_commands.html
  win32/PrivateFrame.cpp
  win32/PrivateFrame.h


--
lp:dcplusplus
https://code.launchpad.net/~dcplusplus-team/dcplusplus/trunk

Your team Dcplusplus-team is subscribed to branch lp:dcplusplus.
To unsubscribe from this branch go to https://code.launchpad.net/~dcplusplus-team/dcplusplus/trunk/+edit-subscription
=== modified file 'changelog.txt'
--- changelog.txt	2013-11-29 17:42:21 +0000
+++ changelog.txt	2013-11-29 20:41:48 +0000
@@ -5,6 +5,7 @@
 * [L#309815] Hub icon will change depending on user status (user/registered/operator) (ullner)
 * [L#721513] Transferview: Added "Remove file from queue" menu option and "Force attempt" is now only available for downloads (ullner)
 * [L#210217] Add connectivity status for hubs to the favorite hubs window (ullner)
+* [L#593613] Added /lastmessage in PMs to show the time of the last message (ullner)
 
 -- 0.831 2013-11-11 --
 * [L#1249810] Fix NMDC TTH search responses (emtee)

=== modified file 'dcpp/Util.cpp'
--- dcpp/Util.cpp	2013-06-01 13:48:06 +0000
+++ dcpp/Util.cpp	2013-11-29 20:41:48 +0000
@@ -385,17 +385,6 @@
 	return '<' + s + '>';
 }
 
-string Util::getShortTimeString(time_t t) {
-	char buf[255];
-	tm* _tm = localtime(&t);
-	if(_tm == NULL) {
-		strcpy(buf, "xx:xx");
-	} else {
-		strftime(buf, 254, SETTING(TIME_STAMPS_FORMAT).c_str(), _tm);
-	}
-	return Text::toUtf8(buf);
-}
-
 void Util::sanitizeUrl(string& url) {
 	boost::algorithm::trim_if(url, boost::is_space() || boost::is_any_of("<>\""));
 }
@@ -1040,15 +1029,35 @@
 	return y;
 }
 
+string Util::getShortTimeString(time_t t) {
+	char buf[255];
+	tm* _tm = localtime(&t);
+	if(_tm == NULL) {
+		strcpy(buf, "xx:xx");
+	} else {
+		strftime(buf, 254, SETTING(TIME_STAMPS_FORMAT).c_str(), _tm);
+	}
+	return Text::toUtf8(buf);
+}
+
 string Util::getTimeString() {
-	char buf[64];
 	time_t _tt;
 	time(&_tt);
+
+	return getTimeString(_tt);
+}
+
+string Util::getTimeString(time_t _tt) {
+	return getTimeString(_tt, "%X");
+}
+
+string Util::getTimeString(time_t _tt, const string& formatting) {
+	char buf[254];
 	tm* _tm = localtime(&_tt);
 	if(_tm == NULL) {
 		strcpy(buf, "xx:xx:xx");
 	} else {
-		strftime(buf, 64, "%X", _tm);
+		strftime(buf, 254, formatting.c_str(), _tm);
 	}
 	return buf;
 }

=== modified file 'dcpp/Util.h'
--- dcpp/Util.h	2013-08-08 18:04:01 +0000
+++ dcpp/Util.h	2013-11-29 20:41:48 +0000
@@ -222,6 +222,8 @@
 	static string getShortTimeString(time_t t = time(NULL) );
 
 	static string getTimeString();
+	static string getTimeString(time_t t);
+	static string getTimeString(time_t t, const string& formatting);
 	static string toAdcFile(const string& file);
 	static string toNmdcFile(const string& file);
 

=== modified file 'help/chat_commands.html'
--- help/chat_commands.html	2013-11-11 16:54:49 +0000
+++ help/chat_commands.html	2013-11-29 20:41:48 +0000
@@ -66,6 +66,8 @@
   <dt><untranslated>/unignore</untranslated></dt>
   <dd>Adds a user matching definition (or modifies an existing one, if possible) to stop ignoring
   chat messages from the current user.</dd>
+  <dt><untranslated>/lastmessage</untranslated></dt>
+  <dd>Lists the date and time when the last message was sent or received.</dd>
 </dl>
 <h2>Both</h2>
 <dl style="margin-left: 40px;">

=== modified file 'win32/PrivateFrame.cpp'
--- win32/PrivateFrame.cpp	2013-11-13 21:45:15 +0000
+++ win32/PrivateFrame.cpp	2013-11-29 20:41:48 +0000
@@ -68,6 +68,7 @@
 			p->activate();
 
 		p->addChat(message);
+		p->lastMessageTime = message.timestamp;
 
 		if(Util::getAway() && !(SETTING(NO_AWAYMSG_TO_BOTS) && fromBot)) {
 			auto awayMessage = Util::getAwayMessage();
@@ -81,6 +82,7 @@
 	} else {
 		// send the message to the existing window
 		i->second->addChat(message);
+		i->second->lastMessageTime = message.timestamp;
 	}
 
 	WinUtil::notify(WinUtil::NOTIFICATION_PM, Text::toT(message.message), [user] { activateWindow(user); });
@@ -135,7 +137,8 @@
 BaseType(parent, _T(""), IDH_PM, IDI_PRIVATE_OFF, false),
 replyTo(replyTo_),
 online(false),
-conn(nullptr)
+conn(nullptr),
+lastMessageTime(time(NULL))
 {
 	createChat(this);
 	chat->setHelpId(IDH_PM_CHAT);
@@ -379,6 +382,8 @@
 			handleIgnoreChat(false);
 		} else if(Util::stricmp(cmd.c_str(), _T("log")) == 0) {
 			openLog();
+		} else if(Util::stricmp(cmd.c_str(), _T("lastmessage")) == 0) {
+			addStatus(Text::toT(str(F_("Last message occured %1%") % Util::getTimeString(lastMessageTime, "%c"))));
 		} else if(Util::stricmp(cmd.c_str(), _T("help")) == 0) {
 			bool bShowBriefCommands = !param.empty() && (Util::stricmp(param.c_str(), _T("brief")) == 0);
 
@@ -386,7 +391,7 @@
 			{
 				addChat(T_("*** Keyboard commands:") + _T("\r\n") + 
 						WinUtil::commands + 
-						_T(", /direct, /encrypted, /getlist, /grant, /close, /favorite, /ignore, /unignore, /log <system, downloads, uploads>")
+						_T(", /direct, /encrypted, /getlist, /grant, /close, /favorite, /ignore, /unignore, /log <system, downloads, uploads>, /lastmessage")
 						);
 			}
 			else
@@ -407,6 +412,8 @@
 						+ _T("\r\n\t") + T_("Adds a user matching definition (or modifies an existing one, if possible) to ignore chat messages from the current user.")
 						+ _T("\r\n") _T("/unignore")
 						+ _T("\r\n\t") + T_("Adds a user matching definition (or modifies an existing one, if possible) to stop ignoring chat messages from the current user.")
+						+ _T("\r\n") _T("/lastmessage")
+						+ _T("\r\n\t") + T_("Lists the date and time when the last message was sent or received.")
 						);
 			}
 
@@ -566,6 +573,7 @@
 	auto user = uc->getHintedUser();
 	callAsync([this, message, user] {
 		addChat(message);
+		lastMessageTime = message.timestamp;
 		WinUtil::notify(WinUtil::NOTIFICATION_PM, Text::toT(message.message), [user] { activateWindow(user); });
 		WinUtil::mainWindow->TrayPM();
 	});

=== modified file 'win32/PrivateFrame.h'
--- win32/PrivateFrame.h	2013-08-19 21:01:34 +0000
+++ win32/PrivateFrame.h	2013-11-29 20:41:48 +0000
@@ -82,6 +82,8 @@
 	mutable CriticalSection mutex;
 	UserConnection* conn;
 
+	time_t lastMessageTime;
+
 	ParamMap ucLineParams;
 
 	typedef unordered_map<UserPtr, PrivateFrame*, User::Hash> FrameMap;