← Back to team overview

linuxdcpp-team team mailing list archive

[Branch ~dcplusplus-team/dcplusplus/trunk] Rev 3366: identity flags: remove unused ones, add one for self-id and move the ignore-chat bool there

 

------------------------------------------------------------
revno: 3366
committer: poy <poy@xxxxxxxxxx>
branch nick: trunk
timestamp: Sun 2013-11-17 17:15:01 +0100
message:
  identity flags: remove unused ones, add one for self-id and move the ignore-chat bool there
modified:
  dcpp/Client.h
  dcpp/OnlineUser.h
  dcpp/User.cpp


--
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 'dcpp/Client.h'
--- dcpp/Client.h	2013-09-15 16:39:42 +0000
+++ dcpp/Client.h	2013-11-17 16:15:01 +0000
@@ -95,12 +95,20 @@
 	string getHubName() const { return getHubIdentity().getNick().empty() ? getHubUrl() : getHubIdentity().getNick(); }
 	string getHubDescription() const { return getHubIdentity().getDescription(); }
 
-	Identity& getHubIdentity() { return hubIdentity; }
-
 	const string& getHubUrl() const { return hubUrl; }
 
-	GETSET(Identity, myIdentity, MyIdentity);
 	GETSET(Identity, hubIdentity, HubIdentity);
+	Identity& getHubIdentity() { return hubIdentity; }
+
+	// break this GETSET up to add a setSelf call.
+private:
+	Identity myIdentity;
+public:
+	const Identity& getMyIdentity() const { return myIdentity; }
+	template<typename GetSetT> void setMyIdentity(GetSetT&& myIdentity) {
+		myIdentity.setSelf();
+		this->myIdentity = std::forward<GetSetT>(myIdentity);
+	}
 
 	GETSET(uint32_t, uniqueId, UniqueId);
 	GETSET(string, defpassword, Password);

=== modified file 'dcpp/OnlineUser.h'
--- dcpp/OnlineUser.h	2013-01-18 21:28:38 +0000
+++ dcpp/OnlineUser.h	2013-11-17 16:15:01 +0000
@@ -37,14 +37,6 @@
 /** One of possibly many identities of a user, mainly for UI purposes */
 class Identity : public Flags {
 public:
-	enum IdentityFlagBits {
-		GOT_INF_BIT,
-		NMDC_PASSIVE_BIT
-	};
-	enum IdentityFlags {
-		GOT_INF = 1 << GOT_INF_BIT,
-		NMDC_PASSIVE = 1 << NMDC_PASSIVE_BIT
-	};
 	enum ClientType {
 		CT_BOT = 1,
 		CT_REGGED = 2,
@@ -55,15 +47,14 @@
 		CT_HIDDEN = 64
 	};
 
-	Identity() : sid(0), ignoreChat(false) { }
-	Identity(const UserPtr& ptr, uint32_t aSID) : user(ptr), sid(aSID), ignoreChat(false) { }
+	Identity() : sid(0) { }
+	Identity(const UserPtr& ptr, uint32_t aSID) : user(ptr), sid(aSID) { }
 	Identity(const Identity& rhs) : Flags(), sid(0) { *this = rhs; } // Use operator= since we have to lock before reading...
 	Identity& operator=(const Identity& rhs) {
 		FastLock l(cs);
 		*static_cast<Flags*>(this) = rhs;
 		user = rhs.user;
 		sid = rhs.sid;
-		ignoreChat = rhs.ignoreChat;
 		style = rhs.style;
 		info = rhs.info;
 		return *this;
@@ -120,6 +111,9 @@
 	UserPtr& getUser() { return user; }
 	uint32_t getSID() const { return sid; }
 
+	bool isSelf() const;
+	void setSelf();
+
 	bool noChat() const;
 	void setNoChat(bool ignoreChat);
 
@@ -127,6 +121,14 @@
 	void setStyle(Style&& style);
 
 private:
+	enum {
+		// This identity corresponds to this client's user.
+		SELF_ID = 1 << 0,
+
+		// Chat messages from this identity shall be ignored.
+		IGNORE_CHAT = 1 << 1
+	};
+
 	UserPtr user;
 	uint32_t sid;
 
@@ -134,7 +136,6 @@
 	typedef InfMap::iterator InfIter;
 	InfMap info;
 
-	bool ignoreChat;
 	Style style;
 
 	static FastCriticalSection cs;

=== modified file 'dcpp/User.cpp'
--- dcpp/User.cpp	2013-01-18 21:28:38 +0000
+++ dcpp/User.cpp	2013-11-17 16:15:01 +0000
@@ -203,14 +203,31 @@
 	return ret;
 }
 
+bool Identity::isSelf() const {
+	FastLock l(cs);
+	return Flags::isSet(SELF_ID);
+}
+
+void Identity::setSelf() {
+	FastLock l(cs);
+	if(!Flags::isSet(SELF_ID))
+		Flags::setFlag(SELF_ID);
+}
+
 bool Identity::noChat() const {
 	FastLock l(cs);
-	return ignoreChat;
+	return Flags::isSet(IGNORE_CHAT);
 }
 
 void Identity::setNoChat(bool ignoreChat) {
 	FastLock l(cs);
-	this->ignoreChat = ignoreChat;
+	if(ignoreChat) {
+		if(!Flags::isSet(IGNORE_CHAT))
+			Flags::setFlag(IGNORE_CHAT);
+	} else {
+		if(Flags::isSet(IGNORE_CHAT))
+			Flags::unsetFlag(IGNORE_CHAT);
+	}
 }
 
 Style Identity::getStyle() const {