2021-05-27 11:15:30 -05:00
|
|
|
/*
|
|
|
|
* Copyright 2021, Jaidyn Levesque <jadedctrl@teknik.io>
|
|
|
|
* All rights reserved. Distributed under the terms of the MIT license.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "ConversationListView.h"
|
|
|
|
|
|
|
|
#include <PopUpMenu.h>
|
|
|
|
#include <MenuItem.h>
|
|
|
|
#include <Window.h>
|
|
|
|
|
|
|
|
#include "CayaMessages.h"
|
2021-06-04 16:32:18 -05:00
|
|
|
#include "CayaProtocolMessages.h"
|
2021-05-27 11:15:30 -05:00
|
|
|
#include "Conversation.h"
|
|
|
|
#include "ConversationItem.h"
|
2021-06-04 16:32:18 -05:00
|
|
|
#include "ProtocolLooper.h"
|
2021-05-27 11:15:30 -05:00
|
|
|
|
|
|
|
|
|
|
|
const uint32 kOpenSelectedChat = 'CVos';
|
|
|
|
const uint32 kLeaveSelectedChat = 'CVcs';
|
|
|
|
|
|
|
|
|
|
|
|
ConversationListView::ConversationListView(const char* name)
|
2021-05-30 12:30:26 -05:00
|
|
|
: BListView(name)
|
2021-05-27 11:15:30 -05:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
ConversationListView::MessageReceived(BMessage* msg)
|
|
|
|
{
|
|
|
|
switch (msg->what) {
|
|
|
|
case kOpenSelectedChat:
|
|
|
|
{
|
|
|
|
ConversationItem* item;
|
|
|
|
int32 selIndex = CurrentSelection();
|
|
|
|
|
|
|
|
if ((item = (ConversationItem*)ItemAt(selIndex)) != NULL)
|
2021-05-28 22:26:32 -05:00
|
|
|
item->GetConversation()->ShowView(false, true);
|
2021-05-27 11:15:30 -05:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2021-06-04 16:32:18 -05:00
|
|
|
case kLeaveSelectedChat:
|
|
|
|
{
|
|
|
|
ConversationItem* item;
|
|
|
|
int32 selIndex = CurrentSelection();
|
|
|
|
|
|
|
|
if ((item = (ConversationItem*)ItemAt(selIndex)) == NULL)
|
|
|
|
break;
|
|
|
|
|
|
|
|
BMessage leave(IM_MESSAGE);
|
|
|
|
leave.AddInt32("im_what", IM_LEAVE_ROOM);
|
|
|
|
leave.AddString("chat_id", item->GetConversation()->GetId());
|
|
|
|
item->GetConversation()->GetProtocolLooper()->MessageReceived(&leave);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2021-05-27 11:15:30 -05:00
|
|
|
default:
|
2021-05-30 12:30:26 -05:00
|
|
|
BListView::MessageReceived(msg);
|
2021-05-27 11:15:30 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
ConversationListView::MouseDown(BPoint where)
|
|
|
|
{
|
2021-06-03 23:39:20 -05:00
|
|
|
int32 selection = CurrentSelection();
|
|
|
|
|
2021-05-27 11:15:30 -05:00
|
|
|
BListView::MouseDown(where);
|
|
|
|
|
2021-06-03 23:39:20 -05:00
|
|
|
// Don't allow deselcting a room
|
|
|
|
if (CurrentSelection() < 0 && selection >= 0)
|
|
|
|
Select(selection);
|
|
|
|
|
2021-05-27 11:15:30 -05:00
|
|
|
uint32 buttons = 0;
|
|
|
|
Window()->CurrentMessage()->FindInt32("buttons", (int32*)&buttons);
|
|
|
|
|
|
|
|
if (!(buttons & B_SECONDARY_MOUSE_BUTTON))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (CurrentSelection() >= 0)
|
|
|
|
_ConversationPopUp()->Go(ConvertToScreen(where), true, false);
|
|
|
|
else
|
|
|
|
_BlankPopUp()->Go(ConvertToScreen(where), true, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-05-30 20:45:24 -05:00
|
|
|
void
|
|
|
|
ConversationListView::SelectionChanged()
|
|
|
|
{
|
|
|
|
MessageReceived(new BMessage(kOpenSelectedChat));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-05-27 11:15:30 -05:00
|
|
|
BPopUpMenu*
|
|
|
|
ConversationListView::_ConversationPopUp()
|
|
|
|
{
|
|
|
|
BPopUpMenu* menu = new BPopUpMenu("chatPopUp");
|
2021-05-30 12:30:26 -05:00
|
|
|
menu->AddItem(new BMenuItem("Open chat" B_UTF8_ELLIPSIS,
|
|
|
|
new BMessage(kOpenSelectedChat)));
|
2021-05-27 11:15:30 -05:00
|
|
|
menu->AddItem(new BMenuItem("Leave chat", new BMessage(kLeaveSelectedChat)));
|
|
|
|
menu->SetTargetForItems(this);
|
|
|
|
|
|
|
|
return menu;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
BPopUpMenu*
|
|
|
|
ConversationListView::_BlankPopUp()
|
|
|
|
{
|
|
|
|
BPopUpMenu* menu = new BPopUpMenu("blankPopUp");
|
|
|
|
menu->AddItem(new BMenuItem("New chat" B_UTF8_ELLIPSIS,
|
2021-05-31 10:50:43 -05:00
|
|
|
new BMessage(CAYA_NEW_CHAT), 'M', B_COMMAND_KEY));
|
2021-05-27 11:15:30 -05:00
|
|
|
menu->SetTargetForItems(Window());
|
|
|
|
|
|
|
|
return menu;
|
|
|
|
}
|
|
|
|
|
|
|
|
|