Recieve messages from MUC rooms

This commit is contained in:
Jaidyn Ann 2021-06-02 12:34:00 -05:00
parent 3f62492b9c
commit 061489ba2e
2 changed files with 32 additions and 5 deletions

View File

@ -136,10 +136,15 @@ JabberHandler::Process(BMessage* msg)
case IM_JOIN_ROOM: {
BString chat_id = msg->FindString("chat_id");
chat_id << "/" << fUsername;
BString join_id = chat_id;
join_id << "/" << fUsername;
gloox::MUCRoom room(fClient, gloox::JID(chat_id.String()), this, this);
room.join();
gloox::MUCRoom* room =
new gloox::MUCRoom(fClient, gloox::JID(join_id.String()),
this, this);
room->join();
fRooms.AddItem(chat_id, room);
break;
}
@ -1074,9 +1079,25 @@ JabberHandler::handleMUCParticipantPresence(gloox::MUCRoom *room,
void
JabberHandler::handleMUCMessage(gloox::MUCRoom *room, const gloox::Message &msg,
JabberHandler::handleMUCMessage(gloox::MUCRoom *room, const gloox::Message &m,
bool priv)
{
// We need a body
if (m.body() == "")
return;
BString chat_id(room->name().c_str());
chat_id << "@" << room->service().c_str();
// Notify that a chat message was received
BMessage msg(IM_MESSAGE);
msg.AddString("user_id", m.from().resource().c_str());
msg.AddString("chat_id", chat_id);
msg.AddInt32("im_what", IM_MESSAGE_RECEIVED);
if (m.subject() != "")
msg.AddString("subject", m.subject().c_str());
msg.AddString("body", m.body().c_str());
_SendMessage(&msg);
}

View File

@ -31,9 +31,14 @@
#include <CayaProtocol.h>
#include <CayaConstants.h>
#include <libsupport/KeyMap.h>
class BList;
typedef KeyMap<BString, gloox::MUCRoom*> RoomMap;
class JabberHandler : public CayaProtocol, gloox::RosterListener, gloox::ConnectionListener,
gloox::LogHandler, gloox::MessageSessionHandler,
gloox::MessageHandler, gloox::MessageEventHandler,
@ -100,6 +105,7 @@ private:
gloox::JID fJid;
thread_id fRecvThread;
RoomMap fRooms;
BPath fCachePath;
BPath fAvatarCachePath;
@ -136,7 +142,7 @@ private:
virtual void handleMUCParticipantPresence(gloox::MUCRoom* room,
const gloox::MUCRoomParticipant participant,
const gloox::Presence &presence);
virtual void handleMUCMessage(gloox::MUCRoom* room, const gloox::Message &msg, bool priv);
virtual void handleMUCMessage(gloox::MUCRoom* room, const gloox::Message &m, bool priv);
virtual bool handleMUCRoomCreation(gloox::MUCRoom* room);
virtual void handleMUCSubject(gloox::MUCRoom* room, const std::string &nick,
const std::string &subject);