soc.2009.transport: 4935d686: Better counting of online buddies for st...
hanzz at soc.pidgin.im
hanzz at soc.pidgin.im
Wed Apr 29 13:40:56 EDT 2009
-----------------------------------------------------------------
Revision: 4935d6862cb942d5fbd9acbfd68a17655537c581
Ancestor: c5a3f0d04316710c098ea88eb00a96edbc95ded2
Author: hanzz at soc.pidgin.im
Date: 2009-04-29T17:37:14
Branch: im.pidgin.soc.2009.transport
URL: http://d.pidgin.im/viewmtn/revision/info/4935d6862cb942d5fbd9acbfd68a17655537c581
Modified files:
user.cpp usermanager.cpp usermanager.h
ChangeLog:
Better counting of online buddies for stats.
-------------- next part --------------
============================================================
--- user.cpp 7d781067878152da8f9b388d5dce7e25c7418161
+++ user.cpp 4eec7b778e0a37c321d088c86d8c3b15f089fb0a
@@ -22,6 +22,7 @@
#include "main.h"
#include "log.h"
#include "protocols/abstractprotocol.h"
+#include "usermanager.h"
/*
* Called when contact list has been received from legacy network.
@@ -291,10 +292,16 @@ Tag *User::generatePresenceStanza(Purple
// update stats...
if (s==PURPLE_STATUS_OFFLINE){
- m_roster[name].online=false;
+ if (m_roster[name].online) {
+ m_roster[name].online = false;
+ p->userManager()->buddyOffline();
+ }
}
else
- m_roster[name].online=true;
+ if (!m_roster[name].online) {
+ m_roster[name].online = true;
+ p->userManager()->buddyOnline();
+ }
return tag;
}
@@ -896,6 +903,7 @@ User::~User(){
tag->addAttribute( "type", "unavailable" );
tag->addAttribute( "from", (*u).second.uin+"@"+ p->jid() + "/bot");
p->j->send( tag );
+ p->userManager()->buddyOffline();
}
}
============================================================
--- usermanager.cpp 92565c3e4798b48c52c1f8a89b794c6675d7d93c
+++ usermanager.cpp 6e82743d6eef5d00923184b5dd3cd0212a261b9b
@@ -66,15 +66,14 @@ void UserManager::removeUserTimer(User *
g_timeout_add(0,&deleteUser,user);
}
-long UserManager::onlineUserCount(){
- long users=0;
+void UserManager::buddyOnline() {
+ m_onlineBuddies++;
+}
- for(std::map<std::string,User*>::iterator it = m_users.begin() ; it != m_users.end() ; it++) {
- for(std::map<std::string, RosterRow>::iterator u = (*it).second->roster().begin(); u != (*it).second->roster().end() ; u++){
- if ((*u).second.online==true){
- users+=1;
- }
- }
- }
- return users;
+void UserManager::buddyOffline() {
+ m_onlineBuddies--;
}
+
+long UserManager::onlineUserCount(){
+ return m_onlineBuddies;
+}
============================================================
--- usermanager.h ff85a35775345d6681d2f28fd5dcddda091e23d0
+++ usermanager.h edc2f11c75a806e475cff2df2d9dfed9708b2eaa
@@ -38,12 +38,15 @@ class UserManager
void addUser(User *user) { m_users[user->jid()] = user; }
void removeUser(User *user);
void removeUserTimer(User *user);
+ void buddyOnline();
+ void buddyOffline();
long onlineUserCount();
int userCount() { return m_users.size(); }
private:
GlooxMessageHandler *main;
std::map<std::string, User*> m_users;
+ long m_onlineBuddies;
};
More information about the Commits
mailing list