2011-04-01 23:54:29 +02:00
|
|
|
/**
|
|
|
|
* XMPP - libpurple transport
|
|
|
|
*
|
|
|
|
* Copyright (C) 2009, Jan Kaluza <hanzz@soc.pidgin.im>
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
#include <algorithm>
|
2015-11-18 14:05:57 +01:00
|
|
|
#include <list>
|
2011-04-01 23:54:29 +02:00
|
|
|
#include "Swiften/Elements/Message.h"
|
2015-11-16 10:49:10 +01:00
|
|
|
#include "Swiften/Elements/Presence.h"
|
2016-09-12 18:20:58 +02:00
|
|
|
#include "Swiften/SwiftenCompat.h"
|
2011-04-01 23:54:29 +02:00
|
|
|
|
|
|
|
namespace Transport {
|
|
|
|
|
|
|
|
class ConversationManager;
|
|
|
|
|
2011-06-06 10:48:27 +02:00
|
|
|
/// Represents one XMPP-Legacy network conversation.
|
2011-04-03 11:39:06 +02:00
|
|
|
class Conversation {
|
2011-04-01 23:54:29 +02:00
|
|
|
public:
|
2013-01-23 19:41:56 +01:00
|
|
|
typedef enum {
|
|
|
|
PARTICIPANT_FLAG_NONE = 0,
|
|
|
|
PARTICIPANT_FLAG_MODERATOR = 1,
|
|
|
|
PARTICIPANT_FLAG_CONFLICT = 2,
|
|
|
|
PARTICIPANT_FLAG_BANNED = 4,
|
|
|
|
PARTICIPANT_FLAG_NOT_AUTHORIZED = 8,
|
|
|
|
PARTICIPANT_FLAG_ME = 16,
|
2013-02-12 09:30:24 +01:00
|
|
|
PARTICIPANT_FLAG_KICKED = 32,
|
|
|
|
PARTICIPANT_FLAG_ROOM_NOT_FOUD = 64
|
2013-01-23 19:41:56 +01:00
|
|
|
} ParticipantFlag;
|
|
|
|
|
2011-06-06 10:48:27 +02:00
|
|
|
/// Creates new conversation.
|
2011-04-01 23:54:29 +02:00
|
|
|
|
2011-06-06 10:48:27 +02:00
|
|
|
/// \param conversationManager ConversationManager associated with this Conversation.
|
|
|
|
/// \param legacyName Legacy network name of recipient.
|
|
|
|
/// \param muc True if this conversation is Multi-user chat.
|
|
|
|
Conversation(ConversationManager *conversationManager, const std::string &legacyName, bool muc = false);
|
|
|
|
|
|
|
|
/// Destructor.
|
2011-04-03 11:39:06 +02:00
|
|
|
virtual ~Conversation();
|
2011-04-01 23:54:29 +02:00
|
|
|
|
2011-06-06 10:48:27 +02:00
|
|
|
/// Returns legacy network name of this conversation.
|
|
|
|
|
|
|
|
/// \return legacy network name of this conversation.
|
2011-04-01 23:54:29 +02:00
|
|
|
const std::string &getLegacyName() { return m_legacyName; }
|
|
|
|
|
2011-06-06 10:48:27 +02:00
|
|
|
/// Handles new message from Legacy network and forwards it to XMPP.
|
|
|
|
|
|
|
|
/// \param message Message received from legacy network.
|
|
|
|
/// \param nickname For MUC conversation this is nickname of room participant who sent this message.
|
2016-09-12 18:20:58 +02:00
|
|
|
void handleMessage(SWIFTEN_SHRPTR_NAMESPACE::shared_ptr<Swift::Message> &message, const std::string &nickname = "");
|
2011-06-06 10:48:27 +02:00
|
|
|
|
2016-09-12 18:20:58 +02:00
|
|
|
void handleRawMessage(SWIFTEN_SHRPTR_NAMESPACE::shared_ptr<Swift::Message> &message);
|
2013-02-22 09:45:31 +01:00
|
|
|
void handleRawPresence(Swift::Presence::ref presence);
|
2013-02-09 11:09:38 +01:00
|
|
|
|
2011-06-06 10:48:27 +02:00
|
|
|
/// Handles participant change in MUC.
|
|
|
|
|
|
|
|
/// \param nickname Nickname of participant which changed.
|
|
|
|
/// \param flag ParticipantFlag.
|
|
|
|
/// \param status Current status of this participant.
|
|
|
|
/// \param statusMessage Current status message of this participant.
|
|
|
|
/// \param newname If participant was renamed, this variable contains his new name.
|
2016-02-08 09:26:34 +01:00
|
|
|
void handleParticipantChanged(const std::string &nickname, ParticipantFlag flag, int status = Swift::StatusShow::None, const std::string &statusMessage = "", const std::string &newname = "", const std::string &iconhash = "", const std::string &alias = "");
|
2011-06-06 10:48:27 +02:00
|
|
|
|
|
|
|
/// Sets XMPP user nickname in MUC rooms.
|
|
|
|
|
|
|
|
/// \param nickname XMPP user nickname in MUC rooms.
|
2013-02-26 15:31:21 +01:00
|
|
|
void setNickname(const std::string &nickname);
|
2011-04-01 23:54:29 +02:00
|
|
|
|
2011-11-24 12:24:26 +01:00
|
|
|
const std::string &getNickname() {
|
|
|
|
return m_nickname;
|
|
|
|
}
|
|
|
|
|
2011-11-11 11:40:10 +01:00
|
|
|
void setJID(const Swift::JID &jid) {
|
|
|
|
m_jid = jid;
|
|
|
|
}
|
|
|
|
|
2012-09-22 20:19:19 +02:00
|
|
|
void addJID(const Swift::JID &jid) {
|
|
|
|
m_jids.push_back(jid);
|
|
|
|
}
|
|
|
|
|
2012-12-21 09:26:34 +01:00
|
|
|
void clearJIDs() {
|
|
|
|
m_jids.clear();
|
|
|
|
}
|
|
|
|
|
2016-02-08 20:13:43 +01:00
|
|
|
void removeJID(const Swift::JID &jid);
|
2012-09-22 20:19:19 +02:00
|
|
|
|
|
|
|
const std::list<Swift::JID> &getJIDs() {
|
|
|
|
return m_jids;
|
|
|
|
}
|
|
|
|
|
2011-06-06 10:48:27 +02:00
|
|
|
/// Sends message to Legacy network.
|
|
|
|
|
|
|
|
/// \param message Message.
|
2016-09-12 18:20:58 +02:00
|
|
|
virtual void sendMessage(SWIFTEN_SHRPTR_NAMESPACE::shared_ptr<Swift::Message> &message) = 0;
|
2011-04-01 23:54:29 +02:00
|
|
|
|
2011-06-06 10:48:27 +02:00
|
|
|
/// Returns ConversationManager associated with this Conversation.
|
|
|
|
|
|
|
|
/// \return ConversationManager associated with this Conversation.
|
2011-05-14 15:31:29 +02:00
|
|
|
ConversationManager *getConversationManager() {
|
|
|
|
return m_conversationManager;
|
|
|
|
}
|
|
|
|
|
2011-06-06 10:48:27 +02:00
|
|
|
/// Returns True if this conversation is MUC room.
|
|
|
|
|
|
|
|
/// \return True if this conversation is MUC room.
|
2011-05-19 00:05:17 +02:00
|
|
|
bool isMUC() {
|
|
|
|
return m_muc;
|
|
|
|
}
|
|
|
|
|
2011-06-06 10:48:27 +02:00
|
|
|
/// Sets room name associated with this Conversation.
|
|
|
|
|
|
|
|
/// This is used to detect Private messages associated with particular room.
|
|
|
|
/// \param room room name associated with this Conversation.
|
2011-10-25 20:29:58 +02:00
|
|
|
void setRoom(const std::string &room);
|
2011-05-19 00:05:17 +02:00
|
|
|
|
2011-06-06 10:48:27 +02:00
|
|
|
/// Returns room name associated with this Conversation.
|
|
|
|
|
|
|
|
/// \return room name associated with this Conversation.
|
2011-05-19 00:05:17 +02:00
|
|
|
const std::string &getRoom() {
|
|
|
|
return m_room;
|
|
|
|
}
|
|
|
|
|
2012-09-21 13:56:17 +02:00
|
|
|
void destroyRoom();
|
|
|
|
|
2015-12-07 18:17:04 +01:00
|
|
|
std::string getParticipants();
|
2016-02-10 17:02:06 +01:00
|
|
|
void sendParticipants(const Swift::JID &to, const std::string &nickname);
|
2012-09-23 09:48:03 +02:00
|
|
|
|
2012-12-21 11:20:05 +01:00
|
|
|
void sendCachedMessages(const Swift::JID &to = Swift::JID());
|
2012-12-21 09:26:34 +01:00
|
|
|
|
2016-02-04 15:12:23 +01:00
|
|
|
void setMUCEscaping(bool mucEscaping);
|
|
|
|
|
2012-09-23 09:48:03 +02:00
|
|
|
private:
|
2016-02-06 15:50:53 +01:00
|
|
|
Swift::Presence::ref generatePresence(const std::string &nick, int flag, int status, const std::string &statusMessage, const std::string &newname = "", const std::string &iconhash = "");
|
2016-09-12 18:20:58 +02:00
|
|
|
void cacheMessage(SWIFTEN_SHRPTR_NAMESPACE::shared_ptr<Swift::Message> &message);
|
2012-09-23 09:48:03 +02:00
|
|
|
|
2011-04-01 23:54:29 +02:00
|
|
|
private:
|
|
|
|
ConversationManager *m_conversationManager;
|
|
|
|
std::string m_legacyName;
|
2011-05-17 09:44:29 +02:00
|
|
|
std::string m_nickname;
|
2011-05-19 00:05:17 +02:00
|
|
|
std::string m_room;
|
|
|
|
bool m_muc;
|
2011-11-11 11:40:10 +01:00
|
|
|
Swift::JID m_jid;
|
2012-09-22 20:19:19 +02:00
|
|
|
std::list<Swift::JID> m_jids;
|
2012-11-27 12:51:19 +01:00
|
|
|
bool m_sentInitialPresence;
|
2013-02-26 15:31:21 +01:00
|
|
|
bool m_nicknameChanged;
|
2016-02-04 15:12:23 +01:00
|
|
|
bool m_mucEscaping;
|
2016-02-10 17:02:06 +01:00
|
|
|
bool m_sentInitialSubject;
|
2013-02-22 09:45:31 +01:00
|
|
|
|
|
|
|
// TODO: Move this to some extra class to cache the most used
|
|
|
|
// rooms across different accounts. Just now if we have 10 users
|
|
|
|
// connected to single room, we store all those things 10 times.
|
|
|
|
// It would be also great to store last 100 messages per room
|
|
|
|
// every time, so we can get history messages for IRC for example.
|
2016-09-12 18:20:58 +02:00
|
|
|
SWIFTEN_SHRPTR_NAMESPACE::shared_ptr<Swift::Message> m_subject;
|
|
|
|
std::list<SWIFTEN_SHRPTR_NAMESPACE::shared_ptr<Swift::Message> > m_cachedMessages;
|
2016-02-08 09:26:34 +01:00
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
Swift::Presence::ref presence;
|
|
|
|
std::string alias;
|
|
|
|
} Participant;
|
|
|
|
std::map<std::string, Participant> m_participants;
|
2011-04-01 23:54:29 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|