Support generally setting own nick, own UserItems

Seperate UserItems are now created for each list, too, rather than a
single one being created per-user. This functionally works a lot nicer.

But onto more important things… now setting the user's own nick should
work quite well. Finally. =w=

This has given me a good bit of trouble over the past couple of days―
setting the user's nick *worked*, but it wouldn't propagate to its
corresponding UserItem nor its UserInfoDialog. It would, however, work
with the StatusView.

These are all registered Observers of the User itself, so if one works,
they *all* should, them all being registered to the same User.

Now, if a given User isn't found in the ProtocolLooper's user-list,
the Conversation class will take it upon itself to create a new
one and add it to both of their respective lists.

So the user's own contact would be set in the ProtocolLooper― but it
*wouldn't* be added to the user-list.

Hilarity ensues as two seperate objects for the user's own contact would
be created.

Since the StatusView is registered to the ProtocolLooper's "real" own contact
slot, it would receive all updates… but since Conversations' user-lists and
items would be registered to the Conversation-created "fake" user, they
would be borked.

Simple oversight, but wow it hecked with me. :P
This commit is contained in:
Jaidyn Ann 2021-08-05 14:10:21 -05:00
parent 128ac91d56
commit f0ce3e87c6
9 changed files with 65 additions and 35 deletions

View File

@ -193,8 +193,10 @@ ProtocolLooper::GetOwnContact()
void
ProtocolLooper::SetOwnContact(Contact* contact)
{
if (contact != NULL)
if (contact != NULL) {
fMySelf = contact;
AddUser(contact);
}
}

View File

@ -279,6 +279,17 @@ Server::ImMessage(BMessage* msg)
}
break;
}
case IM_OWN_NICKNAME_SET:
{
BString nick = msg->FindString("user_name");
ProtocolLooper* looper = _LooperFromMessage(msg);
if (looper == NULL)
break;
Contact* contact = looper->GetOwnContact();
if (contact != NULL)
contact->SetNotifyName(nick.String());
break;
}
case IM_STATUS_SET:
{
int32 status;

View File

@ -22,7 +22,6 @@
#include "NotifyMessage.h"
#include "ProtocolLooper.h"
#include "ProtocolManager.h"
#include "UserItem.h"
#include "UserPopUp.h"
#include "Utils.h"
@ -33,7 +32,6 @@ User::User(BString id, BMessenger msgn)
fName(id),
fMessenger(msgn),
fLooper(NULL),
fListItem(NULL),
fItemColor(ForegroundColor(ui_color(B_LIST_BACKGROUND_COLOR))),
fStatus(STATUS_ONLINE),
fAvatarBitmap(NULL),
@ -148,17 +146,6 @@ User::ProtocolBitmap() const
}
UserItem*
User::GetListItem()
{
if (fListItem == NULL) {
fListItem = new UserItem(fName, this, (int32)fStatus);
RegisterObserver(fListItem);
}
return fListItem;
}
UserStatus
User::GetNotifyStatus() const
{

View File

@ -22,7 +22,6 @@ class BBitmap;
class Conversation;
class ProtocolLooper;
class UserItem;
class UserPopUp;
@ -51,8 +50,6 @@ public:
void SetProtocolLooper(ProtocolLooper* looper);
BBitmap* ProtocolBitmap() const;
UserItem* GetListItem();
BString GetName() const;
BBitmap* AvatarBitmap() const;
UserStatus GetNotifyStatus() const;
@ -76,8 +73,6 @@ protected:
BMessenger fMessenger;
ProtocolLooper* fLooper;
UserItem* fListItem;
BString fID;
BString fName;
BString fPersonalStatus;

View File

@ -30,7 +30,6 @@
#include "RenderView.h"
#include "SendTextView.h"
#include "User.h"
#include "UserItem.h"
#include "UserListView.h"
#include "Utils.h"
@ -273,8 +272,8 @@ ConversationView::UpdateUserList(UserMap users)
fUserList->MakeEmpty();
for (int i = 0; i < users.CountItems(); i++) {
User* user = users.ValueAt(i);
if (fUserList->HasItem(user->GetListItem()) == false) {
fUserList->AddItem(user->GetListItem());
if (fUserList->HasUser(user) == false) {
fUserList->AddUser(user);
fUserList->Sort();
}
}

View File

@ -14,12 +14,19 @@
#include "Utils.h"
UserItem::UserItem(const char* name, User* user, int32 status)
UserItem::UserItem(User* user)
:
BStringItem(name),
BStringItem(user->GetName()),
fUser(user),
fStatus(status)
fStatus(user->GetNotifyStatus())
{
user->RegisterObserver(this);
}
UserItem::~UserItem()
{
fUser->UnregisterObserver(this);
}
@ -81,5 +88,3 @@ UserItem::_GetTextColor(rgb_color highColor)
}
return highColor;
}

View File

@ -15,12 +15,13 @@ class User;
class UserItem : public BStringItem, public Observer {
public:
UserItem(const char* name, User* user, int32 status);
UserItem(User* user);
~UserItem();
void DrawItem(BView* owner, BRect frame, bool complete);
virtual void DrawItem(BView* owner, BRect frame, bool complete);
void ObserveString(int32 what, BString str);
void ObserveInteger(int32 what, int32 value);
virtual void ObserveString(int32 what, BString str);
virtual void ObserveInteger(int32 what, int32 value);
User* GetUser();
@ -32,6 +33,4 @@ private:
int fStatus;
};
#endif // USERITEM_H

View File

@ -69,6 +69,32 @@ UserListView::Sort()
}
bool
UserListView::HasUser(User* user)
{
for (int i = 0; i < CountItems(); i++)
if (user == ((UserItem*)ItemAt(i))->GetUser())
return true;
return false;
}
void
UserListView::AddUser(User* user)
{
AddItem(new UserItem(user));
}
void
UserListView::RemoveUser(User* user)
{
for (int i = 0; i < CountItems(); i++)
if (user == ((UserItem*)ItemAt(i))->GetUser())
RemoveItem(i);
}
BPopUpMenu*
UserListView::_UserPopUp()
{

View File

@ -10,7 +10,9 @@
#include "Role.h"
class BPopUpMenu;
class Conversation;
class User;
enum
@ -33,6 +35,10 @@ public:
void Sort();
bool HasUser(User* user);
void AddUser(User* user);
void RemoveUser(User* user);
void SetConversation(Conversation* chat) { fChat = chat; }
private: