From 52a580e03d2b96f65a4cc7772e357a655b10cbcf Mon Sep 17 00:00:00 2001 From: Jaidyn Ann Date: Tue, 6 Jul 2021 14:46:28 -0500 Subject: [PATCH] Remove own user from contacts; fix roster bitmaps MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It doesn't make sense to lump the user themself with their contacts list― their Contact object is now stored seperately. BBitmap loading for RosterItems are fixed, as well. Fixes #33 --- application/Conversation.cpp | 6 +++--- application/Conversation.h | 2 +- application/ProtocolLooper.cpp | 8 ++++---- application/ProtocolLooper.h | 6 +++--- application/Server.cpp | 16 +++++++++++----- application/views/RosterItem.cpp | 4 +--- application/views/UserListView.cpp | 2 +- 7 files changed, 24 insertions(+), 20 deletions(-) diff --git a/application/Conversation.cpp b/application/Conversation.cpp index fdeed92..db282d3 100644 --- a/application/Conversation.cpp +++ b/application/Conversation.cpp @@ -332,10 +332,10 @@ Conversation::RemoveUser(User* user) } -BString -Conversation::GetOwnId() +Contact* +Conversation::GetOwnContact() { - return fLooper->GetOwnId(); + return fLooper->GetOwnContact(); } diff --git a/application/Conversation.h b/application/Conversation.h index 52bf805..d9f27de 100644 --- a/application/Conversation.h +++ b/application/Conversation.h @@ -62,7 +62,7 @@ public: UserMap Users(); User* UserById(BString id); - BString GetOwnId(); + Contact* GetOwnContact(); void AddUser(User* user); void RemoveUser(User* user); diff --git a/application/ProtocolLooper.cpp b/application/ProtocolLooper.cpp index c995715..5dbf190 100644 --- a/application/ProtocolLooper.cpp +++ b/application/ProtocolLooper.cpp @@ -167,17 +167,17 @@ ProtocolLooper::CommandById(BString id) } -BString -ProtocolLooper::GetOwnId() +Contact* +ProtocolLooper::GetOwnContact() { return fMySelf; } void -ProtocolLooper::SetOwnId(BString user_id) +ProtocolLooper::SetOwnContact(Contact* contact) { - fMySelf = user_id; + fMySelf = contact; } diff --git a/application/ProtocolLooper.h b/application/ProtocolLooper.h index a73d029..d5690c6 100644 --- a/application/ProtocolLooper.h +++ b/application/ProtocolLooper.h @@ -53,8 +53,8 @@ public: CommandMap Commands() const; ChatCommand* CommandById(BString id); - BString GetOwnId(); - void SetOwnId(BString user_id); + Contact* GetOwnContact(); + void SetOwnContact(Contact* contact); int64 GetInstance(); @@ -67,7 +67,7 @@ private: ChatProtocol* fProtocol; int64 fInstance; - BString fMySelf; + Contact* fMySelf; ChatMap fChatMap; RosterMap fRosterMap; diff --git a/application/Server.cpp b/application/Server.cpp index 8a01b74..783927e 100644 --- a/application/Server.cpp +++ b/application/Server.cpp @@ -270,10 +270,17 @@ Server::ImMessage(BMessage* msg) } case IM_OWN_CONTACT_INFO: { - Contact* contact = _EnsureContact(msg); - if (contact != NULL) { - contact->GetProtocolLooper()->SetOwnId(contact->GetId()); + BString id = msg->FindString("user_id"); + ProtocolLooper* looper = _LooperFromMessage(msg); + if (looper == NULL || id.IsEmpty() == true) break; + + Contact* contact = looper->GetOwnContact(); + if (contact == NULL) { + contact = new Contact(id, Looper()); + contact->SetProtocolLooper(looper); + looper->SetOwnContact(contact); } + BString name; if (msg->FindString("user_name", &name) == B_OK) contact->SetNotifyName(name); @@ -449,7 +456,6 @@ Server::ImMessage(BMessage* msg) { Conversation* item = _EnsureConversation(msg); item->ImMessage(msg); - break; } case IM_ROOM_INVITE_RECEIVED: @@ -922,7 +928,7 @@ Server::_EnsureConversation(BMessage* message) if (item == NULL) { item = new Conversation(chat_id, Looper()); item->SetProtocolLooper(looper); - item->AddUser(looper->ContactById(looper->GetOwnId())); + item->AddUser(looper->GetOwnContact()); looper->AddConversation(item); BMessage meta(IM_MESSAGE); diff --git a/application/views/RosterItem.cpp b/application/views/RosterItem.cpp index 33c3bcf..1afb7fb 100644 --- a/application/views/RosterItem.cpp +++ b/application/views/RosterItem.cpp @@ -20,7 +20,7 @@ RosterItem::RosterItem(const char* name, Contact* contact) : BStringItem(name), - fBitmap(NULL), + fBitmap(contact->AvatarBitmap()), fStatus(STATUS_OFFLINE), contactLinker(contact), fVisible(true) @@ -49,8 +49,6 @@ RosterItem::SetVisible(bool visible) void RosterItem::SetBitmap(BBitmap* bitmap) { - if (fBitmap != NULL) - delete fBitmap; fBitmap = bitmap; } diff --git a/application/views/UserListView.cpp b/application/views/UserListView.cpp index 35eee8c..7f0fe28 100644 --- a/application/views/UserListView.cpp +++ b/application/views/UserListView.cpp @@ -57,7 +57,7 @@ UserListView::_UserPopUp() if (item == NULL || (selected_user = item->GetUser()) == NULL) return _BlankPopUp(); - Role* own_role = fChat->GetRole(fChat->GetOwnId()); + Role* own_role = fChat->GetRole(fChat->GetOwnContact()->GetId()); Role* selected_role = fChat->GetRole(selected_user->GetId());