Jabber support for receiving invitations
This commit is contained in:
parent
37512144a1
commit
3827787d38
|
@ -340,7 +340,6 @@ Server::ImMessage(BMessage* msg)
|
||||||
}
|
}
|
||||||
case IM_ROOM_INVITE_RECEIVED:
|
case IM_ROOM_INVITE_RECEIVED:
|
||||||
{
|
{
|
||||||
msg->PrintToStream();
|
|
||||||
BString chat_id;
|
BString chat_id;
|
||||||
User* user = _EnsureUser(msg);
|
User* user = _EnsureUser(msg);
|
||||||
BString user_id = msg->FindString("user_id");
|
BString user_id = msg->FindString("user_id");
|
||||||
|
@ -350,6 +349,7 @@ Server::ImMessage(BMessage* msg)
|
||||||
ProtocolLooper* looper = _LooperFromMessage(msg);
|
ProtocolLooper* looper = _LooperFromMessage(msg);
|
||||||
|
|
||||||
if (msg->FindString("chat_id", &chat_id) != B_OK || looper == NULL)
|
if (msg->FindString("chat_id", &chat_id) != B_OK || looper == NULL)
|
||||||
|
{
|
||||||
result = B_SKIP_MESSAGE;
|
result = B_SKIP_MESSAGE;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -370,9 +370,11 @@ Server::ImMessage(BMessage* msg)
|
||||||
alertBody.ReplaceAll("%room%", chat_name);
|
alertBody.ReplaceAll("%room%", chat_name);
|
||||||
alertBody.ReplaceAll("%body%", body);
|
alertBody.ReplaceAll("%body%", body);
|
||||||
|
|
||||||
BMessage* accept = new BMessage(IM_ROOM_INVITE_ACCEPT);
|
BMessage* accept = new BMessage(IM_MESSAGE);
|
||||||
|
accept->AddInt32("im_what", IM_ROOM_INVITE_ACCEPT);
|
||||||
accept->AddString("chat_id", chat_id);
|
accept->AddString("chat_id", chat_id);
|
||||||
BMessage* reject = new BMessage(IM_ROOM_INVITE_REFUSE);
|
BMessage* reject = new BMessage(IM_MESSAGE);
|
||||||
|
accept->AddInt32("im_what", IM_ROOM_INVITE_REFUSE);
|
||||||
reject->AddString("chat_id", chat_id);
|
reject->AddString("chat_id", chat_id);
|
||||||
|
|
||||||
InviteDialogue* invite = new InviteDialogue(BMessenger(looper),
|
InviteDialogue* invite = new InviteDialogue(BMessenger(looper),
|
||||||
|
|
|
@ -30,7 +30,6 @@ InviteDialogue::MessageReceived(BMessage* msg)
|
||||||
BAlert::MessageReceived(msg);
|
BAlert::MessageReceived(msg);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
msg->PrintToStream();
|
|
||||||
|
|
||||||
switch (which)
|
switch (which)
|
||||||
{
|
{
|
||||||
|
|
|
@ -145,17 +145,10 @@ JabberHandler::Process(BMessage* msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
case IM_JOIN_ROOM: {
|
case IM_JOIN_ROOM: {
|
||||||
BString chat_id = msg->FindString("chat_id");
|
BString chat_id;
|
||||||
BString join_id = chat_id;
|
if (msg->FindString("chat_id", &chat_id) == B_OK)
|
||||||
join_id << "/" << fNick;
|
_JoinRoom(chat_id.String());
|
||||||
|
|
||||||
gloox::MUCRoom* room =
|
|
||||||
new gloox::MUCRoom(fClient, gloox::JID(join_id.String()),
|
|
||||||
this, this);
|
|
||||||
room->join();
|
|
||||||
room->getRoomItems();
|
|
||||||
|
|
||||||
fRooms.AddItem(chat_id, room);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -175,6 +168,19 @@ JabberHandler::Process(BMessage* msg)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case IM_ROOM_INVITE_ACCEPT: {
|
||||||
|
BString chat_id;
|
||||||
|
if (msg->FindString("chat_id", &chat_id) != B_OK)
|
||||||
|
break;
|
||||||
|
|
||||||
|
BStringList splitAtPassword;
|
||||||
|
chat_id.Split("#", false, splitAtPassword);
|
||||||
|
chat_id = splitAtPassword.StringAt(0);
|
||||||
|
|
||||||
|
_JoinRoom(chat_id.String());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
case IM_ROOM_KICK_PARTICIPANT:
|
case IM_ROOM_KICK_PARTICIPANT:
|
||||||
case IM_ROOM_BAN_PARTICIPANT:
|
case IM_ROOM_BAN_PARTICIPANT:
|
||||||
case IM_ROOM_UNBAN_PARTICIPANT:
|
case IM_ROOM_UNBAN_PARTICIPANT:
|
||||||
|
@ -268,6 +274,7 @@ JabberHandler::UpdateSettings(BMessage* msg)
|
||||||
fClient->setPort(fPort);
|
fClient->setPort(fPort);
|
||||||
fClient->registerConnectionListener(this);
|
fClient->registerConnectionListener(this);
|
||||||
fClient->registerMessageSessionHandler(this);
|
fClient->registerMessageSessionHandler(this);
|
||||||
|
fClient->registerMUCInvitationHandler(new InviteHandler(fClient, this));
|
||||||
fClient->rosterManager()->registerRosterListener(this);
|
fClient->rosterManager()->registerRosterListener(this);
|
||||||
fClient->disco()->setVersion("Caya", VERSION);
|
fClient->disco()->setVersion("Caya", VERSION);
|
||||||
fClient->disco()->setIdentity("client", "caya");
|
fClient->disco()->setIdentity("client", "caya");
|
||||||
|
@ -773,8 +780,6 @@ JabberHandler::_StatusSetMsg(const char* user_id, gloox::Presence::PresenceType
|
||||||
if (BString(message).IsEmpty() == false)
|
if (BString(message).IsEmpty() == false)
|
||||||
msg.AddString("message", message);
|
msg.AddString("message", message);
|
||||||
|
|
||||||
msg.PrintToStream();
|
|
||||||
|
|
||||||
_SendMessage(&msg);
|
_SendMessage(&msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -967,6 +972,23 @@ JabberHandler::_MUCUserId(BString chat_id, const char* nick, BString* id)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
JabberHandler::_JoinRoom(const char* chat_id)
|
||||||
|
{
|
||||||
|
BString join_id(chat_id);
|
||||||
|
join_id << "/" << fNick;
|
||||||
|
|
||||||
|
gloox::MUCRoom* room = fRooms.ValueFor(chat_id);
|
||||||
|
if (room == NULL)
|
||||||
|
room = new gloox::MUCRoom(fClient, gloox::JID(join_id.String()), this, this);
|
||||||
|
|
||||||
|
room->join();
|
||||||
|
room->getRoomItems();
|
||||||
|
|
||||||
|
fRooms.AddItem(BString(chat_id), room);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
JabberHandler::_MUCModeration(BMessage* msg)
|
JabberHandler::_MUCModeration(BMessage* msg)
|
||||||
{
|
{
|
||||||
|
@ -1486,6 +1508,8 @@ JabberHandler::handleMUCRequest(gloox::MUCRoom* room, const gloox::DataForm &for
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
JabberHandler::handleItemAdded(const gloox::JID&)
|
JabberHandler::handleItemAdded(const gloox::JID&)
|
||||||
{
|
{
|
||||||
|
@ -1634,3 +1658,40 @@ JabberHandler::handleVCardResult(gloox::VCardHandler::VCardContext context,
|
||||||
//if (context == gloox::VCardHandler::FetchVCard)
|
//if (context == gloox::VCardHandler::FetchVCard)
|
||||||
//else
|
//else
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
InviteHandler::InviteHandler(gloox::ClientBase* client, JabberHandler* handler)
|
||||||
|
:
|
||||||
|
gloox::MUCInvitationHandler(client),
|
||||||
|
fHandler(handler)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
InviteHandler::handleMUCInvitation(const gloox::JID& room, const gloox::JID& from,
|
||||||
|
const std::string& reason, const std::string& body,
|
||||||
|
const std::string& password, bool cont,
|
||||||
|
const std::string& thread)
|
||||||
|
{
|
||||||
|
std::string chat_name = room.resource().c_str();
|
||||||
|
BString chat_id = room.full().c_str();
|
||||||
|
|
||||||
|
if (chat_name.empty() == true)
|
||||||
|
chat_name = chat_id.String();
|
||||||
|
if (password.empty() == false)
|
||||||
|
chat_id << "#" << password.c_str();
|
||||||
|
|
||||||
|
BMessage invite(IM_MESSAGE);
|
||||||
|
invite.AddInt32("im_what", IM_ROOM_INVITE_RECEIVED);
|
||||||
|
invite.AddString("chat_id", chat_id);
|
||||||
|
invite.AddString("chat_name", chat_name.c_str());
|
||||||
|
invite.AddString("user_id", from.bare().c_str());
|
||||||
|
if (reason.empty() == false)
|
||||||
|
invite.AddString("body", reason.c_str());
|
||||||
|
invite.AddString("protocol", fHandler->Signature());
|
||||||
|
|
||||||
|
fHandler->MessengerInterface()->SendMessage(new BMessage(invite));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -19,12 +19,13 @@
|
||||||
#include <gloox/loghandler.h>
|
#include <gloox/loghandler.h>
|
||||||
#include <gloox/logsink.h>
|
#include <gloox/logsink.h>
|
||||||
#include <gloox/message.h>
|
#include <gloox/message.h>
|
||||||
|
#include <gloox/messageeventhandler.h>
|
||||||
#include <gloox/messagehandler.h>
|
#include <gloox/messagehandler.h>
|
||||||
#include <gloox/messagesession.h>
|
#include <gloox/messagesession.h>
|
||||||
#include <gloox/messagesessionhandler.h>
|
#include <gloox/messagesessionhandler.h>
|
||||||
#include <gloox/messageeventhandler.h>
|
#include <gloox/mucinvitationhandler.h>
|
||||||
#include <gloox/mucroomhandler.h>
|
|
||||||
#include <gloox/mucroomconfighandler.h>
|
#include <gloox/mucroomconfighandler.h>
|
||||||
|
#include <gloox/mucroomhandler.h>
|
||||||
#include <gloox/presence.h>
|
#include <gloox/presence.h>
|
||||||
#include <gloox/vcardhandler.h>
|
#include <gloox/vcardhandler.h>
|
||||||
#include <gloox/vcardmanager.h>
|
#include <gloox/vcardmanager.h>
|
||||||
|
@ -34,6 +35,7 @@
|
||||||
#include <libsupport/KeyMap.h>
|
#include <libsupport/KeyMap.h>
|
||||||
|
|
||||||
class BList;
|
class BList;
|
||||||
|
class InviteHandler;
|
||||||
|
|
||||||
|
|
||||||
typedef KeyMap<BString, gloox::MUCRoom*> RoomMap;
|
typedef KeyMap<BString, gloox::MUCRoom*> RoomMap;
|
||||||
|
@ -103,6 +105,7 @@ private:
|
||||||
fConnection;
|
fConnection;
|
||||||
gloox::VCardManager* fVCardManager;
|
gloox::VCardManager* fVCardManager;
|
||||||
gloox::MessageSession* fSession;
|
gloox::MessageSession* fSession;
|
||||||
|
InviteHandler* fInviteHandler;
|
||||||
|
|
||||||
gloox::JID fJid;
|
gloox::JID fJid;
|
||||||
thread_id fRecvThread;
|
thread_id fRecvThread;
|
||||||
|
@ -116,6 +119,7 @@ private:
|
||||||
void _SendMessage(BMessage* msg);
|
void _SendMessage(BMessage* msg);
|
||||||
void _MessageSent(const char* id, const char* subject,
|
void _MessageSent(const char* id, const char* subject,
|
||||||
const char* body);
|
const char* body);
|
||||||
|
void _JoinRoom(const char* chat_id);
|
||||||
|
|
||||||
void _ChatCreatedMsg(const char* id);
|
void _ChatCreatedMsg(const char* id);
|
||||||
void _RoleChangedMsg(BString chat_id, BString user_id,
|
void _RoleChangedMsg(BString chat_id, BString user_id,
|
||||||
|
@ -194,4 +198,18 @@ private:
|
||||||
const gloox::JID&, gloox::StanzaError);
|
const gloox::JID&, gloox::StanzaError);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
class InviteHandler : public gloox::MUCInvitationHandler {
|
||||||
|
public:
|
||||||
|
InviteHandler(gloox::ClientBase* parent, JabberHandler* handler);
|
||||||
|
void handleMUCInvitation(const gloox::JID& room, const gloox::JID& from,
|
||||||
|
const std::string& reason, const std::string& body,
|
||||||
|
const std::string& password, bool cont,
|
||||||
|
const std::string& thread);
|
||||||
|
private:
|
||||||
|
JabberHandler* fHandler;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
#endif // _JABBER_HANDLER_H
|
#endif // _JABBER_HANDLER_H
|
||||||
|
|
||||||
|
|
Ŝarĝante…
Reference in New Issue