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.
This commit is contained in:
parent
7767995400
commit
5b5840a79e
|
@ -267,9 +267,9 @@ Conversation::RemoveUser(User* user)
|
||||||
|
|
||||||
|
|
||||||
BString
|
BString
|
||||||
Conversation::OwnUserId()
|
Conversation::GetOwnId()
|
||||||
{
|
{
|
||||||
return _GetServer()->GetOwnContact();
|
return fLooper->GetOwnId();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -373,7 +373,7 @@ Conversation::_EnsureUser(BMessage* msg)
|
||||||
if (id.IsEmpty() == true) return NULL;
|
if (id.IsEmpty() == true) return NULL;
|
||||||
|
|
||||||
User* user = UserById(id);
|
User* user = UserById(id);
|
||||||
User* serverUser = _GetServer()->UserById(id);
|
User* serverUser = fLooper->UserById(id);
|
||||||
|
|
||||||
// Not here, but found in server
|
// Not here, but found in server
|
||||||
if (user == NULL && serverUser != NULL) {
|
if (user == NULL && serverUser != NULL) {
|
||||||
|
@ -383,10 +383,11 @@ Conversation::_EnsureUser(BMessage* msg)
|
||||||
}
|
}
|
||||||
// Not anywhere; create user
|
// Not anywhere; create user
|
||||||
else if (user == NULL) {
|
else if (user == NULL) {
|
||||||
user = new User(id, _GetServer()->Looper());
|
user = new User(id,
|
||||||
|
((TheApp*)be_app)->GetMainWindow()->GetServer()->Looper());
|
||||||
user->SetProtocolLooper(fLooper);
|
user->SetProtocolLooper(fLooper);
|
||||||
|
|
||||||
_GetServer()->AddUser(user);
|
fLooper->AddUser(user);
|
||||||
fUsers.AddItem(id, user);
|
fUsers.AddItem(id, user);
|
||||||
GetView()->UpdateUserList(fUsers);
|
GetView()->UpdateUserList(fUsers);
|
||||||
|
|
||||||
|
@ -398,10 +399,3 @@ Conversation::_EnsureUser(BMessage* msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Server*
|
|
||||||
Conversation::_GetServer()
|
|
||||||
{
|
|
||||||
return ((TheApp*)be_app)->GetMainWindow()->GetServer();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -59,7 +59,7 @@ public:
|
||||||
|
|
||||||
UserMap Users();
|
UserMap Users();
|
||||||
User* UserById(BString id);
|
User* UserById(BString id);
|
||||||
BString OwnUserId();
|
BString GetOwnId();
|
||||||
|
|
||||||
void AddUser(User* user);
|
void AddUser(User* user);
|
||||||
void RemoveUser(User* user);
|
void RemoveUser(User* user);
|
||||||
|
@ -73,7 +73,6 @@ private:
|
||||||
void _EnsureLogPath();
|
void _EnsureLogPath();
|
||||||
|
|
||||||
User* _EnsureUser(BMessage* msg);
|
User* _EnsureUser(BMessage* msg);
|
||||||
Server* _GetServer();
|
|
||||||
|
|
||||||
BMessenger fMessenger;
|
BMessenger fMessenger;
|
||||||
ProtocolLooper* fLooper;
|
ProtocolLooper* fLooper;
|
||||||
|
|
|
@ -53,7 +53,6 @@ SRCS = \
|
||||||
application/preferences/AccountView.cpp \
|
application/preferences/AccountView.cpp \
|
||||||
application/preferences/CayaPreferences.cpp \
|
application/preferences/CayaPreferences.cpp \
|
||||||
application/preferences/PreferencesChatWindow.cpp \
|
application/preferences/PreferencesChatWindow.cpp \
|
||||||
application/preferences/PreferencesDialog.cpp \
|
|
||||||
application/preferences/PreferencesAccounts.cpp \
|
application/preferences/PreferencesAccounts.cpp \
|
||||||
application/preferences/PreferencesBehavior.cpp \
|
application/preferences/PreferencesBehavior.cpp \
|
||||||
application/preferences/PreferencesReplicant.cpp \
|
application/preferences/PreferencesReplicant.cpp \
|
||||||
|
@ -76,6 +75,7 @@ SRCS = \
|
||||||
application/windows/AboutWindow.cpp \
|
application/windows/AboutWindow.cpp \
|
||||||
application/windows/JoinWindow.cpp \
|
application/windows/JoinWindow.cpp \
|
||||||
application/windows/MainWindow.cpp \
|
application/windows/MainWindow.cpp \
|
||||||
|
application/windows/PreferencesWindow.cpp \
|
||||||
application/windows/RosterWindow.cpp \
|
application/windows/RosterWindow.cpp \
|
||||||
application/windows/UserInfoWindow.cpp
|
application/windows/UserInfoWindow.cpp
|
||||||
|
|
||||||
|
|
|
@ -8,16 +8,19 @@
|
||||||
* Pier Luigi Fiorini, pierluigi.fiorini@gmail.com
|
* Pier Luigi Fiorini, pierluigi.fiorini@gmail.com
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "ProtocolLooper.h"
|
||||||
|
|
||||||
#include <String.h>
|
#include <String.h>
|
||||||
|
|
||||||
#include "Account.h"
|
#include "Account.h"
|
||||||
#include "ProtocolLooper.h"
|
#include "Conversation.h"
|
||||||
|
|
||||||
|
|
||||||
ProtocolLooper::ProtocolLooper(CayaProtocol* protocol)
|
ProtocolLooper::ProtocolLooper(CayaProtocol* protocol, int64 instance)
|
||||||
:
|
:
|
||||||
BLooper(),
|
BLooper(),
|
||||||
fProtocol(protocol)
|
fProtocol(protocol),
|
||||||
|
fInstance(instance)
|
||||||
{
|
{
|
||||||
Account* account = reinterpret_cast<Account*>(
|
Account* account = reinterpret_cast<Account*>(
|
||||||
protocol->MessengerInterface());
|
protocol->MessengerInterface());
|
||||||
|
@ -43,3 +46,110 @@ ProtocolLooper::Protocol()
|
||||||
{
|
{
|
||||||
return fProtocol;
|
return fProtocol;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
ChatMap
|
||||||
|
ProtocolLooper::Conversations() const
|
||||||
|
{
|
||||||
|
return fChatMap;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Conversation*
|
||||||
|
ProtocolLooper::ConversationById(BString id)
|
||||||
|
{
|
||||||
|
bool found = false;
|
||||||
|
return fChatMap.ValueFor(id, &found);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
ProtocolLooper::AddConversation(Conversation* chat)
|
||||||
|
{
|
||||||
|
fChatMap.AddItem(chat->GetId(), chat);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
ProtocolLooper::RemoveConversation(Conversation* chat)
|
||||||
|
{
|
||||||
|
fChatMap.RemoveItemFor(chat->GetId());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
RosterMap
|
||||||
|
ProtocolLooper::Contacts() const
|
||||||
|
{
|
||||||
|
return fRosterMap;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Contact*
|
||||||
|
ProtocolLooper::ContactById(BString id)
|
||||||
|
{
|
||||||
|
bool found = false;
|
||||||
|
return fRosterMap.ValueFor(id, &found);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
ProtocolLooper::AddContact(Contact* contact)
|
||||||
|
{
|
||||||
|
fRosterMap.AddItem(contact->GetId(), contact);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
UserMap
|
||||||
|
ProtocolLooper::Users() const
|
||||||
|
{
|
||||||
|
UserMap users = fUserMap;
|
||||||
|
|
||||||
|
for (int i = 0; i < fRosterMap.CountItems(); i++) {
|
||||||
|
User* user = (User*)fRosterMap.ValueAt(i);
|
||||||
|
users.AddItem(user->GetId(), user);
|
||||||
|
}
|
||||||
|
|
||||||
|
return users;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
User*
|
||||||
|
ProtocolLooper::UserById(BString id)
|
||||||
|
{
|
||||||
|
bool found = false;
|
||||||
|
User* user = ContactById(id);
|
||||||
|
if (user == NULL)
|
||||||
|
user = fUserMap.ValueFor(id, &found);
|
||||||
|
|
||||||
|
return user;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
ProtocolLooper::AddUser(User* user)
|
||||||
|
{
|
||||||
|
fUserMap.AddItem(user->GetId(), user);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
BString
|
||||||
|
ProtocolLooper::GetOwnId()
|
||||||
|
{
|
||||||
|
return fMySelf;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
ProtocolLooper::SetOwnId(BString user_id)
|
||||||
|
{
|
||||||
|
fMySelf = user_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int64
|
||||||
|
ProtocolLooper::GetInstance()
|
||||||
|
{
|
||||||
|
return fInstance;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -7,19 +7,57 @@
|
||||||
#define _PROTOCOL_LOOPER_H
|
#define _PROTOCOL_LOOPER_H
|
||||||
|
|
||||||
#include <Looper.h>
|
#include <Looper.h>
|
||||||
|
#include <String.h>
|
||||||
|
|
||||||
|
#include <libsupport/KeyMap.h>
|
||||||
|
|
||||||
#include "CayaProtocol.h"
|
#include "CayaProtocol.h"
|
||||||
|
|
||||||
|
class Contact;
|
||||||
|
class Conversation;
|
||||||
|
class User;
|
||||||
|
|
||||||
|
|
||||||
|
typedef KeyMap<BString, Conversation*> ChatMap;
|
||||||
|
typedef KeyMap<BString, Contact*> RosterMap;
|
||||||
|
typedef KeyMap<BString, User*> UserMap;
|
||||||
|
|
||||||
|
|
||||||
class ProtocolLooper : public BLooper {
|
class ProtocolLooper : public BLooper {
|
||||||
public:
|
public:
|
||||||
ProtocolLooper(CayaProtocol* protocol);
|
ProtocolLooper(CayaProtocol* protocol, int64 instance);
|
||||||
|
|
||||||
void MessageReceived(BMessage* msg);
|
void MessageReceived(BMessage* msg);
|
||||||
|
|
||||||
CayaProtocol* Protocol();
|
CayaProtocol* Protocol();
|
||||||
|
|
||||||
|
ChatMap Conversations() const;
|
||||||
|
Conversation* ConversationById(BString id);
|
||||||
|
void AddConversation(Conversation* chat);
|
||||||
|
void RemoveConversation(Conversation* chat);
|
||||||
|
|
||||||
|
RosterMap Contacts() const;
|
||||||
|
Contact* ContactById(BString id);
|
||||||
|
void AddContact(Contact* contact);
|
||||||
|
|
||||||
|
UserMap Users() const;
|
||||||
|
User* UserById(BString id);
|
||||||
|
void AddUser(User* user);
|
||||||
|
|
||||||
|
BString GetOwnId();
|
||||||
|
void SetOwnId(BString user_id);
|
||||||
|
|
||||||
|
int64 GetInstance();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
CayaProtocol* fProtocol;
|
CayaProtocol* fProtocol;
|
||||||
|
int64 fInstance;
|
||||||
|
|
||||||
|
BString fMySelf;
|
||||||
|
|
||||||
|
ChatMap fChatMap;
|
||||||
|
RosterMap fRosterMap;
|
||||||
|
UserMap fUserMap;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // _PROTOCOL_LOOPER_H
|
#endif // _PROTOCOL_LOOPER_H
|
||||||
|
|
|
@ -46,15 +46,15 @@ Server::Quit()
|
||||||
Contact* contact = NULL;
|
Contact* contact = NULL;
|
||||||
Conversation* conversation = NULL;
|
Conversation* conversation = NULL;
|
||||||
|
|
||||||
while (contact = fRosterMap.ValueAt(0)) {
|
// while (contact = fRosterMap.ValueAt(0)) {
|
||||||
contact->DeletePopUp();
|
// contact->DeletePopUp();
|
||||||
fRosterMap.RemoveItemAt(0);
|
// fRosterMap.RemoveItemAt(0);
|
||||||
}
|
// }
|
||||||
|
|
||||||
while (conversation = fChatMap.ValueAt(0)) {
|
// while (conversation = fChatMap.ValueAt(0)) {
|
||||||
fChatMap.RemoveItemAt(0);
|
// fChatMap.RemoveItemAt(0);
|
||||||
delete conversation;
|
// delete conversation;
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -83,7 +83,7 @@ Server::Filter(BMessage* message, BHandler **target)
|
||||||
BString id = message->FindString("chat_id");
|
BString id = message->FindString("chat_id");
|
||||||
if (id.Length() > 0) {
|
if (id.Length() > 0) {
|
||||||
bool found = false;
|
bool found = false;
|
||||||
Conversation* item = fChatMap.ValueFor(id, &found);
|
// Conversation* item = fChatMap.ValueFor(id, &found);
|
||||||
}
|
}
|
||||||
result = B_SKIP_MESSAGE;
|
result = B_SKIP_MESSAGE;
|
||||||
break;
|
break;
|
||||||
|
@ -170,7 +170,7 @@ Server::ImMessage(BMessage* msg)
|
||||||
{
|
{
|
||||||
Contact* contact = _EnsureContact(msg);
|
Contact* contact = _EnsureContact(msg);
|
||||||
if (contact != NULL) {
|
if (contact != NULL) {
|
||||||
fMySelf = contact->GetId();
|
contact->GetProtocolLooper()->SetOwnId(contact->GetId());
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -229,7 +229,7 @@ Server::ImMessage(BMessage* msg)
|
||||||
{
|
{
|
||||||
BString user_id = msg->FindString("user_id");
|
BString user_id = msg->FindString("user_id");
|
||||||
if (user_id.IsEmpty() == false) {
|
if (user_id.IsEmpty() == false) {
|
||||||
User* user = ContactById(user_id);
|
User* user = ContactById(user_id, msg->FindInt64("instance"));
|
||||||
user->GetProtocolLooper()->PostMessage(msg);
|
user->GetProtocolLooper()->PostMessage(msg);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -466,7 +466,7 @@ Server::ImMessage(BMessage* msg)
|
||||||
void
|
void
|
||||||
Server::AddProtocolLooper(bigtime_t instanceId, CayaProtocol* cayap)
|
Server::AddProtocolLooper(bigtime_t instanceId, CayaProtocol* cayap)
|
||||||
{
|
{
|
||||||
ProtocolLooper* looper = new ProtocolLooper(cayap);
|
ProtocolLooper* looper = new ProtocolLooper(cayap, instanceId);
|
||||||
fLoopers.AddItem(instanceId, looper);
|
fLoopers.AddItem(instanceId, looper);
|
||||||
fAccounts.AddItem(cayap->GetName(), instanceId);
|
fAccounts.AddItem(cayap->GetName(), instanceId);
|
||||||
}
|
}
|
||||||
|
@ -531,33 +531,53 @@ Server::SendAllProtocolMessage(BMessage* msg)
|
||||||
RosterMap
|
RosterMap
|
||||||
Server::Contacts() const
|
Server::Contacts() const
|
||||||
{
|
{
|
||||||
return fRosterMap;
|
RosterMap contacts;
|
||||||
|
|
||||||
|
for (int i = 0; i < fAccounts.CountItems(); i++) {
|
||||||
|
ProtocolLooper* fruitLoop = fLoopers.ValueFor(fAccounts.ValueAt(i));
|
||||||
|
if (fruitLoop == NULL) continue;
|
||||||
|
|
||||||
|
RosterMap accContacts = fruitLoop->Contacts();
|
||||||
|
for (int i = 0; i < accContacts.CountItems(); i++)
|
||||||
|
contacts.AddItem(accContacts.KeyAt(i), accContacts.ValueAt(i));
|
||||||
|
}
|
||||||
|
|
||||||
|
return contacts;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Contact*
|
Contact*
|
||||||
Server::ContactById(BString id)
|
Server::ContactById(BString id, int64 instance)
|
||||||
{
|
{
|
||||||
bool found = false;
|
ProtocolLooper* looper = fLoopers.ValueFor(instance);
|
||||||
return fRosterMap.ValueFor(id, &found);
|
Contact* result = NULL;
|
||||||
|
if (looper != NULL)
|
||||||
|
result = looper->ContactById(id);
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
Server::AddContact(Contact* contact)
|
Server::AddContact(Contact* contact, int64 instance)
|
||||||
{
|
{
|
||||||
fRosterMap.AddItem(contact->GetId(), contact);
|
ProtocolLooper* looper = fLoopers.ValueFor(instance);
|
||||||
|
if (looper != NULL)
|
||||||
|
looper->AddContact(contact);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
UserMap
|
UserMap
|
||||||
Server::Users() const
|
Server::Users() const
|
||||||
{
|
{
|
||||||
UserMap users = fUserMap;
|
UserMap users;
|
||||||
|
|
||||||
for (int i = 0; i < fRosterMap.CountItems(); i++) {
|
for (int i = 0; i < fAccounts.CountItems(); i++) {
|
||||||
User* user = (User*)fRosterMap.ValueAt(i);
|
ProtocolLooper* fruitLoop = fLoopers.ValueFor(fAccounts.ValueAt(i));
|
||||||
users.AddItem(user->GetId(), user);
|
if (fruitLoop == NULL) continue;
|
||||||
|
|
||||||
|
UserMap accUsers = fruitLoop->Users();
|
||||||
|
for (int i = 0; i < accUsers.CountItems(); i++)
|
||||||
|
users.AddItem(accUsers.KeyAt(i), accUsers.ValueAt(i));
|
||||||
}
|
}
|
||||||
|
|
||||||
return users;
|
return users;
|
||||||
|
@ -565,57 +585,69 @@ Server::Users() const
|
||||||
|
|
||||||
|
|
||||||
User*
|
User*
|
||||||
Server::UserById(BString id)
|
Server::UserById(BString id, int64 instance)
|
||||||
{
|
{
|
||||||
bool found = false;
|
ProtocolLooper* looper = fLoopers.ValueFor(instance);
|
||||||
User* user = ContactById(id);
|
User* result = NULL;
|
||||||
if (user == NULL)
|
if (looper != NULL)
|
||||||
user = fUserMap.ValueFor(id, &found);
|
result = looper->UserById(id);
|
||||||
|
return result;
|
||||||
return user;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
Server::AddUser(User* user)
|
Server::AddUser(User* user, int64 instance)
|
||||||
{
|
{
|
||||||
fUserMap.AddItem(user->GetId(), user);
|
ProtocolLooper* looper = fLoopers.ValueFor(instance);
|
||||||
|
if (looper != NULL)
|
||||||
|
looper->AddUser(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
ChatMap
|
ChatMap
|
||||||
Server::Conversations() const
|
Server::Conversations() const
|
||||||
{
|
{
|
||||||
return fChatMap;
|
ChatMap chats;
|
||||||
|
|
||||||
|
for (int i = 0; i < fAccounts.CountItems(); i++) {
|
||||||
|
ProtocolLooper* fruitLoop = fLoopers.ValueFor(fAccounts.ValueAt(i));
|
||||||
|
if (fruitLoop == NULL) continue;
|
||||||
|
|
||||||
|
ChatMap accChats = fruitLoop->Conversations();
|
||||||
|
for (int i = 0; i < accChats.CountItems(); i++)
|
||||||
|
chats.AddItem(accChats.KeyAt(i), accChats.ValueAt(i));
|
||||||
|
}
|
||||||
|
|
||||||
|
return chats;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Conversation*
|
Conversation*
|
||||||
Server::ConversationById(BString id)
|
Server::ConversationById(BString id, int64 instance)
|
||||||
{
|
{
|
||||||
bool found = false;
|
ProtocolLooper* looper = fLoopers.ValueFor(instance);
|
||||||
return fChatMap.ValueFor(id, &found);
|
Conversation* result = NULL;
|
||||||
|
if (looper != NULL)
|
||||||
|
result = looper->ConversationById(id);
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
Server::AddConversation(Conversation* chat)
|
Server::AddConversation(Conversation* chat, int64 instance)
|
||||||
{
|
{
|
||||||
fChatMap.AddItem(chat->GetId(), chat);
|
ProtocolLooper* looper = fLoopers.ValueFor(instance);
|
||||||
|
if (looper != NULL)
|
||||||
|
looper->AddConversation(chat);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
Server::RemoveConversation(Conversation* chat)
|
Server::RemoveConversation(Conversation* chat, int64 instance)
|
||||||
{
|
{
|
||||||
fChatMap.RemoveItemFor(chat->GetId());
|
ProtocolLooper* looper = fLoopers.ValueFor(instance);
|
||||||
}
|
if (looper != NULL)
|
||||||
|
looper->RemoveConversation(chat);
|
||||||
|
|
||||||
BString
|
|
||||||
Server::GetOwnContact()
|
|
||||||
{
|
|
||||||
return fMySelf;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -643,12 +675,15 @@ Contact*
|
||||||
Server::_EnsureContact(BMessage* message)
|
Server::_EnsureContact(BMessage* message)
|
||||||
{
|
{
|
||||||
BString id = message->FindString("user_id");
|
BString id = message->FindString("user_id");
|
||||||
Contact* contact = ContactById(id);
|
ProtocolLooper* looper = _LooperFromMessage(message);
|
||||||
|
if (looper == NULL) return NULL;
|
||||||
|
|
||||||
if (contact == NULL && id.IsEmpty() == false) {
|
Contact* contact = looper->ContactById(id);
|
||||||
|
|
||||||
|
if (contact == NULL && id.IsEmpty() == false && looper != NULL) {
|
||||||
contact = new Contact(id, Looper());
|
contact = new Contact(id, Looper());
|
||||||
contact->SetProtocolLooper(_LooperFromMessage(message));
|
contact->SetProtocolLooper(looper);
|
||||||
AddContact(contact);
|
looper->AddContact(contact);
|
||||||
}
|
}
|
||||||
|
|
||||||
return contact;
|
return contact;
|
||||||
|
@ -666,12 +701,12 @@ Server::_EnsureUser(BMessage* message)
|
||||||
User*
|
User*
|
||||||
Server::_EnsureUser(BString id, ProtocolLooper* protoLooper)
|
Server::_EnsureUser(BString id, ProtocolLooper* protoLooper)
|
||||||
{
|
{
|
||||||
User* user = UserById(id);
|
User* user = protoLooper->UserById(id);
|
||||||
|
|
||||||
if (user == NULL && id.IsEmpty() == false) {
|
if (user == NULL && id.IsEmpty() == false) {
|
||||||
user = new User(id, Looper());
|
user = new User(id, Looper());
|
||||||
user->SetProtocolLooper(protoLooper);
|
user->SetProtocolLooper(protoLooper);
|
||||||
AddUser(user);
|
protoLooper->AddUser(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
return user;
|
return user;
|
||||||
|
@ -681,21 +716,21 @@ Server::_EnsureUser(BString id, ProtocolLooper* protoLooper)
|
||||||
Conversation*
|
Conversation*
|
||||||
Server::_EnsureConversation(BMessage* message)
|
Server::_EnsureConversation(BMessage* message)
|
||||||
{
|
{
|
||||||
if (!message)
|
ProtocolLooper* looper;
|
||||||
|
if (!message || (looper = _LooperFromMessage(message)) == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
BString chat_id = message->FindString("chat_id");
|
BString chat_id = message->FindString("chat_id");
|
||||||
Conversation* item = NULL;
|
Conversation* item = NULL;
|
||||||
|
|
||||||
if (chat_id.IsEmpty() == false) {
|
if (chat_id.IsEmpty() == false) {
|
||||||
bool found = false;
|
item = looper->ConversationById(chat_id);
|
||||||
item = fChatMap.ValueFor(chat_id, &found);
|
|
||||||
|
|
||||||
if (!found) {
|
if (item == NULL) {
|
||||||
item = new Conversation(chat_id, Looper());
|
item = new Conversation(chat_id, Looper());
|
||||||
item->SetProtocolLooper(_LooperFromMessage(message));
|
item->SetProtocolLooper(looper);
|
||||||
item->AddUser(ContactById(fMySelf));
|
item->AddUser(looper->ContactById(looper->GetOwnId()));
|
||||||
fChatMap.AddItem(chat_id, item);
|
looper->AddConversation(item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return item;
|
return item;
|
||||||
|
|
|
@ -14,6 +14,7 @@
|
||||||
#include "CayaConstants.h"
|
#include "CayaConstants.h"
|
||||||
#include "Contact.h"
|
#include "Contact.h"
|
||||||
#include "Conversation.h"
|
#include "Conversation.h"
|
||||||
|
#include "ProtocolLooper.h"
|
||||||
#include "User.h"
|
#include "User.h"
|
||||||
|
|
||||||
class CayaProtocol;
|
class CayaProtocol;
|
||||||
|
@ -21,9 +22,6 @@ class RosterItem;
|
||||||
class ProtocolLooper;
|
class ProtocolLooper;
|
||||||
|
|
||||||
|
|
||||||
typedef KeyMap<BString, Contact*> RosterMap;
|
|
||||||
typedef KeyMap<BString, User*> UserMap;
|
|
||||||
typedef KeyMap<BString, Conversation*> ChatMap;
|
|
||||||
typedef KeyMap<bigtime_t, ProtocolLooper*> ProtocolLoopers;
|
typedef KeyMap<bigtime_t, ProtocolLooper*> ProtocolLoopers;
|
||||||
typedef KeyMap<BString, bigtime_t> AccountInstances;
|
typedef KeyMap<BString, bigtime_t> AccountInstances;
|
||||||
|
|
||||||
|
@ -49,20 +47,17 @@ public:
|
||||||
void SendAllProtocolMessage(BMessage* msg);
|
void SendAllProtocolMessage(BMessage* msg);
|
||||||
|
|
||||||
RosterMap Contacts() const;
|
RosterMap Contacts() const;
|
||||||
Contact* ContactById(BString id);
|
Contact* ContactById(BString id, int64 instance);
|
||||||
void AddContact(Contact* contact);
|
void AddContact(Contact* contact, int64 instance);
|
||||||
|
|
||||||
UserMap Users() const;
|
UserMap Users() const;
|
||||||
User* UserById(BString id);
|
User* UserById(BString id, int64 instance);
|
||||||
void AddUser(User* user);
|
void AddUser(User* user, int64 instance);
|
||||||
|
|
||||||
ChatMap Conversations() const;
|
ChatMap Conversations() const;
|
||||||
Conversation* ConversationById(BString id);
|
Conversation* ConversationById(BString id, int64 instance);
|
||||||
void AddConversation(Conversation* chat);
|
void AddConversation(Conversation* chat, int64 instance);
|
||||||
void RemoveConversation(Conversation* chat);
|
void RemoveConversation(Conversation* chat, int64 instance);
|
||||||
|
|
||||||
// TODO: there should be a contact for each account.
|
|
||||||
BString GetOwnContact();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ProtocolLooper* _LooperFromMessage(BMessage* message);
|
ProtocolLooper* _LooperFromMessage(BMessage* message);
|
||||||
|
@ -76,9 +71,6 @@ private:
|
||||||
|
|
||||||
void _ReplicantStatusNotify(CayaStatus status);
|
void _ReplicantStatusNotify(CayaStatus status);
|
||||||
|
|
||||||
RosterMap fRosterMap;
|
|
||||||
UserMap fUserMap;
|
|
||||||
ChatMap fChatMap;
|
|
||||||
ProtocolLoopers fLoopers;
|
ProtocolLoopers fLoopers;
|
||||||
AccountInstances
|
AccountInstances
|
||||||
fAccounts;
|
fAccounts;
|
||||||
|
|
|
@ -76,9 +76,11 @@ ConversationView::MessageReceived(BMessage* message)
|
||||||
BString text = message->FindString("body");
|
BString text = message->FindString("body");
|
||||||
if (text == "")
|
if (text == "")
|
||||||
return;
|
return;
|
||||||
|
int64 instance = fConversation->GetProtocolLooper()->GetInstance();
|
||||||
|
|
||||||
BMessage msg(IM_MESSAGE);
|
BMessage msg(IM_MESSAGE);
|
||||||
msg.AddInt32("im_what", IM_SEND_MESSAGE);
|
msg.AddInt32("im_what", IM_SEND_MESSAGE);
|
||||||
|
msg.AddInt64("instance", instance);
|
||||||
msg.AddString("chat_id", fConversation->GetId());
|
msg.AddString("chat_id", fConversation->GetId());
|
||||||
msg.AddString("body", text);
|
msg.AddString("body", text);
|
||||||
fConversation->ImMessage(&msg);
|
fConversation->ImMessage(&msg);
|
||||||
|
|
|
@ -115,8 +115,11 @@ RosterListView::MessageReceived(BMessage* msg)
|
||||||
BMessage* start = new BMessage(IM_MESSAGE);
|
BMessage* start = new BMessage(IM_MESSAGE);
|
||||||
start->AddInt32("im_what", IM_CREATE_CHAT);
|
start->AddInt32("im_what", IM_CREATE_CHAT);
|
||||||
start->AddString("user_id", user->GetId());
|
start->AddString("user_id", user->GetId());
|
||||||
|
ProtocolLooper* looper = user->GetProtocolLooper();
|
||||||
|
|
||||||
|
if (looper != NULL)
|
||||||
|
looper->PostMessage(start);
|
||||||
|
|
||||||
user->GetProtocolLooper()->PostMessage(start);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -92,7 +92,7 @@ UserListView::_UserPopUp()
|
||||||
menu->SetTargetForItems(this);
|
menu->SetTargetForItems(this);
|
||||||
|
|
||||||
// Now for the moderation items
|
// Now for the moderation items
|
||||||
Role* role = fChat->GetRole(fChat->OwnUserId());
|
Role* role = fChat->GetRole(fChat->GetOwnId());
|
||||||
if (role == NULL) return menu;
|
if (role == NULL) return menu;
|
||||||
int32 perms = role->fPerms;
|
int32 perms = role->fPerms;
|
||||||
UserItem* item = (UserItem*)ItemAt(CurrentSelection());
|
UserItem* item = (UserItem*)ItemAt(CurrentSelection());
|
||||||
|
@ -150,7 +150,7 @@ UserListView::_BlankPopUp()
|
||||||
void
|
void
|
||||||
UserListView::_ModerationAction(int32 im_what)
|
UserListView::_ModerationAction(int32 im_what)
|
||||||
{
|
{
|
||||||
Role* role = fChat->GetRole(fChat->OwnUserId());
|
Role* role = fChat->GetRole(fChat->GetOwnId());
|
||||||
int32 perms = role->fPerms;
|
int32 perms = role->fPerms;
|
||||||
UserItem* item = (UserItem*)ItemAt(CurrentSelection());
|
UserItem* item = (UserItem*)ItemAt(CurrentSelection());
|
||||||
if (item == NULL)
|
if (item == NULL)
|
||||||
|
|
|
@ -26,7 +26,7 @@
|
||||||
#include "JoinWindow.h"
|
#include "JoinWindow.h"
|
||||||
#include "MainWindow.h"
|
#include "MainWindow.h"
|
||||||
#include "NotifyMessage.h"
|
#include "NotifyMessage.h"
|
||||||
#include "PreferencesDialog.h"
|
#include "PreferencesWindow.h"
|
||||||
#include "ReplicantStatusView.h"
|
#include "ReplicantStatusView.h"
|
||||||
#include "RosterWindow.h"
|
#include "RosterWindow.h"
|
||||||
#include "Server.h"
|
#include "Server.h"
|
||||||
|
@ -99,8 +99,8 @@ MainWindow::MessageReceived(BMessage* message)
|
||||||
switch (message->what) {
|
switch (message->what) {
|
||||||
case CAYA_SHOW_SETTINGS:
|
case CAYA_SHOW_SETTINGS:
|
||||||
{
|
{
|
||||||
PreferencesDialog* dialog = new PreferencesDialog();
|
PreferencesWindow* win = new PreferencesWindow();
|
||||||
dialog->Show();
|
win->Show();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -257,13 +257,9 @@ MainWindow::ImMessage(BMessage* msg)
|
||||||
case IM_CONTACT_INFO:
|
case IM_CONTACT_INFO:
|
||||||
case IM_EXTENDED_CONTACT_INFO:
|
case IM_EXTENDED_CONTACT_INFO:
|
||||||
case IM_STATUS_SET:
|
case IM_STATUS_SET:
|
||||||
{
|
|
||||||
if (fServer->ContactById(msg->FindString("user_id")) != NULL)
|
|
||||||
if (fRosterWindow != NULL)
|
|
||||||
fRosterWindow->PostMessage(msg);
|
fRosterWindow->PostMessage(msg);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -428,7 +424,7 @@ MainWindow::_EnsureConversationItem(BMessage* msg)
|
||||||
ChatMap chats = fServer->Conversations();
|
ChatMap chats = fServer->Conversations();
|
||||||
|
|
||||||
BString chat_id = msg->FindString("chat_id");
|
BString chat_id = msg->FindString("chat_id");
|
||||||
Conversation* chat = fServer->ConversationById(chat_id);
|
Conversation* chat = fServer->ConversationById(chat_id, msg->FindInt64("instance"));
|
||||||
|
|
||||||
if (chat != NULL) {
|
if (chat != NULL) {
|
||||||
ConversationItem* item = chat->GetListItem();
|
ConversationItem* item = chat->GetListItem();
|
||||||
|
@ -466,7 +462,11 @@ MainWindow::_RemoveListItem(ConversationItem* item)
|
||||||
index--;
|
index--;
|
||||||
|
|
||||||
fListView->RemoveItem(item);
|
fListView->RemoveItem(item);
|
||||||
fServer->RemoveConversation(item->GetConversation());
|
Conversation* chat = item->GetConversation();
|
||||||
|
ProtocolLooper* looper = chat->GetProtocolLooper();
|
||||||
|
|
||||||
|
if (chat != NULL && looper != NULL)
|
||||||
|
looper->RemoveConversation(chat);
|
||||||
|
|
||||||
if (fListView->CountItems() == 0) {
|
if (fListView->CountItems() == 0) {
|
||||||
fChatView = new ConversationView();
|
fChatView = new ConversationView();
|
||||||
|
|
|
@ -6,21 +6,23 @@
|
||||||
* Pier Luigi Fiorini, pierluigi.fiorini@gmail.com
|
* Pier Luigi Fiorini, pierluigi.fiorini@gmail.com
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "PreferencesWindow.h"
|
||||||
|
|
||||||
#include <Button.h>
|
#include <Button.h>
|
||||||
#include <ControlLook.h>
|
#include <ControlLook.h>
|
||||||
#include <LayoutBuilder.h>
|
#include <LayoutBuilder.h>
|
||||||
#include <TabView.h>
|
#include <TabView.h>
|
||||||
|
|
||||||
#include "PreferencesDialog.h"
|
|
||||||
#include "PreferencesAccounts.h"
|
#include "PreferencesAccounts.h"
|
||||||
#include "PreferencesBehavior.h"
|
#include "PreferencesBehavior.h"
|
||||||
#include "PreferencesChatWindow.h"
|
#include "PreferencesChatWindow.h"
|
||||||
#include "PreferencesReplicant.h"
|
#include "PreferencesReplicant.h"
|
||||||
|
|
||||||
|
|
||||||
const uint32 kApply = 'SAVE';
|
const uint32 kApply = 'SAVE';
|
||||||
|
|
||||||
|
|
||||||
PreferencesDialog::PreferencesDialog()
|
PreferencesWindow::PreferencesWindow()
|
||||||
: BWindow(BRect(0, 0, 500, 615), "Preferences", B_TITLED_WINDOW,
|
: BWindow(BRect(0, 0, 500, 615), "Preferences", B_TITLED_WINDOW,
|
||||||
B_NOT_RESIZABLE | B_NOT_ZOOMABLE | B_CLOSE_ON_ESCAPE)
|
B_NOT_RESIZABLE | B_NOT_ZOOMABLE | B_CLOSE_ON_ESCAPE)
|
||||||
{
|
{
|
||||||
|
@ -44,7 +46,7 @@ PreferencesDialog::PreferencesDialog()
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
PreferencesDialog::MessageReceived(BMessage* msg)
|
PreferencesWindow::MessageReceived(BMessage* msg)
|
||||||
{
|
{
|
||||||
switch (msg->what) {
|
switch (msg->what) {
|
||||||
case kApply:
|
case kApply:
|
|
@ -2,16 +2,16 @@
|
||||||
* Copyright 2009-2010, Pier Luigi Fiorini. All rights reserved.
|
* Copyright 2009-2010, Pier Luigi Fiorini. All rights reserved.
|
||||||
* Distributed under the terms of the MIT License.
|
* Distributed under the terms of the MIT License.
|
||||||
*/
|
*/
|
||||||
#ifndef _PREFERENCES_DIALOG_H
|
#ifndef _PREFERENCES_WINDOW_H
|
||||||
#define _PREFERENCES_DIALOG_H
|
#define _PREFERENCES_WINDOW_H
|
||||||
|
|
||||||
#include <Window.h>
|
#include <Window.h>
|
||||||
|
|
||||||
class PreferencesDialog : public BWindow {
|
class PreferencesWindow : public BWindow {
|
||||||
public:
|
public:
|
||||||
PreferencesDialog();
|
PreferencesWindow();
|
||||||
|
|
||||||
virtual void MessageReceived(BMessage* msg);
|
virtual void MessageReceived(BMessage* msg);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // _PREFERENCES_DIALOG_H
|
#endif // _PREFERENCES_WINDOW_H
|
|
@ -102,6 +102,7 @@ RosterWindow::MessageReceived(BMessage* message)
|
||||||
|
|
||||||
User* user = ritem->GetContact();
|
User* user = ritem->GetContact();
|
||||||
fMessage->AddString("user_id", user->GetId());
|
fMessage->AddString("user_id", user->GetId());
|
||||||
|
fMessage->AddInt64("instance", user->GetProtocolLooper()->GetInstance());
|
||||||
fTarget->SendMessage(fMessage);
|
fTarget->SendMessage(fMessage);
|
||||||
PostMessage(B_QUIT_REQUESTED);
|
PostMessage(B_QUIT_REQUESTED);
|
||||||
|
|
||||||
|
@ -126,11 +127,18 @@ RosterWindow::ImMessage(BMessage* msg)
|
||||||
case IM_STATUS_SET:
|
case IM_STATUS_SET:
|
||||||
{
|
{
|
||||||
int32 status;
|
int32 status;
|
||||||
|
int64 instance;
|
||||||
if (msg->FindInt32("status", &status) != B_OK)
|
BString user_id = msg->FindString("user_id");
|
||||||
|
if (msg->FindInt32("status", &status) != B_OK
|
||||||
|
|| msg->FindInt64("instance", &instance) != B_OK
|
||||||
|
|| user_id.IsEmpty() == true)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
RosterItem* rosterItem = fServer->ContactById(msg->FindString("user_id"))->GetRosterItem();
|
Contact* contact = fServer->ContactById(user_id, instance);
|
||||||
|
if (contact == NULL)
|
||||||
|
return;
|
||||||
|
|
||||||
|
RosterItem* rosterItem = contact->GetRosterItem();
|
||||||
|
|
||||||
if (rosterItem) {
|
if (rosterItem) {
|
||||||
UpdateListItem(rosterItem);
|
UpdateListItem(rosterItem);
|
||||||
|
@ -191,8 +199,19 @@ RosterWindow::ImMessage(BMessage* msg)
|
||||||
case IM_CONTACT_INFO:
|
case IM_CONTACT_INFO:
|
||||||
case IM_EXTENDED_CONTACT_INFO:
|
case IM_EXTENDED_CONTACT_INFO:
|
||||||
{
|
{
|
||||||
RosterItem* rosterItem
|
int32 status = -1;
|
||||||
= fServer->ContactById(msg->FindString("user_id"))->GetRosterItem();
|
int64 instance;
|
||||||
|
BString user_id = msg->FindString("user_id");
|
||||||
|
if (msg->FindInt32("status", &status) != B_OK
|
||||||
|
|| msg->FindInt64("instance", &instance) != B_OK
|
||||||
|
|| user_id.IsEmpty() == true)
|
||||||
|
return;
|
||||||
|
|
||||||
|
Contact* contact = fServer->ContactById(user_id, instance);
|
||||||
|
if (contact == NULL)
|
||||||
|
return;
|
||||||
|
|
||||||
|
RosterItem* rosterItem = contact->GetRosterItem();
|
||||||
if (rosterItem)
|
if (rosterItem)
|
||||||
UpdateListItem(rosterItem);
|
UpdateListItem(rosterItem);
|
||||||
break;
|
break;
|
||||||
|
|
Ŝarĝante…
Reference in New Issue