Post-merge cleanups, remove the old message handling
[quassel.git] / src / client / buffer.cpp
1 /***************************************************************************
2  *   Copyright (C) 2005-08 by the Quassel Project                          *
3  *   devel@quassel-irc.org                                                 *
4  *                                                                         *
5  *   This program is free software; you can redistribute it and/or modify  *
6  *   it under the terms of the GNU General Public License as published by  *
7  *   the Free Software Foundation; either version 2 of the License, or     *
8  *   (at your option) version 3.                                           *
9  *                                                                         *
10  *   This program is distributed in the hope that it will be useful,       *
11  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
12  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
13  *   GNU General Public License for more details.                          *
14  *                                                                         *
15  *   You should have received a copy of the GNU General Public License     *
16  *   along with this program; if not, write to the                         *
17  *   Free Software Foundation, Inc.,                                       *
18  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
19  ***************************************************************************/
20 #include <QDebug>
21
22 #include "buffer.h"
23
24 #include "buffersyncer.h"
25 #include "client.h"
26 #include "networkmodel.h"
27 #include "quasselui.h"
28 #include "util.h"
29
30
31 Buffer::Buffer(BufferInfo bufferid, QObject *parent)
32   : QObject(parent),
33     _bufferInfo(bufferid),
34     _isVisible(false),
35     _activityLevel(NoActivity)
36 {
37
38 }
39
40 BufferInfo Buffer::bufferInfo() const {
41   // still needed by the gui *sigh* to request the backlogs *sigh*
42   return _bufferInfo;
43 }
44
45 void Buffer::setVisible(bool visible) {
46   _isVisible = visible;
47   setActivityLevel(NoActivity);
48   if(_lastRcvdMsg.msgId() > 0) setLastSeenMsg(_lastRcvdMsg.msgId());
49 }
50
51 void Buffer::setLastSeenMsg(const MsgId &msgId) {
52   const MsgId oldLastSeen = lastSeenMsg();
53   if(!oldLastSeen.isValid() || (msgId.isValid() && msgId > oldLastSeen)) {
54     _lastSeenMsg = msgId;
55     Client::setBufferLastSeenMsg(bufferInfo().bufferId(), msgId);
56     setActivityLevel(NoActivity);
57   }
58 }
59
60 void Buffer::setActivityLevel(ActivityLevel level) {
61   _activityLevel = level;
62   if(bufferInfo().bufferId() > 0) {
63     Client::networkModel()->setBufferActivity(bufferInfo(), level);
64   }
65 }
66
67 void Buffer::updateActivityLevel(const Message &msg) {
68   // FIXME dirty hack to allow the lastSeen stuff to continue to work
69   //       will be made much nicer once Buffer dies, I hope...
70   if(msg.msgId() > _lastRcvdMsg.msgId()) _lastRcvdMsg = msg;
71
72   if(isVisible())
73     return;
74
75   if(msg.flags() & Message::Self)       // don't update activity for our own messages
76     return;
77
78   if(lastSeenMsg().isValid() && lastSeenMsg() >= msg.msgId())
79     return;
80
81   ActivityLevel level = activityLevel() | OtherActivity;
82   if(msg.type() & (Message::Plain | Message::Notice | Message::Action))
83     level |= NewMessage;
84
85   if(msg.flags() & Message::Highlight)
86     level |= Highlight;
87
88   if(level != activityLevel())
89     setActivityLevel(level);
90 }