leaving the room works
This commit is contained in:
parent
6699a898fb
commit
2c526db0f3
7 changed files with 55 additions and 2 deletions
|
@ -56,6 +56,13 @@ class IRCNetworkPlugin : public NetworkPlugin {
|
|||
handleRoomChanged(user, room, m_sessions[user]->nick().toStdString());
|
||||
}
|
||||
|
||||
void handleLeaveRoomRequest(const std::string &user, const std::string &room) {
|
||||
std::cout << "PART\n";
|
||||
if (m_sessions[user] == NULL)
|
||||
return;
|
||||
m_sessions[user]->part(QString::fromStdString(room));
|
||||
}
|
||||
|
||||
std::map<std::string, MyIrcSession *> m_sessions;
|
||||
|
||||
private:
|
||||
|
|
|
@ -56,6 +56,7 @@ class NetworkPlugin {
|
|||
virtual void handleLogoutRequest(const std::string &user, const std::string &legacyName) = 0;
|
||||
virtual void handleMessageSendRequest(const std::string &user, const std::string &legacyName, const std::string &message) = 0;
|
||||
virtual void handleJoinRoomRequest(const std::string &/*user*/, const std::string &/*room*/, const std::string &/*nickname*/, const std::string &/*pasword*/) {}
|
||||
virtual void handleLeaveRoomRequest(const std::string &/*user*/, const std::string &/*room*/) {}
|
||||
|
||||
|
||||
private:
|
||||
|
@ -64,6 +65,7 @@ class NetworkPlugin {
|
|||
void handleLogoutPayload(const std::string &payload);
|
||||
void handleConvMessagePayload(const std::string &payload);
|
||||
void handleJoinRoomPayload(const std::string &payload);
|
||||
void handleLeaveRoomPayload(const std::string &payload);
|
||||
void handleDataRead(const Swift::ByteArray&);
|
||||
void handleConnected(bool error);
|
||||
void handleDisconnected();
|
||||
|
|
|
@ -60,6 +60,7 @@ class NetworkPluginServer {
|
|||
|
||||
void handleUserCreated(User *user);
|
||||
void handleRoomJoined(User *user, const std::string &room, const std::string &nickname, const std::string &password);
|
||||
void handleRoomLeft(User *user, const std::string &room);
|
||||
void handleUserReadyToConnect(User *user);
|
||||
void handleUserDestroyed(User *user);
|
||||
|
||||
|
|
|
@ -196,6 +196,16 @@ void NetworkPlugin::handleJoinRoomPayload(const std::string &data) {
|
|||
handleJoinRoomRequest(payload.username(), payload.room(), payload.nickname(), payload.password());
|
||||
}
|
||||
|
||||
void NetworkPlugin::handleLeaveRoomPayload(const std::string &data) {
|
||||
pbnetwork::Room payload;
|
||||
if (payload.ParseFromString(data) == false) {
|
||||
// TODO: ERROR
|
||||
return;
|
||||
}
|
||||
|
||||
handleLeaveRoomRequest(payload.username(), payload.room());
|
||||
}
|
||||
|
||||
void NetworkPlugin::handleDataRead(const Swift::ByteArray &data) {
|
||||
long expected_size = 0;
|
||||
m_data += data.toString();
|
||||
|
@ -236,6 +246,9 @@ void NetworkPlugin::handleDataRead(const Swift::ByteArray &data) {
|
|||
case pbnetwork::WrapperMessage_Type_TYPE_JOIN_ROOM:
|
||||
handleJoinRoomPayload(wrapper.payload());
|
||||
break;
|
||||
case pbnetwork::WrapperMessage_Type_TYPE_LEAVE_ROOM:
|
||||
handleLeaveRoomPayload(wrapper.payload());
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -342,6 +342,7 @@ void NetworkPluginServer::handleUserCreated(User *user) {
|
|||
// UserInfo userInfo = user->getUserInfo();
|
||||
user->onReadyToConnect.connect(boost::bind(&NetworkPluginServer::handleUserReadyToConnect, this, user));
|
||||
user->onRoomJoined.connect(boost::bind(&NetworkPluginServer::handleRoomJoined, this, user, _1, _2, _3));
|
||||
user->onRoomLeft.connect(boost::bind(&NetworkPluginServer::handleRoomLeft, this, user, _1));
|
||||
}
|
||||
|
||||
void NetworkPluginServer::handleUserReadyToConnect(User *user) {
|
||||
|
@ -381,6 +382,30 @@ void NetworkPluginServer::handleRoomJoined(User *user, const std::string &r, con
|
|||
conv->setNickname(nickname);
|
||||
}
|
||||
|
||||
void NetworkPluginServer::handleRoomLeft(User *user, const std::string &r) {
|
||||
UserInfo userInfo = user->getUserInfo();
|
||||
|
||||
pbnetwork::Room room;
|
||||
room.set_username(user->getJID().toBare());
|
||||
room.set_nickname("");
|
||||
room.set_room(r);
|
||||
room.set_password("");
|
||||
|
||||
std::string message;
|
||||
room.SerializeToString(&message);
|
||||
|
||||
WRAP(message, pbnetwork::WrapperMessage_Type_TYPE_LEAVE_ROOM);
|
||||
|
||||
send(m_client, message);
|
||||
|
||||
NetworkConversation *conv = (NetworkConversation *) user->getConversationManager()->getConversation(r);
|
||||
if (!conv) {
|
||||
return;
|
||||
}
|
||||
|
||||
delete conv;
|
||||
}
|
||||
|
||||
void NetworkPluginServer::handleUserDestroyed(User *user) {
|
||||
UserInfo userInfo = user->getUserInfo();
|
||||
|
||||
|
|
|
@ -65,7 +65,7 @@ message WrapperMessage {
|
|||
TYPE_PING = 9;
|
||||
TYPE_PONG = 10;
|
||||
TYPE_JOIN_ROOM = 11;
|
||||
TYPE_PART_ROOM = 12;
|
||||
TYPE_LEAVE_ROOM = 12;
|
||||
TYPE_PARTICIPANT_CHANGED = 13;
|
||||
TYPE_PARTICIPANT_LEFT = 14;
|
||||
TYPE_ROOM_NICKNAME_CHANGED = 15;
|
||||
|
|
|
@ -86,7 +86,12 @@ void User::handlePresence(Swift::Presence::ref presence) {
|
|||
bool isMUC = presence->getPayload<Swift::MUCPayload>() != NULL || *presence->getTo().getNode().c_str() == '#';
|
||||
if (isMUC) {
|
||||
std::cout << "AAAAAAAAA\n";
|
||||
onRoomJoined(presence->getTo().getNode(), presence->getTo().getResource(), "");
|
||||
if (presence->getType() == Swift::Presence::Unavailable) {
|
||||
onRoomLeft(presence->getTo().getNode());
|
||||
}
|
||||
else {
|
||||
onRoomJoined(presence->getTo().getNode(), presence->getTo().getResource(), "");
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue