Editing of roster members

Roster members' can now be edited (through Roster->Edit Roster / CMD+R)

TemplateWindows can now be populated through sending any IM_MESSAGE to
it (it will assume the slots of the message correspond to the
template's).

IM_CONTACT_LIST_ADDED_CONTACT was removed (for redundancy), and
IM_CONTACT_LIST_EDIT_CONTACT was added.
This commit is contained in:
Jaidyn Ann 2021-06-19 22:03:02 -05:00
parent b1254494cb
commit a21c8f7601
6 changed files with 125 additions and 26 deletions

View File

@ -41,14 +41,18 @@ enum im_what_code {
// "roster" template (CayaProtocol::SettingsTemplate("roster")) // "roster" template (CayaProtocol::SettingsTemplate("roster"))
IM_CONTACT_LIST_ADD_CONTACT = 3, IM_CONTACT_LIST_ADD_CONTACT = 3,
//! Someone has been added →Caya //! Remove a contact →Protocol
// Requires: String "user_id" // Requires: String "user_id"
// Allows: String "user_name" IM_CONTACT_LIST_REMOVE_CONTACT = 4,
IM_CONTACT_LIST_CONTACT_ADDED = 4,
//! Contact(s) removed from the server-side list →Caya //! Contact(s) removed from the server-side list →Caya
// Requires: String "user_id" // Requires: String "user_id"
IM_CONTACT_LIST_REMOVED_CONTACT = 4, IM_CONTACT_LIST_REMOVED_CONTACT = 5,
//! Edit some data on contact →Protocol
// The slots for this message are determined by the protocol's
// "roster" template (CayaProtocol::SettingsTemplate("roster"))
IM_CONTACT_LIST_EDIT_CONTACT = 6,
/* /*

View File

@ -46,7 +46,6 @@ MainWindow::MainWindow()
fWorkspaceChanged(false), fWorkspaceChanged(false),
fConversation(NULL), fConversation(NULL),
fRosterWindow(NULL), fRosterWindow(NULL),
fRosterEditWindow(NULL),
fServer(NULL) fServer(NULL)
{ {
_InitInterface(); _InitInterface();
@ -173,8 +172,7 @@ MainWindow::MessageReceived(BMessage* message)
} }
case CAYA_EDIT_ROSTER: case CAYA_EDIT_ROSTER:
{ {
fRosterEditWindow = new RosterEditWindow(fServer); RosterEditWindow::Get(fServer)->Show();
fRosterEditWindow->Show();
break; break;
} }
case CAYA_MOVE_UP: case CAYA_MOVE_UP:
@ -292,8 +290,8 @@ MainWindow::ImMessage(BMessage* msg)
case IM_STATUS_SET: case IM_STATUS_SET:
if (fRosterWindow != NULL) if (fRosterWindow != NULL)
fRosterWindow->PostMessage(msg); fRosterWindow->PostMessage(msg);
if (fRosterEditWindow != NULL) if (RosterEditWindow::Check() == true)
fRosterEditWindow->PostMessage(msg); RosterEditWindow::Get(fServer)->PostMessage(msg);
break; break;
case IM_PROTOCOL_READY: case IM_PROTOCOL_READY:

View File

@ -36,12 +36,15 @@ const uint32 kEditMember = 'RWEM';
const uint32 kSelAccount = 'RWSA'; const uint32 kSelAccount = 'RWSA';
const uint32 kSelNoAccount = 'RWNA'; const uint32 kSelNoAccount = 'RWNA';
RosterEditWindow* RosterEditWindow::fInstance = NULL;
RosterEditWindow::RosterEditWindow(Server* server) RosterEditWindow::RosterEditWindow(Server* server)
: :
BWindow(BRect(0, 0, 300, 400), "Roster", B_FLOATING_WINDOW, 0), BWindow(BRect(0, 0, 300, 400), "Roster", B_FLOATING_WINDOW, 0),
fAccounts(server->GetAccounts()), fAccounts(server->GetAccounts()),
fServer(server) fServer(server),
fEditingWindow(NULL)
{ {
fRosterView = new RosterView("buddyView", server); fRosterView = new RosterView("buddyView", server);
fRosterView->SetInvocationMessage(new BMessage(kEditMember)); fRosterView->SetInvocationMessage(new BMessage(kEditMember));
@ -85,22 +88,69 @@ RosterEditWindow::RosterEditWindow(Server* server)
} }
RosterEditWindow::~RosterEditWindow()
{
fInstance = NULL;
}
RosterEditWindow*
RosterEditWindow::Get(Server* server)
{
if (fInstance == NULL) {
fInstance = new RosterEditWindow(server);
}
return fInstance;
}
bool
RosterEditWindow::Check()
{
return (fInstance != NULL);
}
void void
RosterEditWindow::MessageReceived(BMessage* message) RosterEditWindow::MessageReceived(BMessage* message)
{ {
switch (message->what) { switch (message->what) {
case kEditMember: case kEditMember:
{ {
if (fEditingWindow != NULL && fEditingWindow->Lock()) {
fEditingWindow->Quit();
fEditingUser.SetTo("");
}
int index = message->FindInt32("index"); int index = message->FindInt32("index");
RosterItem* ritem = fRosterView->ListView()->RosterItemAt(index); RosterItem* ritem = fRosterView->ListView()->RosterItemAt(index);
if (ritem == NULL) if (ritem == NULL)
return; return;
User* user = ritem->GetContact();
TemplateWindow* win = User* user = ritem->GetContact();
new TemplateWindow("Editing contact", "roster", new BMessage(), fEditingUser.SetTo(user->GetId().String());
fServer, user->GetProtocolLooper()->GetInstance());
win->Show(); // The response IM_EXTENDED_CONTACT_INFO is used to populate the
// TemplateWindow.
BMessage* request = new BMessage(IM_MESSAGE);
request->AddInt32("im_what", IM_GET_EXTENDED_CONTACT_INFO);
request->AddString("user_id", user->GetId());
user->GetProtocolLooper()->PostMessage(request);
BMessage* edit = new BMessage(IM_MESSAGE);
edit->AddInt32("im_what", IM_CONTACT_LIST_EDIT_CONTACT);
fEditingWindow =
new TemplateWindow("Editing contact", "roster", edit, fServer,
user->GetProtocolLooper()->GetInstance());
fEditingWindow->Show();
break;
}
case IM_MESSAGE: {
if (message->GetInt32("im_what", 0) == IM_EXTENDED_CONTACT_INFO)
if (message->GetString("user_id", "") == fEditingUser)
fEditingWindow->PostMessage(message);
fRosterView->MessageReceived(message);
break; break;
} }
case kAddMember: case kAddMember:

View File

@ -19,6 +19,7 @@
class BMenuField; class BMenuField;
class RosterItem; class RosterItem;
class RosterView; class RosterView;
class TemplateWindow;
/* A window with the a list of the user's contacts, will send a message to /* A window with the a list of the user's contacts, will send a message to
@ -26,16 +27,24 @@ class RosterView;
class RosterEditWindow : public BWindow { class RosterEditWindow : public BWindow {
public: public:
RosterEditWindow(Server* server); RosterEditWindow(Server* server);
void MessageReceived(BMessage* message); ~RosterEditWindow();
static RosterEditWindow* Get(Server* server);
static bool Check();
void MessageReceived(BMessage* message);
void UpdateListItem(RosterItem* item); void UpdateListItem(RosterItem* item);
private: private:
BMenuField* fAccountField; BMenuField* fAccountField;
AccountInstances fAccounts; AccountInstances fAccounts;
BString fEditingUser;
TemplateWindow* fEditingWindow;
Server* fServer; Server* fServer;
RosterView* fRosterView; RosterView* fRosterView;
static RosterEditWindow* fInstance;
}; };
#endif // _ROSTER_EDIT_WINDOW_H #endif // _ROSTER_EDIT_WINDOW_H

View File

@ -17,6 +17,7 @@
#include <TextControl.h> #include <TextControl.h>
#include <String.h> #include <String.h>
#include "CayaProtocolMessages.h"
#include "CayaUtils.h" #include "CayaUtils.h"
#include "TemplateView.h" #include "TemplateView.h"
@ -69,12 +70,13 @@ void
TemplateWindow::MessageReceived(BMessage* msg) TemplateWindow::MessageReceived(BMessage* msg)
{ {
switch (msg->what) { switch (msg->what) {
case kAccSelected: case IM_MESSAGE: {
{ // If IM_MESSAGE, assume it should be treated as current settings
int32 index; if (fTemplate == NULL)
if (msg->FindInt32("index", &index) == B_OK) break;
fSelectedAcc = index; for (int i = 0; fTemplateView->CountChildren(); i++)
_LoadTemplate(); fTemplateView->RemoveChild(fTemplateView->ChildAt(i));
fTemplate->Load(fTemplateView, msg);
break; break;
} }
case kOK: { case kOK: {
@ -100,8 +102,14 @@ TemplateWindow::MessageReceived(BMessage* msg)
Close(); Close();
break; break;
} }
case kChanged: case kAccSelected:
{
int32 index;
if (msg->FindInt32("index", &index) == B_OK)
fSelectedAcc = index;
_LoadTemplate();
break; break;
}
default: default:
BWindow::MessageReceived(msg); BWindow::MessageReceived(msg);
} }

View File

@ -242,6 +242,13 @@ JabberHandler::Process(BMessage* msg)
_MUCModeration(msg); _MUCModeration(msg);
break; break;
case IM_GET_EXTENDED_CONTACT_INFO: {
BString user_id;
if (msg->FindString("user_id", &user_id) == B_OK)
fVCardManager->fetchVCard(gloox::JID(user_id.String()), this);
break;
}
case IM_CONTACT_LIST_ADD_CONTACT: { case IM_CONTACT_LIST_ADD_CONTACT: {
BString user_name = msg->FindString("user_name"); BString user_name = msg->FindString("user_name");
BString user_id; BString user_id;
@ -254,6 +261,24 @@ JabberHandler::Process(BMessage* msg)
fClient->rosterManager()->synchronize(); fClient->rosterManager()->synchronize();
break; break;
} }
case IM_CONTACT_LIST_EDIT_CONTACT: {
BString user_id;
BString user_name = msg->FindString("user_name");
if (msg->FindString("user_id", &user_id) != B_OK)
break;
gloox::JID jid(user_id.String());
gloox::RosterItem* item =
fClient->rosterManager()->getRosterItem(jid);
if (item != NULL && user_name.IsEmpty() == false) {
item->setName(user_name.String());
fClient->rosterManager()->synchronize();
}
break;
}
default: default:
return B_ERROR; return B_ERROR;
} }
@ -1761,13 +1786,18 @@ JabberHandler::handleVCard(const gloox::JID& jid, const gloox::VCard* card)
gloox::VCard::Name name = card->name(); gloox::VCard::Name name = card->name();
gloox::VCard::Photo photo = card->photo(); gloox::VCard::Photo photo = card->photo();
BString nick(card->nickname().c_str());
gloox::RosterItem* item = fClient->rosterManager()->getRosterItem(jid);
if (item != NULL)
nick = item->name().c_str();
std::string fullName = name.family + " " + name.given; std::string fullName = name.family + " " + name.given;
BMessage msg(IM_MESSAGE); BMessage msg(IM_MESSAGE);
msg.AddInt32("im_what", IM_EXTENDED_CONTACT_INFO); msg.AddInt32("im_what", IM_EXTENDED_CONTACT_INFO);
msg.AddString("user_id", jid.bare().c_str()); msg.AddString("user_id", jid.bare().c_str());
msg.AddString("user_name", card->nickname().c_str()); msg.AddString("user_name", nick);
msg.AddString("family_name", name.family.c_str()); msg.AddString("family_name", name.family.c_str());
msg.AddString("given_name", name.given.c_str()); msg.AddString("given_name", name.given.c_str());
msg.AddString("middle_name", name.middle.c_str()); msg.AddString("middle_name", name.middle.c_str());