Sort room directory by account, 'Category' column

The room directory window now has an accounts menu, to allow the user to
filter rooms by account― and a "category" column has been added, which can
optionally be filled by the protocol for more semantic sorting of rooms
(Through "category" slot of IM_ROOM_DIRECTORY).
This commit is contained in:
Jaidyn Ann 2021-08-31 20:31:39 -05:00
parent 8cb98ccf4b
commit 6a160ced88
5 changed files with 105 additions and 10 deletions

View File

@ -423,7 +423,8 @@ enum im_what_code {
copied and sent back verbatim (with im_what changed to IM_JOIN_ROOM)
to join.
Requires: Strings "chat_id"
Allows: String "chat_name", String "subject", int32 "user_count"*/
Allows: String "chat_name", String "subject", String "category",
int32 "user_count" */
IM_ROOM_DIRECTORY = 231,

View File

@ -18,11 +18,18 @@ RoomListRow::RoomListRow(BMessage* msg)
BString id = msg->FindString("chat_id");
BString name = msg->GetString("chat_name", id);
BString desc = msg->FindString("subject");
BString category = msg->FindString("category");
int32 user_n = msg->GetInt32("user_count", -1);
SetField(new BStringField(name), kNameColumn);
SetField(new BStringField(desc), kDescColumn);
SetField(new BStringField(id), kIdColumn);
SetField(new BStringField(category), kCatColumn);
if (user_n > -1)
SetField(new BIntegerField(user_n), kUserColumn);
}
RoomListRow::~RoomListRow()
{
delete fMessage;
}

View File

@ -11,7 +11,7 @@
enum {
kNameColumn,
kDescColumn,
kIdColumn,
kCatColumn,
kUserColumn
};
@ -19,6 +19,7 @@ enum {
class RoomListRow : public BRow {
public:
RoomListRow(BMessage* msg);
~RoomListRow();
BMessage* Message() { return fMessage; }
int64 Instance() { return fInstance; }

View File

@ -12,6 +12,7 @@
#include <LayoutBuilder.h>
#include <StringList.h>
#include "AccountsMenu.h"
#include "AppPreferences.h"
#include "ChatProtocolMessages.h"
#include "RoomListRow.h"
@ -22,6 +23,8 @@
#define B_TRANSLATION_CONTEXT "Room directory"
const uint32 kSelectAcc = 'rlse';
const uint32 kSelectAll = 'rlsa';
const uint32 kJoinRoom = 'join';
RoomListWindow* RoomListWindow::fInstance = NULL;
@ -31,7 +34,8 @@ RoomListWindow::RoomListWindow(Server* server)
BWindow(AppPreferences::Get()->RoomDirectoryRect,
B_TRANSLATE("Room directory"), B_FLOATING_WINDOW,
B_NOT_ZOOMABLE | B_AUTO_UPDATE_SIZE_LIMITS),
fServer(server)
fServer(server),
fAccount(-1)
{
_InitInterface();
CenterOnScreen();
@ -46,15 +50,21 @@ RoomListWindow::~RoomListWindow()
{
fInstance = NULL;
AppPreferences::Get()->RoomDirectoryRect = Bounds();
_EmptyList();
for (int i = 0; i < fRows.CountItems(); i++) {
BObjectList<RoomListRow>* list = fRows.ValueAt(i);
if (list != NULL)
delete list;
}
}
RoomListWindow*
RoomListWindow::Get(Server* server)
{
if (fInstance == NULL) {
if (fInstance == NULL)
fInstance = new RoomListWindow(server);
}
return fInstance;
}
@ -78,8 +88,55 @@ RoomListWindow::MessageReceived(BMessage* msg)
int64 instance;
BString id;
if (msg->FindInt64("instance", &instance) == B_OK
&& msg->FindString("chat_id", &id) == B_OK)
fListView->AddRow(new RoomListRow(msg));
&& msg->FindString("chat_id", &id) == B_OK) {
RoomListRow* row = new RoomListRow(msg);
bool fnd = false;
BObjectList<RoomListRow>* list = fRows.ValueFor(instance, &fnd);
if (fnd == false || list == NULL) {
list = new BObjectList<RoomListRow>(20, true);
fRows.AddItem(instance, list);
}
list->AddItem(row);
if (fAccount == -1 || instance == fAccount)
fListView->AddRow(row);
}
break;
}
case kSelectAll:
{
_EmptyList();
for (int i = 0; i < fRows.CountItems(); i++) {
BObjectList<RoomListRow>* list = fRows.ValueAt(i);
if (list != NULL)
for (int j = 0; j < list->CountItems(); j++) {
RoomListRow* row = list->ItemAt(j);
if (row != NULL)
fListView->AddRow(row);
}
}
fAccount = -1;
break;
}
case kSelectAcc:
{
msg->PrintToStream();
int64 instance;
if (msg->FindInt64("instance", &instance) == B_OK) {
bool fnd = false;
BObjectList<RoomListRow>* list = fRows.ValueFor(instance, &fnd);
if (fnd == false || list == NULL)
break;
_EmptyList();
for (int i = 0; i < list->CountItems(); i++) {
RoomListRow* row = list->ItemAt(i);
if (row != NULL)
fListView->AddRow(row);
}
fAccount = instance;
}
break;
}
case kJoinRoom:
@ -109,7 +166,8 @@ RoomListWindow::_InitInterface()
B_TRUNCATE_END);
BStringColumn* desc = new BStringColumn(B_TRANSLATE("Description"), 270,
50, 5000, B_TRUNCATE_END);
BStringColumn* id = new BStringColumn("ID", 90, 50, 300, B_TRUNCATE_END);
BStringColumn* category = new BStringColumn("Category", 90, 50, 300,
B_TRUNCATE_END);
BIntegerColumn* users = new BIntegerColumn("Users", 70, 10, 300);
fListView = new BColumnListView("roomList", B_NAVIGABLE, B_PLAIN_BORDER);
@ -117,9 +175,13 @@ RoomListWindow::_InitInterface()
fListView->SetSelectionMode(B_SINGLE_SELECTION_LIST);
fListView->AddColumn(name, kNameColumn);
fListView->AddColumn(desc, kDescColumn);
fListView->AddColumn(id, kIdColumn);
fListView->AddColumn(category, kCatColumn);
fListView->AddColumn(users, kUserColumn);
AccountsMenu* accsMenu = new AccountsMenu("accounts", BMessage(kSelectAcc),
new BMessage(kSelectAll), fServer);
BMenuField* accsField = new BMenuField(NULL, accsMenu);
fJoinButton = new BButton("joinRoom", B_TRANSLATE("Join"),
new BMessage(kJoinRoom));
@ -127,8 +189,20 @@ RoomListWindow::_InitInterface()
.SetInsets(B_USE_DEFAULT_SPACING)
.Add(fListView)
.AddGroup(B_HORIZONTAL)
.Add(accsField)
.AddGlue()
.Add(fJoinButton)
.End()
.End();
}
void
RoomListWindow::_EmptyList()
{
BRow* row = fListView->RowAt((int32)0, NULL);
while (row != NULL) {
fListView->RemoveRow(row);
row = fListView->RowAt((int32)0, NULL);
}
}

View File

@ -5,13 +5,20 @@
#ifndef _ROOM_LIST_WINDOW_H
#define _ROOM_LIST_WINDOW_H
#include <ObjectList.h>
#include <Window.h>
#include <libsupport/KeyMap.h>
class BButton;
class BColumnListView;
class RoomListRow;
class Server;
typedef KeyMap<int64, BObjectList<RoomListRow>*> RowMap;
class RoomListWindow : public BWindow {
public:
RoomListWindow(Server* server);
@ -25,9 +32,14 @@ public:
private:
void _InitInterface();
void _EmptyList();
BButton* fJoinButton;
BColumnListView* fListView;
RowMap fRows;
int64 fAccount;
Server* fServer;
static RoomListWindow* fInstance;
};