diff --git a/application/Conversation.cpp b/application/Conversation.cpp index 27dccbe..875abf3 100644 --- a/application/Conversation.cpp +++ b/application/Conversation.cpp @@ -141,7 +141,7 @@ Conversation::Users() } -Contact* +User* Conversation::UserById(BString id) { bool found = false; @@ -260,14 +260,14 @@ Conversation::_EnsureLogPath() } -Contact* +User* Conversation::_EnsureUser(BMessage* msg) { BString id = msg->FindString("user_id"); if (id.IsEmpty() == true) return NULL; - Contact* user = UserById(id); - Contact* serverUser = _GetServer()->ContactById(id); + User* user = UserById(id); + User* serverUser = _GetServer()->UserById(id); if (user == NULL && serverUser != NULL) { fUsers.AddItem(id, serverUser); @@ -275,10 +275,10 @@ Conversation::_EnsureUser(BMessage* msg) GetView()->UpdateUserList(fUsers); } else if (user == NULL) { - user = new Contact(id, _GetServer()->Looper()); + user = new User(id, _GetServer()->Looper()); user->SetProtocolLooper(fLooper); - _GetServer()->AddContact(user); + _GetServer()->AddUser(user); fUsers.AddItem(id, user); GetView()->UpdateUserList(fUsers); } diff --git a/application/Conversation.h b/application/Conversation.h index a6b7d4d..9f1426f 100644 --- a/application/Conversation.h +++ b/application/Conversation.h @@ -12,17 +12,16 @@ #include #include "Observer.h" +#include "Server.h" #include "User.h" -class ChatWindow; -class Contact; class ConversationItem; class ConversationView; class ProtocolLooper; class Server; -typedef KeyMap UserMap; +typedef KeyMap UserMap; class Conversation : public Observer { @@ -53,7 +52,7 @@ public: BString GetName() const; UserMap Users(); - Contact* UserById(BString id); + User* UserById(BString id); void AddUser(User* user); private: @@ -61,7 +60,7 @@ private: BStringList _GetChatLogs(); void _EnsureLogPath(); - Contact* _EnsureUser(BMessage* msg); + User* _EnsureUser(BMessage* msg); Server* _GetServer(); BMessenger fMessenger; diff --git a/application/Server.cpp b/application/Server.cpp index a3503af..6fcf623 100644 --- a/application/Server.cpp +++ b/application/Server.cpp @@ -188,6 +188,38 @@ Server::AddContact(Contact* contact) } +UserMap +Server::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* +Server::UserById(BString id) +{ + bool found = false; + User* user = ContactById(id); + if (user == NULL) + user = fUserMap.ValueFor(id, &found); + + return user; +} + + +void +Server::AddUser(User* user) +{ + fUserMap.AddItem(user->GetId(), user); +} + + ChatMap Server::Conversations() const { @@ -305,17 +337,17 @@ Server::ImMessage(BMessage* msg) } case IM_AVATAR_SET: { - Contact* contact = _EnsureContact(msg); - if (!contact) + User* user = _EnsureUser(msg); + if (!user) break; entry_ref ref; if (msg->FindRef("ref", &ref) == B_OK) { BBitmap* bitmap = BTranslationUtils::GetBitmap(&ref); - contact->SetNotifyAvatarBitmap(bitmap); + user->SetNotifyAvatarBitmap(bitmap); } else - contact->SetNotifyAvatarBitmap(NULL); + user->SetNotifyAvatarBitmap(NULL); break; } case IM_CREATE_CHAT: @@ -330,7 +362,7 @@ Server::ImMessage(BMessage* msg) case IM_CHAT_CREATED: { Conversation* chat = _EnsureConversation(msg); - User* user = _EnsureContact(msg); + User* user = _EnsureUser(msg); if (chat != NULL && user != NULL) { chat->AddUser(user); @@ -464,29 +496,11 @@ Server::_LooperFromMessage(BMessage* message) } -Contact* -Server::_GetContact(BMessage* message) -{ - if (!message) - return NULL; - - BString id = message->FindString("user_id"); - Contact* item = NULL; - - if (id.IsEmpty() == false) { - bool found = false; - item = fRosterMap.ValueFor(id, &found); - } - - return item; -} - - Contact* Server::_EnsureContact(BMessage* message) { - Contact* contact = _GetContact(message); BString id = message->FindString("user_id"); + Contact* contact = ContactById(id); if (contact == NULL && id.IsEmpty() == false) { contact = new Contact(id, Looper()); @@ -498,6 +512,22 @@ Server::_EnsureContact(BMessage* message) } +User* +Server::_EnsureUser(BMessage* message) +{ + BString id = message->FindString("user_id"); + User* user = UserById(id); + + if (user == NULL && id.IsEmpty() == false) { + user = new User(id, Looper()); + user->SetProtocolLooper(_LooperFromMessage(message)); + fUserMap.AddItem(id, user); + } + + return user; +} + + Conversation* Server::_EnsureConversation(BMessage* message) { diff --git a/application/Server.h b/application/Server.h index 7f68bc1..a57c7af 100644 --- a/application/Server.h +++ b/application/Server.h @@ -14,6 +14,7 @@ #include "CayaConstants.h" #include "Contact.h" #include "Conversation.h" +#include "User.h" class CayaProtocol; class RosterItem; @@ -21,6 +22,7 @@ class ProtocolLooper; typedef KeyMap RosterMap; +typedef KeyMap UserMap; typedef KeyMap ChatMap; typedef KeyMap ProtocolLoopers; @@ -47,6 +49,10 @@ public: Contact* ContactById(BString id); void AddContact(Contact* contact); + UserMap Users() const; + User* UserById(BString id); + void AddUser(User* user); + ChatMap Conversations() const; Conversation* ConversationById(BString id); void AddConversation(Conversation* chat); @@ -56,12 +62,15 @@ public: private: ProtocolLooper* _LooperFromMessage(BMessage* message); - Contact* _GetContact(BMessage* message); + Contact* _EnsureContact(BMessage* message); + User* _EnsureUser(BMessage* message); Conversation* _EnsureConversation(BMessage* message); + void _ReplicantStatusNotify(CayaStatus status); RosterMap fRosterMap; + UserMap fUserMap; ChatMap fChatMap; ProtocolLoopers fLoopers; Contact* fMySelf; diff --git a/application/views/ConversationView.cpp b/application/views/ConversationView.cpp index ad5be4f..e59f0ce 100644 --- a/application/views/ConversationView.cpp +++ b/application/views/ConversationView.cpp @@ -21,9 +21,9 @@ #include "CayaPreferences.h" #include "CayaProtocolMessages.h" #include "CayaRenderView.h" -#include "Contact.h" #include "Conversation.h" #include "NotifyMessage.h" +#include "User.h" #include "UserItem.h" #include "UserListView.h" diff --git a/application/views/ConversationView.h b/application/views/ConversationView.h index e1b17f4..3c25c1d 100644 --- a/application/views/ConversationView.h +++ b/application/views/ConversationView.h @@ -16,7 +16,7 @@ class BTextView; class BitmapView; class CayaRenderView; -class Contact; +class User; class UserListView; @@ -54,7 +54,7 @@ private: void _AppendMessage(BMessage* msg); Conversation* fConversation; - Contact* fContact; + User* fContact; int32 fMessageCount; BObjectList fMessageQueue;