From 7df377d996950185e07d8c9449bc94d5551fcd2b Mon Sep 17 00:00:00 2001 From: Jaidyn Ann Date: Tue, 27 Jul 2021 19:51:55 -0500 Subject: [PATCH] Default chat icon, use other user's avatar For one-on-one chats without a custom icon, the other user's avatar will be used as the chat's icon. A default chat icon was also added (haiku/data/artwork/icons/WebsiteComments). --- application/AppResources.h | 3 ++- application/Conversation.cpp | 39 +++++++++++++++++++++++++++++++++-- application/Conversation.h | 4 ++++ application/ImageCache.cpp | 1 + application/Makefile | 1 + data/icons/misc/Chat | Bin 0 -> 2925 bytes data/icons/misc/Chat.rdef | 9 ++++++++ 7 files changed, 54 insertions(+), 3 deletions(-) create mode 100644 data/icons/misc/Chat create mode 100644 data/icons/misc/Chat.rdef diff --git a/application/AppResources.h b/application/AppResources.h index 6cb9a56..7e62ce9 100644 --- a/application/AppResources.h +++ b/application/AppResources.h @@ -24,7 +24,8 @@ enum { kExitMenuReplicant = 1401, kReplicantMessageReceived = 1402, - kPersonIcon = 1500 + kPersonIcon = 1500, + kChatIcon = 1501 }; #endif // _APP_RESOURCES_H diff --git a/application/Conversation.cpp b/application/Conversation.cpp index aeb92bc..6550cb3 100644 --- a/application/Conversation.cpp +++ b/application/Conversation.cpp @@ -20,6 +20,7 @@ #include "ConversationItem.h" #include "ConversationView.h" #include "Flags.h" +#include "ImageCache.h" #include "MainWindow.h" #include "NotifyMessage.h" #include "ProtocolLooper.h" @@ -36,12 +37,13 @@ Conversation::Conversation(BString id, BMessenger msgn) fMessenger(msgn), fChatView(NULL), fLooper(NULL), - fIcon(NULL), + fIcon(ImageCache::Get()->GetImage("kChatIcon")), fDateFormatter(), fRoomFlags(0), fDisallowedFlags(0), fNotifyMessageCount(0), - fNotifyMentionCount(0) + fNotifyMentionCount(0), + fUserIcon(false) { fConversationItem = new ConversationItem(fName.String(), this); RegisterObserver(fConversationItem); @@ -275,6 +277,18 @@ Conversation::SetNotifySubject(const char* subject) } +bool +Conversation::SetIconBitmap(BBitmap* icon) +{ + if (icon != NULL) { + fIcon = icon; + GetView()->UpdateIcon(); + return true; + } + return false; +} + + BMessenger Conversation::Messenger() const { @@ -564,6 +578,8 @@ Conversation::_EnsureUser(BMessage* msg) fUsers.AddItem(id, serverUser); user = serverUser; GetView()->UpdateUserList(fUsers); + + _CloneUserIcon(user); } // Not anywhere; create user else if (user == NULL) { @@ -573,6 +589,8 @@ Conversation::_EnsureUser(BMessage* msg) fLooper->AddUser(user); fUsers.AddItem(id, user); GetView()->UpdateUserList(fUsers); + + _CloneUserIcon(user); } if (name.IsEmpty() == false) { @@ -583,6 +601,23 @@ Conversation::_EnsureUser(BMessage* msg) } +void +Conversation::_CloneUserIcon(User* user) +{ + // If it's a one-on-one chat without custom icon, steal a user's + if ((fUsers.CountItems() <= 2 && user->GetId() != GetOwnContact()->GetId()) + && (fIcon == ImageCache::Get()->GetImage("kChatIcon") + || fIcon == NULL)) + fUserIcon = SetIconBitmap(user->AvatarBitmap()); + + // If it's no longer one-on-one, revert + if (fUsers.CountItems() > 2 && fUserIcon == true) { + SetIconBitmap(ImageCache::Get()->GetImage("kChatIcon")); + fUserIcon = false; + } +} + + void Conversation::_SortConversationList() { diff --git a/application/Conversation.h b/application/Conversation.h index b7aa821..9979bd9 100644 --- a/application/Conversation.h +++ b/application/Conversation.h @@ -44,6 +44,8 @@ public: void SetNotifyName(const char* name); void SetNotifySubject(const char* subject); + bool SetIconBitmap(BBitmap* icon); + BMessenger Messenger() const; void SetMessenger(BMessenger messenger); @@ -83,6 +85,7 @@ private: void _EnsureCachePath(); User* _EnsureUser(BMessage* msg); + void _CloneUserIcon(User* user); void _SortConversationList(); @@ -100,6 +103,7 @@ private: BString fSubject; BBitmap* fIcon; + bool fUserIcon; BPath fCachePath; BDateTimeFormat fDateFormatter; diff --git a/application/ImageCache.cpp b/application/ImageCache.cpp index c6a0423..143d016 100644 --- a/application/ImageCache.cpp +++ b/application/ImageCache.cpp @@ -27,6 +27,7 @@ ImageCache* ImageCache::fInstance = NULL; ImageCache::ImageCache() { _LoadResource(kPersonIcon, "kPersonIcon"); + _LoadResource(kChatIcon, "kChatIcon"); _LoadResource(kAwayReplicant, "kAwayReplicant"); _LoadResource(kBusyReplicant, "kBusyReplicant"); diff --git a/application/Makefile b/application/Makefile index 06f0969..2b0cba0 100644 --- a/application/Makefile +++ b/application/Makefile @@ -99,6 +99,7 @@ RDEFS = Cardie.rdef \ data/icons/replicant/MessageReceived.rdef \ data/icons/replicant/Offline.rdef \ data/icons/replicant/Online.rdef \ + data/icons/misc/Chat.rdef \ data/icons/misc/Person.rdef \ data/icons/misc/Search.rdef \ data/icons/misc/Tool.rdef diff --git a/data/icons/misc/Chat b/data/icons/misc/Chat new file mode 100644 index 0000000000000000000000000000000000000000..27504888156813175ccaa5cf707d7b0d27ecbc3e GIT binary patch literal 2925 zcmeHJ&ubGw6rQ!&wrNbQAX4dNsR;2PREk=H(74eCp*F!5so1o3@!o?6@z<$HK?Jdf_`R8A)3l}Z&=wC)nB8yQd;9jyd*7SQ{Rh*z z>t=pJV+qa^Ob#uc%S}I+(-_lhmZ*fYK*~m&B}_xvjA0cco6)w(C}CytaArC?02uSE zs?!5dTr3t{M{1cqGgUCVfk!a)n$JDK*rz*;t_FaDxXk101VXD{Os3T_T} z70lz{hRM89tP3W+MxV^*<$h>SaohJi#}-aW(-?k9Qfg2nC|ic@`XN+UuYDOFl3tBDtYE>I53D+HGB=f< zBrm${yMB;Lr5bGJ2!3c!Mc1+y*nxhq$p&Mq*ie%vtAuH&cm{za3HkvP35=pIgkME+ zD5^biLDrC2NkQF<*h}2;#BkgHFku>+M*BSjBxz*3Rv2Ew$}9wY$r4UFeIKPrr*lmo z^h_KxTAv+UPTrd|@6zM_BCx!$><3j#aNi?a#=efL``+uvru=3`Y0?>;l1riVVyXoH z{=D4yv-PT>&*Ud3TB>fpTn-(uoyN*|wD*{(*Bq6PW|fj?3MZ)fu8c>jT12|Yy^0fX zVRXjaOpA2=9E)Z>o)f0Ahac4O&3XvG#_CZlDtu^9st$uZ z)2u_)Qt{yWuF+V-l#Jfisn07`%?ZB&s`}{P2-9fy`8p)JG~8_0ag(sLiz*eDXMqto zWs*nYUU|?orSedSn(!R#RMD@YH-x_!D7wn{)}c&9oN|IUSW}QCPoxM3!n5~~i0Gbe zIRcJih`Zc#jHfu-iTaVakK=3%q?~pm+fTO4GhPxENHB~{Bu-R0n!s>5?n*h(R-RYB zc9~p#@?zsxYFl=vZo7v!w=z>+cVAm_BNM%`)p$J>G$r@uS(191&e982?iouwr|}MaC?2pK!ZfrfTkZOGByoRz5Bk!|`u^i7C?A#Ik}Rzc z*#7+=#&3DP|L3>j7OpLRw*;y6=pV}Q@|#|8RDR=+P5Y48U*8kr_bH^nz&r2{m;D79 CA#r;E literal 0 HcmV?d00001 diff --git a/data/icons/misc/Chat.rdef b/data/icons/misc/Chat.rdef new file mode 100644 index 0000000..a6aff78 --- /dev/null +++ b/data/icons/misc/Chat.rdef @@ -0,0 +1,9 @@ +#include "application/AppResources.h" + +resource(kChatIcon) #'VICN' array { + $"6E63696604052803010100020106023E80000000000000003D800048C0004940" + $"0000F8E278FFFAECA9020106023E80000000000000003D800048000049000000" + $"FFFFFFFFF3E6AA010606BF0F3C30C36F30B8E030244024BC3A24C3453C50B8E0" + $"503C584858C160C5C14458C512C4DF544054C28454BC3A040A00010030282401" + $"158802040A0201002028240A01010030201401158802040A030100202014" +};