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:
parent
128ac91d56
commit
f0ce3e87c6
|
@ -193,8 +193,10 @@ ProtocolLooper::GetOwnContact()
|
||||||
void
|
void
|
||||||
ProtocolLooper::SetOwnContact(Contact* contact)
|
ProtocolLooper::SetOwnContact(Contact* contact)
|
||||||
{
|
{
|
||||||
if (contact != NULL)
|
if (contact != NULL) {
|
||||||
fMySelf = contact;
|
fMySelf = contact;
|
||||||
|
AddUser(contact);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -279,6 +279,17 @@ Server::ImMessage(BMessage* msg)
|
||||||
}
|
}
|
||||||
break;
|
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:
|
case IM_STATUS_SET:
|
||||||
{
|
{
|
||||||
int32 status;
|
int32 status;
|
||||||
|
|
|
@ -22,7 +22,6 @@
|
||||||
#include "NotifyMessage.h"
|
#include "NotifyMessage.h"
|
||||||
#include "ProtocolLooper.h"
|
#include "ProtocolLooper.h"
|
||||||
#include "ProtocolManager.h"
|
#include "ProtocolManager.h"
|
||||||
#include "UserItem.h"
|
|
||||||
#include "UserPopUp.h"
|
#include "UserPopUp.h"
|
||||||
#include "Utils.h"
|
#include "Utils.h"
|
||||||
|
|
||||||
|
@ -33,7 +32,6 @@ User::User(BString id, BMessenger msgn)
|
||||||
fName(id),
|
fName(id),
|
||||||
fMessenger(msgn),
|
fMessenger(msgn),
|
||||||
fLooper(NULL),
|
fLooper(NULL),
|
||||||
fListItem(NULL),
|
|
||||||
fItemColor(ForegroundColor(ui_color(B_LIST_BACKGROUND_COLOR))),
|
fItemColor(ForegroundColor(ui_color(B_LIST_BACKGROUND_COLOR))),
|
||||||
fStatus(STATUS_ONLINE),
|
fStatus(STATUS_ONLINE),
|
||||||
fAvatarBitmap(NULL),
|
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
|
UserStatus
|
||||||
User::GetNotifyStatus() const
|
User::GetNotifyStatus() const
|
||||||
{
|
{
|
||||||
|
|
|
@ -22,7 +22,6 @@ class BBitmap;
|
||||||
|
|
||||||
class Conversation;
|
class Conversation;
|
||||||
class ProtocolLooper;
|
class ProtocolLooper;
|
||||||
class UserItem;
|
|
||||||
class UserPopUp;
|
class UserPopUp;
|
||||||
|
|
||||||
|
|
||||||
|
@ -51,8 +50,6 @@ public:
|
||||||
void SetProtocolLooper(ProtocolLooper* looper);
|
void SetProtocolLooper(ProtocolLooper* looper);
|
||||||
BBitmap* ProtocolBitmap() const;
|
BBitmap* ProtocolBitmap() const;
|
||||||
|
|
||||||
UserItem* GetListItem();
|
|
||||||
|
|
||||||
BString GetName() const;
|
BString GetName() const;
|
||||||
BBitmap* AvatarBitmap() const;
|
BBitmap* AvatarBitmap() const;
|
||||||
UserStatus GetNotifyStatus() const;
|
UserStatus GetNotifyStatus() const;
|
||||||
|
@ -76,8 +73,6 @@ protected:
|
||||||
BMessenger fMessenger;
|
BMessenger fMessenger;
|
||||||
ProtocolLooper* fLooper;
|
ProtocolLooper* fLooper;
|
||||||
|
|
||||||
UserItem* fListItem;
|
|
||||||
|
|
||||||
BString fID;
|
BString fID;
|
||||||
BString fName;
|
BString fName;
|
||||||
BString fPersonalStatus;
|
BString fPersonalStatus;
|
||||||
|
|
|
@ -30,7 +30,6 @@
|
||||||
#include "RenderView.h"
|
#include "RenderView.h"
|
||||||
#include "SendTextView.h"
|
#include "SendTextView.h"
|
||||||
#include "User.h"
|
#include "User.h"
|
||||||
#include "UserItem.h"
|
|
||||||
#include "UserListView.h"
|
#include "UserListView.h"
|
||||||
#include "Utils.h"
|
#include "Utils.h"
|
||||||
|
|
||||||
|
@ -273,8 +272,8 @@ ConversationView::UpdateUserList(UserMap users)
|
||||||
fUserList->MakeEmpty();
|
fUserList->MakeEmpty();
|
||||||
for (int i = 0; i < users.CountItems(); i++) {
|
for (int i = 0; i < users.CountItems(); i++) {
|
||||||
User* user = users.ValueAt(i);
|
User* user = users.ValueAt(i);
|
||||||
if (fUserList->HasItem(user->GetListItem()) == false) {
|
if (fUserList->HasUser(user) == false) {
|
||||||
fUserList->AddItem(user->GetListItem());
|
fUserList->AddUser(user);
|
||||||
fUserList->Sort();
|
fUserList->Sort();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,12 +14,19 @@
|
||||||
#include "Utils.h"
|
#include "Utils.h"
|
||||||
|
|
||||||
|
|
||||||
UserItem::UserItem(const char* name, User* user, int32 status)
|
UserItem::UserItem(User* user)
|
||||||
:
|
:
|
||||||
BStringItem(name),
|
BStringItem(user->GetName()),
|
||||||
fUser(user),
|
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;
|
return highColor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -15,12 +15,13 @@ class User;
|
||||||
|
|
||||||
class UserItem : public BStringItem, public Observer {
|
class UserItem : public BStringItem, public Observer {
|
||||||
public:
|
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);
|
virtual void ObserveString(int32 what, BString str);
|
||||||
void ObserveInteger(int32 what, int32 value);
|
virtual void ObserveInteger(int32 what, int32 value);
|
||||||
|
|
||||||
User* GetUser();
|
User* GetUser();
|
||||||
|
|
||||||
|
@ -32,6 +33,4 @@ private:
|
||||||
int fStatus;
|
int fStatus;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#endif // USERITEM_H
|
#endif // USERITEM_H
|
||||||
|
|
||||||
|
|
|
@ -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*
|
BPopUpMenu*
|
||||||
UserListView::_UserPopUp()
|
UserListView::_UserPopUp()
|
||||||
{
|
{
|
||||||
|
|
|
@ -10,7 +10,9 @@
|
||||||
#include "Role.h"
|
#include "Role.h"
|
||||||
|
|
||||||
class BPopUpMenu;
|
class BPopUpMenu;
|
||||||
|
|
||||||
class Conversation;
|
class Conversation;
|
||||||
|
class User;
|
||||||
|
|
||||||
|
|
||||||
enum
|
enum
|
||||||
|
@ -33,6 +35,10 @@ public:
|
||||||
|
|
||||||
void Sort();
|
void Sort();
|
||||||
|
|
||||||
|
bool HasUser(User* user);
|
||||||
|
void AddUser(User* user);
|
||||||
|
void RemoveUser(User* user);
|
||||||
|
|
||||||
void SetConversation(Conversation* chat) { fChat = chat; }
|
void SetConversation(Conversation* chat) { fChat = chat; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
Ŝarĝante…
Reference in New Issue