Fix status view's avatar icon

The StatusView (below the roomlist) now shows a default icon if no
accounts have associated avatars, and will use an account's cached avatar
if available.
This commit is contained in:
Jaidyn Ann 2021-07-13 14:43:48 -05:00
parent 91ab9d8fb7
commit 5ec79ebbf5
7 changed files with 42 additions and 19 deletions

View File

@ -30,15 +30,6 @@ Contact::GetRosterItem() const
} }
void
Contact::SetNotifyAvatarBitmap(BBitmap* bitmap)
{
User::SetNotifyAvatarBitmap(bitmap);
// if (fAvatarBitmap != NULL && fChatWindow != NULL)
// fChatWindow->UpdateAvatar();
}
void void
Contact::_EnsureCachePath() Contact::_EnsureCachePath()
{ {

View File

@ -26,8 +26,6 @@ public:
RosterItem* GetRosterItem() const; RosterItem* GetRosterItem() const;
void SetNotifyAvatarBitmap(BBitmap* bitmap);
private: private:
virtual void _EnsureCachePath(); virtual void _EnsureCachePath();

View File

@ -322,6 +322,19 @@ Server::ImMessage(BMessage* msg)
contact->SetNotifyName(name); contact->SetNotifyName(name);
break; break;
} }
case IM_OWN_AVATAR_SET:
{
ProtocolLooper* looper = _LooperFromMessage(msg);
Contact* contact = looper->GetOwnContact();
entry_ref ref;
if (msg->FindRef("ref", &ref) == B_OK) {
BBitmap* bitmap = BTranslationUtils::GetBitmap(&ref);
if (bitmap != NULL)
contact->SetNotifyAvatarBitmap(bitmap);
}
break;
}
case IM_AVATAR_SET: case IM_AVATAR_SET:
{ {
User* user = _EnsureUser(msg); User* user = _EnsureUser(msg);

View File

@ -70,6 +70,7 @@ private:
Contact* _EnsureContact(BMessage* message); Contact* _EnsureContact(BMessage* message);
User* _EnsureUser(BMessage* message); User* _EnsureUser(BMessage* message);
User* _EnsureUser(BString id, ProtocolLooper* protoLooper); User* _EnsureUser(BString id, ProtocolLooper* protoLooper);
Contact* _GetOwnContact(BMessage* message);
Conversation* _EnsureConversation(BMessage* message); Conversation* _EnsureConversation(BMessage* message);
Role* _GetRole(BMessage* msg); Role* _GetRole(BMessage* msg);

View File

@ -21,6 +21,7 @@
#include <libinterface/BitmapView.h> #include <libinterface/BitmapView.h>
#include "AccountManager.h" #include "AccountManager.h"
#include "ImageCache.h"
#include "NicknameTextControl.h" #include "NicknameTextControl.h"
#include "StatusMenuItem.h" #include "StatusMenuItem.h"
#include "Utils.h" #include "Utils.h"
@ -69,6 +70,7 @@ StatusView::StatusView(const char* name)
fAvatar = new BitmapView("AvatarIcon"); fAvatar = new BitmapView("AvatarIcon");
fAvatar->SetExplicitMaxSize(BSize(50, 50)); fAvatar->SetExplicitMaxSize(BSize(50, 50));
fAvatar->SetExplicitPreferredSize(BSize(50, 50)); fAvatar->SetExplicitPreferredSize(BSize(50, 50));
fAvatar->SetBitmap(ImageCache::Get()->GetImage("kPersonIcon"));
// Set layout // Set layout
BLayoutBuilder::Group<>(this, B_HORIZONTAL) BLayoutBuilder::Group<>(this, B_HORIZONTAL)
@ -140,5 +142,7 @@ StatusView::SetStatus(UserStatus status)
void void
StatusView::SetAvatarIcon(const BBitmap* bitmap) StatusView::SetAvatarIcon(const BBitmap* bitmap)
{ {
fAvatar->SetBitmap(bitmap); // We don't want the default avatar to override a real one
if (bitmap != ImageCache::Get()->GetImage("kPersonIcon"))
fAvatar->SetBitmap(bitmap);
} }

View File

@ -229,15 +229,19 @@ MainWindow::ImMessage(BMessage* msg)
int32 im_what = msg->FindInt32("im_what"); int32 im_what = msg->FindInt32("im_what");
switch (im_what) { switch (im_what) {
case IM_OWN_CONTACT_INFO: case IM_OWN_CONTACT_INFO:
fStatusView->SetName(msg->FindString("name"));
break;
case IM_OWN_AVATAR_SET:
{ {
entry_ref ref; BString name;
if (msg->FindString("name", &name) == B_OK)
fStatusView->SetName(msg->FindString("name"));
if (msg->FindRef("ref", &ref) == B_OK) { int64 instance;
BBitmap* bitmap = BTranslationUtils::GetBitmap(&ref); if (msg->FindInt64("instance", &instance) == B_OK) {
fStatusView->SetAvatarIcon(bitmap); ProtocolLooper* looper = fServer->GetProtocolLooper(instance);
if (looper != NULL) {
Contact* contact = looper->GetOwnContact();
contact->RegisterObserver(this);
fStatusView->SetAvatarIcon(contact->AvatarBitmap());
}
} }
break; break;
} }
@ -309,6 +313,17 @@ MainWindow::ObserveInteger(int32 what, int32 val)
} }
void
MainWindow::ObservePointer(int32 what, void* ptr)
{
if (what == PTR_AVATAR_BITMAP) {
BBitmap* bmp = (BBitmap*)ptr;
if (bmp != NULL)
fStatusView->SetAvatarIcon(bmp);
}
}
void void
MainWindow::WorkspaceActivated(int32 workspace, bool active) MainWindow::WorkspaceActivated(int32 workspace, bool active)
{ {

View File

@ -39,6 +39,7 @@ public:
// Observer inheritance // Observer inheritance
void ObserveInteger(int32 what, int32 val); void ObserveInteger(int32 what, int32 val);
void ObservePointer(int32 what, void* ptr);
virtual void WorkspaceActivated(int32 workspace, virtual void WorkspaceActivated(int32 workspace,
bool active); bool active);