diff --git a/application/NotifyMessage.h b/application/NotifyMessage.h index 99600e1..9e1f733 100644 --- a/application/NotifyMessage.h +++ b/application/NotifyMessage.h @@ -13,7 +13,8 @@ enum { PTR_AVATAR_BITMAP, INT_ACCOUNT_STATUS, - INT_CONTACT_STATUS + INT_CONTACT_STATUS, + INT_USER_PERMS }; #endif // _NOTIFY_MESSAGE_H diff --git a/application/Role.h b/application/Role.h index dff8732..6479e6d 100644 --- a/application/Role.h +++ b/application/Role.h @@ -14,16 +14,16 @@ // NSRBKDMNRW // 0000000000 -#define PERM_WRITE 0x01 -#define PERM_READ 0x02 -#define PERM_NICK 0x04 -#define PERM_MUTE 0x08 -#define PERM_DEAFEN 0x016 -#define PERM_KICK 0x032 -#define PERM_BAN 0x064 -#define PERM_ROLECHANGE 0x0128 -#define PERM_ROOM_SUBJECT 0x0256 -#define PERM_ROOM_NAME 0x0512 +#define PERM_WRITE 1 +#define PERM_READ 2 +#define PERM_NICK 4 +#define PERM_MUTE 8 +#define PERM_DEAFEN 16 +#define PERM_KICK 32 +#define PERM_BAN 64 +#define PERM_ROLECHANGE 128 +#define PERM_ROOM_SUBJECT 256 +#define PERM_ROOM_NAME 512 #define PERM_ALL 1023 @@ -34,14 +34,14 @@ public: { } - Role(BString title, uint32 perms, uint32 priority) + Role(BString title, int32 perms, int32 priority) : fTitle(title), fPerms(perms), fPriority(priority) { } BString fTitle; - uint32 fPerms; // Permissions afforded to role, as described above. - uint32 fPriority; // 'Rank' of role, with higher being greater priority. + int32 fPerms; // Permissions afforded to role, as described above. + int32 fPriority; // 'Rank' of role, with higher being greater priority. // I.E., a user with a priority of 11 can't kick a user // with a priority of 12, but can one with 10. // This sort of hierarchy might not be universal in diff --git a/application/Server.cpp b/application/Server.cpp index 85d64f3..4c9b348 100644 --- a/application/Server.cpp +++ b/application/Server.cpp @@ -653,12 +653,12 @@ Server::_GetRole(BMessage* msg) return NULL; BString title; - uint32 perms; - uint32 priority; + int32 perms; + int32 priority; if (msg->FindString("role_title", &title) != B_OK - || msg->FindUInt32("role_perms", &perms) != B_OK - || msg->FindUInt32("role_priority", &priority) != B_OK) + || msg->FindInt32("role_perms", &perms) != B_OK + || msg->FindInt32("role_priority", &priority) != B_OK) return NULL; return new Role(title, perms, priority); diff --git a/application/views/ConversationView.cpp b/application/views/ConversationView.cpp index deb7b1a..3d830f6 100644 --- a/application/views/ConversationView.cpp +++ b/application/views/ConversationView.cpp @@ -43,6 +43,7 @@ ConversationView::ConversationView(Conversation* chat) : ConversationView() { SetConversation(chat); + fUserList->SetConversation(chat); } diff --git a/application/views/UserListView.cpp b/application/views/UserListView.cpp index 0670cbe..767484c 100644 --- a/application/views/UserListView.cpp +++ b/application/views/UserListView.cpp @@ -10,17 +10,23 @@ #include #include "CayaMessages.h" +#include "Conversation.h" +#include "Role.h" #include "User.h" #include "UserInfoWindow.h" #include "UserItem.h" const uint32 kUserInfo = 'ULui'; -//const uint32 kLeaveSelectedChat = 'CVcs'; +const uint32 kDeafenUser = 'UMdu'; +const uint32 kMuteUser = 'UMmu'; +const uint32 kKickUser = 'UMku'; +const uint32 kBanUser = 'UMbu'; UserListView::UserListView(const char* name) - : BListView(name) + : BListView(name), + fChat(NULL) { } @@ -68,12 +74,38 @@ BPopUpMenu* UserListView::_UserPopUp() { BPopUpMenu* menu = new BPopUpMenu("userPopUp"); - menu->AddItem(new BMenuItem("User info…" B_UTF8_ELLIPSIS, + menu->AddItem(new BMenuItem("User info" B_UTF8_ELLIPSIS, new BMessage(kUserInfo))); menu->SetTargetForItems(this); - return menu; + // Now for the moderation items + Role* role = fChat->GetRole(fChat->OwnUserId()); + int32 perms = role->fPerms; + UserItem* item = (UserItem*)ItemAt(CurrentSelection()); + User* selected_user; + if (item == NULL || (selected_user = item->GetUser()) == NULL) + return menu; + + int32 selected_priority = fChat->GetRole(selected_user->GetId())->fPriority; + if (selected_priority > role->fPriority) + return menu; + + if ((perms & PERM_DEAFEN) || (perms & PERM_MUTE) || (perms & PERM_KICK) + || (perms & PERM_BAN)) + menu->AddSeparatorItem(); + + if (perms & PERM_DEAFEN) + menu->AddItem(new BMenuItem("Deafen user", new BMessage(kDeafenUser))); + if (perms & PERM_MUTE) + menu->AddItem(new BMenuItem("Mute user", new BMessage(kMuteUser))); + 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))); + + + return menu; } diff --git a/application/views/UserListView.h b/application/views/UserListView.h index ded9c48..01dc81d 100644 --- a/application/views/UserListView.h +++ b/application/views/UserListView.h @@ -8,6 +8,7 @@ #include class BPopUpMenu; +class Conversation; class UserListView : public BListView { @@ -18,9 +19,13 @@ public: void MouseDown(BPoint where); + void SetConversation(Conversation* chat) { fChat = chat; } + private: BPopUpMenu* _UserPopUp(); BPopUpMenu* _BlankPopUp(); + + Conversation* fChat; }; diff --git a/protocols/xmpp/JabberHandler.cpp b/protocols/xmpp/JabberHandler.cpp index c214025..3cc4ea0 100644 --- a/protocols/xmpp/JabberHandler.cpp +++ b/protocols/xmpp/JabberHandler.cpp @@ -913,7 +913,7 @@ JabberHandler::_RoleTitle(gloox::MUCRoomRole role, gloox::MUCRoomAffiliation aff } -uint32 +int32 JabberHandler::_RolePerms(gloox::MUCRoomRole role, gloox::MUCRoomAffiliation aff) { switch (role) @@ -931,7 +931,7 @@ JabberHandler::_RolePerms(gloox::MUCRoomRole role, gloox::MUCRoomAffiliation aff } -uint32 +int32 JabberHandler::_RolePriority(gloox::MUCRoomRole role, gloox::MUCRoomAffiliation aff) { switch (role) @@ -1249,8 +1249,8 @@ JabberHandler::_RoleChanged(BString chat_id, BString user_id, roleMsg.AddString("user_id", user_id); roleMsg.AddString("chat_id", chat_id); roleMsg.AddString("role_title", _RoleTitle(role, aff)); - roleMsg.AddUInt32("role_perms", _RolePerms(role, aff)); - roleMsg.AddUInt32("role_priority", _RolePriority(role, aff)); + roleMsg.AddInt32("role_perms", _RolePerms(role, aff)); + roleMsg.AddInt32("role_priority", _RolePriority(role, aff)); _SendMessage(&roleMsg); } diff --git a/protocols/xmpp/JabberHandler.h b/protocols/xmpp/JabberHandler.h index d3cd131..5d64d04 100644 --- a/protocols/xmpp/JabberHandler.h +++ b/protocols/xmpp/JabberHandler.h @@ -135,8 +135,8 @@ private: bool _MUCUserId(BString chat_id, const char* nick, BString* id); const char* _RoleTitle(gloox::MUCRoomRole role, gloox::MUCRoomAffiliation aff); - uint32 _RolePerms(gloox::MUCRoomRole role, gloox::MUCRoomAffiliation aff); - uint32 _RolePriority(gloox::MUCRoomRole role, gloox::MUCRoomAffiliation aff); + int32 _RolePerms(gloox::MUCRoomRole role, gloox::MUCRoomAffiliation aff); + int32 _RolePriority(gloox::MUCRoomRole role, gloox::MUCRoomAffiliation aff); virtual void onConnect(); virtual void onDisconnect(gloox::ConnectionError);