Changeset 375:96bb8d64e6ad

Show
Ignore:
Timestamp:
05/18/2009 09:54:18 PM (3 years ago)
Author:
Dmitry Nezhevenko <dion@…>
Branch:
default
Message:

Intiail Nick statistic

Files:
3 added
7 modified

Legend:

Unmodified
Added
Removed
  • src/plugins/muc/CMakeLists.txt

    r298 r375  
    1212        conferencelist.h 
    1313        jid.h 
     14        jidstat.h 
    1415        nick.h 
    1516        nicklist.h 
     
    2324        conferencelist.cpp 
    2425        jid.cpp 
     26        jidstat.cpp 
    2527        mucplugin.cpp 
    2628        nick.cpp 
  • src/plugins/muc/jid.cpp

    r373 r375  
    5656void Jid::loadJid() 
    5757{ 
     58        myId == 0; 
    5859        QSqlQuery query=DataStorage::instance() 
    5960                ->prepareQuery("SELECT id,created FROM conference_jids WHERE conference_id = ? AND jid = ?"); 
  • src/plugins/muc/jid.h

    r227 r375  
    2323        void commit(); 
    2424        void remove(); 
     25        bool isTemporary() const { return myTemporary; } 
    2526        static void removeTemporary(Conference *conf=0); 
    2627private: 
  • src/plugins/muc/mucplugin.cpp

    r367 r375  
    55#include "alistitem.h" 
    66#include "jid.h" 
     7#include "jidstat.h" 
    78#include "config/mucconfigurator.h" 
    89#include "nickasyncrequest.h" 
     
    3637                        << "ATRACE"  << "SEEN" << "CLIENTS" << "SETNICK" << "CHECKVCARD" << "ROLE" << "VERSION"; 
    3738        commands << "HERE" << "STATUS" << "AGE" << "AGESTAT"; 
    38          
     39 
    3940        commands << "POKE"; 
    4041        pluginId=1; 
     
    258259                        n=0; 
    259260                } 
    260  
    261261        } 
    262262 
     
    272272                conf->nicks()->append(n); 
    273273 
     274                JidStat *stat = n->jidStat(); 
     275                if (stat) 
     276                { 
     277                        // Just presence? 
     278                        QString show = getPresence(s->presence()); 
     279                        QString status = QString::fromStdString(s->status()); 
     280                        if (!status.isEmpty()) 
     281                                show += QString(" (%1)").arg(status); 
     282                        stat->setLastAction(JidStat::ActionJoin, show); 
     283                } 
     284 
    274285                if (nick==conf->nick()) 
    275286                { 
     
    283294                        newNick=true; 
    284295        } 
     296 
    285297        if (role=="none" || type=="unavailable") 
    286298        { 
     
    308320                { 
    309321                        qDebug() << "!!!!!! Removing nick"; 
     322                        JidStat *stat = n->jidStat(); 
     323                        if (stat) 
     324                        { 
     325                                int statusCode = getStatus(s); 
     326                                if (statusCode == 307 || statusCode == 301) 
     327                                { 
     328                                        JidStat::ActionType actType = statusCode == 307 
     329                                                ? JidStat::ActionKick : JidStat::ActionBan; 
     330                                        QString reason = getReason(s); 
     331                                        stat->setLastAction(actType, reason); 
     332                                } 
     333                                else 
     334                                { 
     335                                        // Just presence? 
     336                                        QString show = QString::fromStdString(s->status()); 
     337                                        stat->setLastAction(JidStat::ActionLeave, show); 
     338                                } 
     339                        } 
    310340                        conf->nicks()->remove(n); 
    311341                        conf->alistTraceList()->removeAll(QString::fromStdString(s->from().full())); 
     
    315345        else 
    316346        { 
     347                JidStat *stat = n->jidStat(); 
     348                if (stat && !newNick) 
     349                { 
     350                        if (n->role() != role) 
     351                        { 
     352                                JidStat::ActionType actType = JidStat::ActionNone; 
     353                                if (role == "moderator") 
     354                                        actType = JidStat::ActionModerator; 
     355                                else if (role == "participant") 
     356                                        actType = JidStat::ActionParticipant; 
     357                                else if (role == "visitor") 
     358                                        actType = JidStat::ActionVisitor; 
     359                                QString reason = getReason(s); 
     360                                stat->setLastAction(actType, reason); 
     361                        } 
     362                        else if (n->affiliation() != getItem(s, "affiliation")) 
     363                        { 
     364                                QString aff = getItem(s, "affiliation"); 
     365                                JidStat::ActionType actType = JidStat::ActionNone; 
     366                                if (aff == "none") 
     367                                        actType = JidStat::ActionNoAffiliation; 
     368                                else if (aff == "member") 
     369                                        actType = JidStat::ActionMember; 
     370                                else if (aff == "administrator") 
     371                                        actType = JidStat::ActionAdministrator; 
     372                                else if (role == "owner") 
     373                                        actType = JidStat::ActionOwner; 
     374                                QString reason = getReason(s); 
     375                                stat->setLastAction(actType, reason); 
     376                        } 
     377                        else 
     378                        { 
     379                                // Just presence? 
     380                                QString show = getPresence(s->presence()); 
     381                                QString status = QString::fromStdString(s->status()); 
     382                                if (!status.isEmpty()) 
     383                                        show += QString(" (%1)").arg(status); 
     384                                stat->setLastAction(JidStat::ActionPresence, show); 
     385                        } 
     386                } 
     387 
    317388                n->setAffiliation(getItem(s, "affiliation")); 
    318389                n->setJid(getItem(s, "jid")); 
     
    499570                << "тресёт %1 за плечО" 
    500571                << "кОМул МПж в стПрПМу %1"; 
    501                  
     572 
    502573                srand ( time(NULL) ); 
    503574                int r = rand() % replys.count(); 
    504575                QString msg = replys[r]; 
    505                  
     576 
    506577                if( arg.isEmpty() ) 
    507578                { 
     
    525596                        return true; 
    526597                } 
    527                 if ( arg.compare(nickName, Qt::CaseInsensitive) == 0 )  
     598                if ( arg.compare(nickName, Qt::CaseInsensitive) == 0 ) 
    528599                { 
    529600                        reply(s, "ЌазПѠ
     
    534605                for (int i=0; i<cnt; i++) 
    535606                { 
    536                         if( arg.compare( conf->nicks()->at(i)->nick(), Qt::CaseInsensitive ) == 0 )  
     607                        if( arg.compare( conf->nicks()->at(i)->nick(), Qt::CaseInsensitive ) == 0 ) 
    537608                        { 
    538609                                reply(s, QString("/me " + msg) 
     
    10761147        } 
    10771148        return QString::fromStdString(res).toInt(); 
     1149} 
     1150 
     1151 
     1152QString MucPlugin::getReason(gloox::Stanza* s) 
     1153{ 
     1154        std::string res; 
     1155        if (s->hasChild("x", "xmlns", "http://jabber.org/protocol/muc#user")) 
     1156        { 
     1157                gloox::Tag *tg1=s->findChild("x", "xmlns", 
     1158                                "http://jabber.org/protocol/muc#user"); 
     1159                if (!tg1) 
     1160                        return ""; 
     1161                if (tg1->hasChild("item")) 
     1162                { 
     1163                        gloox::Tag *tg2=tg1->findChild("item"); 
     1164                        if (!tg2) 
     1165                                return ""; 
     1166                        tg2 = tg2->findChild("reason"); 
     1167                        if (!tg2) 
     1168                                return ""; 
     1169                        res = tg2->cdata(); 
     1170                } 
     1171        } 
     1172        return QString::fromStdString(res); 
    10781173} 
    10791174 
  • src/plugins/muc/mucplugin.h

    r334 r375  
    6868        QString affiliationByCommand(const QString& cmd); 
    6969        int getStatus(gloox::Stanza* s); 
     70        QString getReason(gloox::Stanza *s); 
    7071        bool warnImOwner(gloox::Stanza* s); 
    7172        int getRoleForNick(Conference* conf, Nick* nick); 
  • src/plugins/muc/nick.cpp

    r335 r375  
    22#include "conference.h" 
    33#include "jid.h" 
     4#include "jidstat.h" 
    45#include "base/datastorage.h" 
    56 
     
    1516        myValidateRequired=false; 
    1617        myParent=parent; 
     18        myJidStat = NULL; 
    1719        myNick=nick; 
    1820        myLazyLeave=false; 
     
    2325 
    2426        myJid=new Jid(this, jid); 
     27 
     28        if (myJid->id() >= 0 ) 
     29                myJidStat = new JidStat(myJid->id()); 
    2530 
    2631        QSqlQuery query=DataStorage::instance() 
     
    8287        devoicedNoVCard_=false; 
    8388        myParent=parent; 
     89        myJidStat = NULL; 
    8490        myLazyLeave=false; 
    8591        myId=id; 
     
    105111        myJid=new Jid(this, query.value(1).toInt()); 
    106112        myJidS=myJid->jid(); 
     113 
     114        if (myJid->id() >= 0 ) 
     115                        myJidStat = new JidStat(myJid->id()); 
     116 
    107117        myJoined=query.value(2).toDateTime(); 
    108118        myLastActivity=query.value(3).toDateTime(); 
     
    124134                delete myJid; 
    125135        } 
     136        delete myJidStat; 
    126137} 
    127138 
  • src/plugins/muc/nick.h

    r294 r375  
    77class Conference; 
    88class Jid; 
     9class JidStat; 
    910 
    10 class Nick{ 
     11class Nick 
     12{ 
    1113public: 
    1214    Nick(Conference* parent, const QString& nick, const QString& jid=QString::null); 
     
    2426        Conference* conference() const { return myParent; }; 
    2527        Jid* jid() const { return myJid; }; 
     28        JidStat *jidStat() const { return myJidStat; } 
    2629        bool validateRequired() const { return myValidateRequired; }; 
    2730        bool isVersionStored() const { return versionStored_; } 
     
    5760        Conference *myParent; 
    5861        Jid *myJid; 
     62        JidStat *myJidStat; 
    5963        QString myJidS; 
    6064        QString myNick;