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
Contact::_EnsureCachePath()
{

View File

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

View File

@ -322,6 +322,19 @@ Server::ImMessage(BMessage* msg)
contact->SetNotifyName(name);
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:
{
User* user = _EnsureUser(msg);

View File

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

View File

@ -21,6 +21,7 @@
#include <libinterface/BitmapView.h>
#include "AccountManager.h"
#include "ImageCache.h"
#include "NicknameTextControl.h"
#include "StatusMenuItem.h"
#include "Utils.h"
@ -69,6 +70,7 @@ StatusView::StatusView(const char* name)
fAvatar = new BitmapView("AvatarIcon");
fAvatar->SetExplicitMaxSize(BSize(50, 50));
fAvatar->SetExplicitPreferredSize(BSize(50, 50));
fAvatar->SetBitmap(ImageCache::Get()->GetImage("kPersonIcon"));
// Set layout
BLayoutBuilder::Group<>(this, B_HORIZONTAL)
@ -140,5 +142,7 @@ StatusView::SetStatus(UserStatus status)
void
StatusView::SetAvatarIcon(const BBitmap* 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");
switch (im_what) {
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) {
BBitmap* bitmap = BTranslationUtils::GetBitmap(&ref);
fStatusView->SetAvatarIcon(bitmap);
int64 instance;
if (msg->FindInt64("instance", &instance) == B_OK) {
ProtocolLooper* looper = fServer->GetProtocolLooper(instance);
if (looper != NULL) {
Contact* contact = looper->GetOwnContact();
contact->RegisterObserver(this);
fStatusView->SetAvatarIcon(contact->AvatarBitmap());
}
}
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
MainWindow::WorkspaceActivated(int32 workspace, bool active)
{

View File

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