Changeset 378:77e70b2ae3e2

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

Calc real online time of user

Files:
4 modified

Legend:

Unmodified
Added
Removed
  • sql/update/pgsql/00374.sql

    r377 r378  
    33  id SERIAL, 
    44  jid_id int NOT NULL, 
     5 
     6  time_online int NOT NULL default 0,  
     7 
    58  lastaction int NOT NULL default '0', 
    69  lastreason varchar(200) NULL, 
  • src/plugins/muc/jidstat.cpp

    r377 r378  
    3232        jidId_ = jidId; 
    3333 
     34        dateTime_ = QDateTime::currentDateTime(); 
    3435        if (jidId_ > 0) 
    3536        { 
     
    149150        if (!cntName.isEmpty()) 
    150151        { 
    151                 q.prepare(QString("UPDATE conference_jidstat set %1 = %1 + 1 WHERE id=?").arg(cntName, cntName)); 
     152                q.prepare(QString("UPDATE conference_jidstat set %1 = %2 + 1 WHERE id=?").arg(cntName).arg(cntName)); 
    152153                q.addBindValue(id_); 
    153154                if (!q.exec()) 
     
    156157                } 
    157158        } 
     159        updateOnlineTime(); 
    158160} 
    159161 
     
    173175        } 
    174176} 
     177 
     178void JidStat::updateOnlineTime() 
     179{ 
     180        if (id_ <= 0) 
     181                return; 
     182        QDateTime now = QDateTime::currentDateTime(); 
     183        int delta = dateTime_.secsTo(now); 
     184        QSqlQuery q = DataStorage::instance()->prepareQuery( 
     185                        "UPDATE conference_jidstat SET time_online = time_online + ? WHERE id=?" 
     186        ); 
     187        q.addBindValue(delta); 
     188        q.addBindValue(id_); 
     189        if (!q.exec()) 
     190        { 
     191                qDebug() << "ERROR: Unable to update time_online"; 
     192        } 
     193        else 
     194        { 
     195                dateTime_=now; 
     196        } 
     197 
     198} 
  • src/plugins/muc/jidstat.h

    r377 r378  
    2222 
    2323#include <QString> 
     24#include <QDateTime> 
    2425 
    2526class JidStat 
     
    5354        void setLastAction(ActionType type, const QString& reason); 
    5455        void setVersion(const QString& version); 
     56        void updateOnlineTime(); 
    5557private: 
    5658        int id_; 
    5759        int jidId_; 
     60        QDateTime dateTime_; 
    5861 
    5962        bool load(); 
  • src/plugins/muc/nick.cpp

    r375 r378  
    134134                delete myJid; 
    135135        } 
     136        if (myJidStat) 
     137                myJidStat->updateOnlineTime(); 
    136138        delete myJidStat; 
    137139}