2021-05-31 10:50:43 -05:00
|
|
|
/*
|
|
|
|
* Copyright 2021, Jaidyn Levesque <jadedctrl@teknik.io>
|
|
|
|
* All rights reserved. Distributed under the terms of the MIT license.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "UserListView.h"
|
|
|
|
|
|
|
|
#include <PopUpMenu.h>
|
|
|
|
#include <MenuItem.h>
|
|
|
|
#include <Window.h>
|
|
|
|
|
|
|
|
#include "CayaMessages.h"
|
2021-06-06 16:31:25 -05:00
|
|
|
#include "CayaProtocolMessages.h"
|
2021-06-06 01:49:11 -05:00
|
|
|
#include "Conversation.h"
|
2021-06-06 16:31:25 -05:00
|
|
|
#include "ProtocolLooper.h"
|
2021-06-06 01:49:11 -05:00
|
|
|
#include "Role.h"
|
2021-05-31 10:50:43 -05:00
|
|
|
#include "User.h"
|
|
|
|
#include "UserInfoWindow.h"
|
|
|
|
#include "UserItem.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
UserListView::UserListView(const char* name)
|
2021-06-06 01:49:11 -05:00
|
|
|
: BListView(name),
|
|
|
|
fChat(NULL)
|
2021-05-31 10:50:43 -05:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
UserListView::MessageReceived(BMessage* msg)
|
|
|
|
{
|
|
|
|
switch (msg->what) {
|
|
|
|
case kUserInfo:
|
|
|
|
{
|
|
|
|
UserItem* item = (UserItem*)ItemAt(CurrentSelection());
|
|
|
|
if (item == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
UserInfoWindow* win = new UserInfoWindow(item->GetUser());
|
|
|
|
win->Show();
|
|
|
|
break;
|
|
|
|
}
|
2021-06-06 16:31:25 -05:00
|
|
|
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;
|
2021-05-31 10:50:43 -05:00
|
|
|
default:
|
|
|
|
BListView::MessageReceived(msg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
UserListView::MouseDown(BPoint where)
|
|
|
|
{
|
|
|
|
BListView::MouseDown(where);
|
|
|
|
|
|
|
|
uint32 buttons = 0;
|
|
|
|
Window()->CurrentMessage()->FindInt32("buttons", (int32*)&buttons);
|
|
|
|
|
|
|
|
if (!(buttons & B_SECONDARY_MOUSE_BUTTON))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (CurrentSelection() >= 0)
|
|
|
|
_UserPopUp()->Go(ConvertToScreen(where), true, false);
|
|
|
|
else
|
|
|
|
_BlankPopUp()->Go(ConvertToScreen(where), true, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
BPopUpMenu*
|
|
|
|
UserListView::_UserPopUp()
|
|
|
|
{
|
|
|
|
BPopUpMenu* menu = new BPopUpMenu("userPopUp");
|
2021-06-06 01:49:11 -05:00
|
|
|
menu->AddItem(new BMenuItem("User info" B_UTF8_ELLIPSIS,
|
2021-05-31 10:50:43 -05:00
|
|
|
new BMessage(kUserInfo)));
|
|
|
|
menu->SetTargetForItems(this);
|
|
|
|
|
2021-06-06 01:49:11 -05:00
|
|
|
// Now for the moderation items
|
Explicitly tie Conversations, Contacts, and Users to their ProtocolLoopers
Previously, all Conversations/Contacts/Users were stored in the Server,
each in their respective KeyMaps, identified solely by their
identifiers. This leads to the glaring problem of overlap― if the user
has multiple accounts, some users/rooms might be used or present in multiple
accounts at the same time.
Now, each accounts' Contacts, Conversations, and Users are stored in
its ProtocolLooper, making this overlap impossible. An oversight of only
allowing one user identifier to be stored (fMySelf) in Server was also fixed
this way.
This is the bulk of the work required for multi-account support― now,
the user can join the same XMPP room on two seperate accounts, and it
works perfectly.
2021-06-10 15:16:43 -05:00
|
|
|
Role* role = fChat->GetRole(fChat->GetOwnId());
|
2021-06-06 16:31:25 -05:00
|
|
|
if (role == NULL) return menu;
|
2021-06-06 01:49:11 -05:00
|
|
|
int32 perms = role->fPerms;
|
|
|
|
UserItem* item = (UserItem*)ItemAt(CurrentSelection());
|
|
|
|
User* selected_user;
|
|
|
|
|
|
|
|
if (item == NULL || (selected_user = item->GetUser()) == NULL)
|
|
|
|
return menu;
|
|
|
|
|
2021-06-06 16:31:25 -05:00
|
|
|
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;
|
2021-06-06 01:49:11 -05:00
|
|
|
if (selected_priority > role->fPriority)
|
|
|
|
return menu;
|
|
|
|
|
|
|
|
if ((perms & PERM_DEAFEN) || (perms & PERM_MUTE) || (perms & PERM_KICK)
|
|
|
|
|| (perms & PERM_BAN))
|
|
|
|
menu->AddSeparatorItem();
|
2021-05-31 10:50:43 -05:00
|
|
|
|
2021-06-06 16:31:25 -05:00
|
|
|
if ((perms & PERM_DEAFEN) && (selected_perms & PERM_READ))
|
2021-06-06 01:49:11 -05:00
|
|
|
menu->AddItem(new BMenuItem("Deafen user", new BMessage(kDeafenUser)));
|
2021-06-06 16:31:25 -05:00
|
|
|
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))
|
2021-06-06 01:49:11 -05:00
|
|
|
menu->AddItem(new BMenuItem("Mute user", new BMessage(kMuteUser)));
|
2021-06-06 16:31:25 -05:00
|
|
|
if ((perms & PERM_MUTE) && !(selected_perms & PERM_WRITE))
|
|
|
|
menu->AddItem(new BMenuItem("Unmute user", new BMessage(kUnmuteUser)));
|
|
|
|
|
2021-06-06 01:49:11 -05:00
|
|
|
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)));
|
|
|
|
|
2021-06-06 16:31:25 -05:00
|
|
|
menu->SetTargetForItems(this);
|
2021-06-06 01:49:11 -05:00
|
|
|
return menu;
|
2021-05-31 10:50:43 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
BPopUpMenu*
|
|
|
|
UserListView::_BlankPopUp()
|
|
|
|
{
|
|
|
|
BPopUpMenu* menu = new BPopUpMenu("blankPopUp");
|
|
|
|
|
|
|
|
BMenuItem* invite = new BMenuItem("Invite user…" B_UTF8_ELLIPSIS,
|
|
|
|
new BMessage(CAYA_SEND_INVITE), 'I', B_COMMAND_KEY);
|
|
|
|
|
|
|
|
menu->AddItem(invite);
|
|
|
|
menu->SetTargetForItems(Window());
|
|
|
|
|
|
|
|
return menu;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-06 16:31:25 -05:00
|
|
|
void
|
|
|
|
UserListView::_ModerationAction(int32 im_what)
|
|
|
|
{
|
Explicitly tie Conversations, Contacts, and Users to their ProtocolLoopers
Previously, all Conversations/Contacts/Users were stored in the Server,
each in their respective KeyMaps, identified solely by their
identifiers. This leads to the glaring problem of overlap― if the user
has multiple accounts, some users/rooms might be used or present in multiple
accounts at the same time.
Now, each accounts' Contacts, Conversations, and Users are stored in
its ProtocolLooper, making this overlap impossible. An oversight of only
allowing one user identifier to be stored (fMySelf) in Server was also fixed
this way.
This is the bulk of the work required for multi-account support― now,
the user can join the same XMPP room on two seperate accounts, and it
works perfectly.
2021-06-10 15:16:43 -05:00
|
|
|
Role* role = fChat->GetRole(fChat->GetOwnId());
|
2021-06-06 16:31:25 -05:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
|