Files
@ 272876d2bdd2
Branch filter:
Location: libtransport.git/backends/libcommuni/session.h - annotation
272876d2bdd2
4.6 KiB
text/plain
libpurple: update unseen count in conversation on active XMPP chatstate
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 | addac0040c4a addac0040c4a e312a8602ec7 addac0040c4a addac0040c4a addac0040c4a addac0040c4a addac0040c4a addac0040c4a addac0040c4a addac0040c4a addac0040c4a addac0040c4a addac0040c4a addac0040c4a addac0040c4a addac0040c4a addac0040c4a e312a8602ec7 e312a8602ec7 e312a8602ec7 e312a8602ec7 e312a8602ec7 47b1db7f432c e312a8602ec7 e312a8602ec7 1c5504d7c60b 1c5504d7c60b 11a084deb042 47b1db7f432c e312a8602ec7 e312a8602ec7 e312a8602ec7 0e56fb848472 0e56fb848472 e312a8602ec7 e312a8602ec7 e312a8602ec7 e312a8602ec7 e312a8602ec7 1c5504d7c60b 1c5504d7c60b 11a084deb042 11a084deb042 1c5504d7c60b 1c5504d7c60b 1c5504d7c60b 1c5504d7c60b 11a084deb042 11a084deb042 11a084deb042 11a084deb042 11a084deb042 11a084deb042 11a084deb042 11a084deb042 11a084deb042 1c5504d7c60b 1c5504d7c60b 1c5504d7c60b 11a084deb042 11a084deb042 1c5504d7c60b 1c5504d7c60b 150afaed9002 150afaed9002 150afaed9002 150afaed9002 150afaed9002 150afaed9002 150afaed9002 150afaed9002 150afaed9002 150afaed9002 150afaed9002 150afaed9002 150afaed9002 150afaed9002 1c5504d7c60b 150afaed9002 1c5504d7c60b 0e56fb848472 11a084deb042 e312a8602ec7 1c5504d7c60b 11a084deb042 e312a8602ec7 e312a8602ec7 e312a8602ec7 1c5504d7c60b 2d3069e6029c e312a8602ec7 e312a8602ec7 58fbe0d388c6 58fbe0d388c6 58fbe0d388c6 58fbe0d388c6 a32e962a1a97 a32e962a1a97 a32e962a1a97 a32e962a1a97 e312a8602ec7 e312a8602ec7 e312a8602ec7 e312a8602ec7 e312a8602ec7 e312a8602ec7 e312a8602ec7 e312a8602ec7 79b50300351f 79b50300351f 79b50300351f 79b50300351f 150afaed9002 150afaed9002 150afaed9002 150afaed9002 718dd59fda2e 718dd59fda2e 718dd59fda2e 718dd59fda2e 2d3069e6029c 2d3069e6029c 2d3069e6029c 2d3069e6029c e312a8602ec7 e312a8602ec7 e312a8602ec7 e312a8602ec7 e312a8602ec7 e312a8602ec7 e312a8602ec7 e312a8602ec7 e312a8602ec7 e312a8602ec7 5c2d081a315c e312a8602ec7 58fbe0d388c6 58fbe0d388c6 58fbe0d388c6 e312a8602ec7 e312a8602ec7 e312a8602ec7 0e56fb848472 e312a8602ec7 e312a8602ec7 11a084deb042 e312a8602ec7 e312a8602ec7 0e56fb848472 e312a8602ec7 e312a8602ec7 1c5504d7c60b e312a8602ec7 9e84e718548d 3201977efb6a 3201977efb6a a32e962a1a97 150afaed9002 11a084deb042 e312a8602ec7 e312a8602ec7 e312a8602ec7 | /**
* XMPP - libpurple transport
*
* Copyright (C) 2013, Jan Kaluza <hanzz.k@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
*/
#ifndef SESSION_H
#define SESSION_H
#ifndef Q_MOC_RUN
#include <IrcSession>
#include <transport/networkplugin.h>
#include "Swiften/Swiften.h"
#include <boost/smart_ptr/make_shared.hpp>
#include <QTimer>
#endif
using namespace Transport;
class IRCNetworkPlugin;
class MyIrcSession : public IrcSession
{
Q_OBJECT
public:
class AutoJoinChannel {
public:
AutoJoinChannel(const std::string &channel = "", const std::string &password = "", int awayCycle = 12) : m_channel(channel), m_password(password),
m_awayCycle(awayCycle), m_currentAwayTick(0) {}
virtual ~AutoJoinChannel() {}
const std::string &getChannel() { return m_channel; }
const std::string &getPassword() { return m_password; }
bool shouldAskWho() {
if (m_currentAwayTick == m_awayCycle) {
m_currentAwayTick = 0;
return true;
}
m_currentAwayTick++;
return false;
}
private:
std::string m_channel;
std::string m_password;
int m_awayCycle;
int m_currentAwayTick;
};
class IRCBuddy {
public:
IRCBuddy(bool op = false, bool away = false) : m_op(op), m_away(away) {};
void setOp(bool op) { m_op = op; }
bool isOp() { return m_op; }
void setAway(bool away) { m_away = away; }
bool isAway() { return m_away; }
private:
bool m_op;
bool m_away;
};
typedef std::map<std::string, boost::shared_ptr<AutoJoinChannel> > AutoJoinMap;
typedef std::map<std::string, std::map<std::string, IRCBuddy> > IRCBuddyMap;
MyIrcSession(const std::string &user, IRCNetworkPlugin *np, const std::string &suffix = "", QObject* parent = 0);
virtual ~MyIrcSession();
void addAutoJoinChannel(const std::string &channel, const std::string &password) {
m_autoJoin[channel] = boost::make_shared<AutoJoinChannel>(channel, password, 12 + m_autoJoin.size());
}
void removeAutoJoinChannel(const std::string &channel) {
m_autoJoin.erase(channel);
removeIRCBuddies(channel);
}
// We are sending PM message. On XMPP side, user is sending PM using the particular channel,
// for example #room@irc.freenode.org/hanzz. On IRC side, we are forwarding this message
// just to "hanzz". Therefore we have to somewhere store, that message from "hanzz" should
// be mapped to #room@irc.freenode.org/hanzz.
void addPM(const std::string &name, const std::string &room) {
m_pms[name] = room;
}
void setIdentify(const std::string &identify) {
m_identify = identify;
}
const std::string &getIdentify() {
return m_identify;
}
bool hasIRCBuddy(const std::string &channel, const std::string &name) {
return m_buddies[channel].find(name) != m_buddies[channel].end();
}
IRCBuddy &getIRCBuddy(const std::string &channel, const std::string &name) {
return m_buddies[channel][name];
}
void removeIRCBuddy(const std::string &channel, const std::string &name) {
m_buddies[channel].erase(name);
}
void removeIRCBuddies(const std::string &channel) {
m_buddies.erase(channel);
}
bool correctNickname(std::string &nickname);
void on_joined(IrcMessage *message);
void on_parted(IrcMessage *message);
void on_quit(IrcMessage *message);
void on_nickChanged(IrcMessage *message);
void on_modeChanged(IrcMessage *message);
void on_topicChanged(IrcMessage *message);
void on_messageReceived(IrcMessage *message);
void on_numericMessageReceived(IrcMessage *message);
void on_noticeMessageReceived(IrcMessage *message);
std::string suffix;
int rooms;
protected Q_SLOTS:
void on_connected();
void on_disconnected();
void on_socketError(QAbstractSocket::SocketError error);
void onMessageReceived(IrcMessage* message);
void awayTimeout();
protected:
IRCNetworkPlugin *np;
std::string user;
std::string m_identify;
AutoJoinMap m_autoJoin;
std::string m_topicData;
bool m_connected;
std::list<std::string> m_rooms;
std::list<std::string> m_names;
std::map<std::string, std::string> m_pms;
IRCBuddyMap m_buddies;
QTimer *m_awayTimer;
};
#endif // SESSION_H
|