diff --git a/application/CayaProtocolMessages.h b/application/CayaProtocolMessages.h index 5c1c000..9cfd0b7 100644 --- a/application/CayaProtocolMessages.h +++ b/application/CayaProtocolMessages.h @@ -225,11 +225,26 @@ enum im_what_code { //! A user's role has been changed IM_ROOM_ROLECHANGE = 170, - //! Ban user - IM_ROOM_BAN_PARTICIPANT = 171, - //! Kick user - IM_ROOM_KICK_PARTICIPANT = 172, + IM_ROOM_KICK_PARTICIPANT = 171, + + //! Ban user + IM_ROOM_BAN_PARTICIPANT = 172, + + //! Unban user + IM_ROOM_UNBAN_PARTICIPANT = 173, + + //! Mute user + IM_ROOM_MUTE_PARTICIPANT = 174, + + //! Unmute user + IM_ROOM_UNMUTE_PARTICIPANT = 175, + + //! Deafen + IM_ROOM_DEAFEN_PARTICIPANT = 176, + + //! Allow to read messages + IM_ROOM_UNDEAFEN_PARTICIPANT = 177, /* diff --git a/application/views/UserListView.cpp b/application/views/UserListView.cpp index 767484c..2d85103 100644 --- a/application/views/UserListView.cpp +++ b/application/views/UserListView.cpp @@ -10,19 +10,15 @@ #include #include "CayaMessages.h" +#include "CayaProtocolMessages.h" #include "Conversation.h" +#include "ProtocolLooper.h" #include "Role.h" #include "User.h" #include "UserInfoWindow.h" #include "UserItem.h" -const uint32 kUserInfo = 'ULui'; -const uint32 kDeafenUser = 'UMdu'; -const uint32 kMuteUser = 'UMmu'; -const uint32 kKickUser = 'UMku'; -const uint32 kBanUser = 'UMbu'; - UserListView::UserListView(const char* name) : BListView(name), @@ -45,7 +41,24 @@ UserListView::MessageReceived(BMessage* msg) win->Show(); break; } - + case kKickUser: + _ModerationAction(IM_ROOM_KICK_PARTICIPANT); + break; + case kBanUser: + _ModerationAction(IM_ROOM_BAN_PARTICIPANT); + break; + case kMuteUser: + _ModerationAction(IM_ROOM_MUTE_PARTICIPANT); + break; + case kUnmuteUser: + _ModerationAction(IM_ROOM_UNMUTE_PARTICIPANT); + break; + case kDeafenUser: + _ModerationAction(IM_ROOM_DEAFEN_PARTICIPANT); + break; + case kUndeafenUser: + _ModerationAction(IM_ROOM_UNDEAFEN_PARTICIPANT); + break; default: BListView::MessageReceived(msg); } @@ -80,6 +93,7 @@ UserListView::_UserPopUp() // Now for the moderation items Role* role = fChat->GetRole(fChat->OwnUserId()); + if (role == NULL) return menu; int32 perms = role->fPerms; UserItem* item = (UserItem*)ItemAt(CurrentSelection()); User* selected_user; @@ -87,7 +101,10 @@ UserListView::_UserPopUp() if (item == NULL || (selected_user = item->GetUser()) == NULL) return menu; - int32 selected_priority = fChat->GetRole(selected_user->GetId())->fPriority; + Role* selected_role = fChat->GetRole(selected_user->GetId()); + if (selected_role == NULL) return menu; + int32 selected_priority = selected_role->fPriority; + int32 selected_perms = selected_role->fPerms; if (selected_priority > role->fPriority) return menu; @@ -95,16 +112,22 @@ UserListView::_UserPopUp() || (perms & PERM_BAN)) menu->AddSeparatorItem(); - if (perms & PERM_DEAFEN) + if ((perms & PERM_DEAFEN) && (selected_perms & PERM_READ)) menu->AddItem(new BMenuItem("Deafen user", new BMessage(kDeafenUser))); - if (perms & PERM_MUTE) + if ((perms & PERM_DEAFEN) && !(selected_perms & PERM_READ)) + menu->AddItem(new BMenuItem("Undeafen user", new BMessage(kUndeafenUser))); + + if ((perms & PERM_MUTE) && (selected_perms & PERM_WRITE)) menu->AddItem(new BMenuItem("Mute user", new BMessage(kMuteUser))); + if ((perms & PERM_MUTE) && !(selected_perms & PERM_WRITE)) + menu->AddItem(new BMenuItem("Unmute user", new BMessage(kUnmuteUser))); + if (perms & PERM_KICK) menu->AddItem(new BMenuItem("Kick user", new BMessage(kKickUser))); if (perms & PERM_BAN) menu->AddItem(new BMenuItem("Ban user", new BMessage(kBanUser))); - + menu->SetTargetForItems(this); return menu; } @@ -125,3 +148,20 @@ UserListView::_BlankPopUp() } +void +UserListView::_ModerationAction(int32 im_what) +{ + Role* role = fChat->GetRole(fChat->OwnUserId()); + int32 perms = role->fPerms; + UserItem* item = (UserItem*)ItemAt(CurrentSelection()); + if (item == NULL) + return; + + BMessage modMsg(IM_MESSAGE); + modMsg.AddInt32("im_what", im_what); + modMsg.AddString("user_id", item->GetUser()->GetId()); + modMsg.AddString("chat_id", fChat->GetId()); + fChat->GetProtocolLooper()->PostMessage(&modMsg); +} + + diff --git a/application/views/UserListView.h b/application/views/UserListView.h index 01dc81d..813e136 100644 --- a/application/views/UserListView.h +++ b/application/views/UserListView.h @@ -11,6 +11,18 @@ class BPopUpMenu; class Conversation; +enum +{ + kUserInfo = 'ULui', + kDeafenUser = 'UMdu', + kUndeafenUser = 'UMud', + kMuteUser = 'UMmu', + kUnmuteUser = 'UMum', + kKickUser = 'UMku', + kBanUser = 'UMbu' +}; + + class UserListView : public BListView { public: UserListView(const char* name); @@ -25,6 +37,8 @@ private: BPopUpMenu* _UserPopUp(); BPopUpMenu* _BlankPopUp(); + void _ModerationAction(int32 im_what); + Conversation* fChat; }; diff --git a/protocols/xmpp/JabberHandler.cpp b/protocols/xmpp/JabberHandler.cpp index eac5840..7dfd221 100644 --- a/protocols/xmpp/JabberHandler.cpp +++ b/protocols/xmpp/JabberHandler.cpp @@ -175,6 +175,14 @@ JabberHandler::Process(BMessage* msg) break; } + case IM_ROOM_KICK_PARTICIPANT: + case IM_ROOM_BAN_PARTICIPANT: + case IM_ROOM_UNBAN_PARTICIPANT: + case IM_ROOM_MUTE_PARTICIPANT: + case IM_ROOM_UNMUTE_PARTICIPANT: + _MUCModeration(msg); + break; + default: return B_ERROR; } @@ -895,6 +903,37 @@ JabberHandler::_MUCUserId(BString chat_id, const char* nick, BString* id) } +void +JabberHandler::_MUCModeration(BMessage* msg) +{ + BString chat_id = msg->FindString("chat_id"); + BString user_id; + BString body = msg->FindString("body"); + gloox::MUCRoom* room = fRooms.ValueFor(chat_id); + + if (room == NULL || msg->FindString("user_id", &user_id) != B_OK) + return; + + std::string nick = gloox::JID(user_id.String()).resource(); + + switch (msg->FindInt32("im_what")) + { + case IM_ROOM_KICK_PARTICIPANT: + room->kick(nick, body.String()); + break; + case IM_ROOM_BAN_PARTICIPANT: + room->ban(nick, body.String()); + break; + case IM_ROOM_MUTE_PARTICIPANT: + room->revokeVoice(nick, body.String()); + break; + case IM_ROOM_UNMUTE_PARTICIPANT: + room->grantVoice(nick, body.String()); + break; + } +} + + const char* JabberHandler::_RoleTitle(gloox::MUCRoomRole role, gloox::MUCRoomAffiliation aff) { @@ -922,10 +961,13 @@ JabberHandler::_RolePerms(gloox::MUCRoomRole role, gloox::MUCRoomAffiliation aff return 0 | PERM_READ | PERM_NICK; case gloox::RoleParticipant: return 0 | PERM_READ | PERM_WRITE | PERM_ROOM_SUBJECT; - case gloox::RoleModerator: + case gloox::RoleModerator: { + int32 perm = 0 | PERM_READ | PERM_WRITE | PERM_ROOM_SUBJECT + | PERM_KICK | PERM_MUTE; if (aff == gloox::AffiliationOwner) - return PERM_ALL; - return PERM_ALL; + perm = perm | PERM_ROLECHANGE | PERM_BAN; + return perm; + } } return 0; } diff --git a/protocols/xmpp/JabberHandler.h b/protocols/xmpp/JabberHandler.h index 5d64d04..bb9b89c 100644 --- a/protocols/xmpp/JabberHandler.h +++ b/protocols/xmpp/JabberHandler.h @@ -133,6 +133,7 @@ private: BString _MUCChatId(gloox::MUCRoom* room); bool _MUCUserId(BString chat_id, const char* nick, BString* id); + void _MUCModeration(BMessage* msg); const char* _RoleTitle(gloox::MUCRoomRole role, gloox::MUCRoomAffiliation aff); int32 _RolePerms(gloox::MUCRoomRole role, gloox::MUCRoomAffiliation aff);