Display message in chat when user changes nick
This commit is contained in:
parent
35cd5cbc8f
commit
12215266d0
|
@ -84,7 +84,8 @@ enum im_what_code {
|
|||
* Messages related changes in general users.
|
||||
*/
|
||||
|
||||
/*! User's nick has changed →App */
|
||||
/*! User's nick has changed →App
|
||||
Requires: String "user_id", String "user_name" */
|
||||
IM_USER_NICKNAME_SET = 40,
|
||||
|
||||
/*! Received new status for user →App
|
||||
|
@ -256,7 +257,7 @@ enum im_what_code {
|
|||
|
||||
/*! User has explicitly joined →App
|
||||
Requires: String "chat_id", String "user_id"
|
||||
Accepts: String "body" */
|
||||
Accepts: String "body", String "user_name" */
|
||||
IM_ROOM_PARTICIPANT_JOINED = 160,
|
||||
|
||||
/*! A user left the room →App
|
||||
|
|
|
@ -54,9 +54,8 @@ Conversation::~Conversation()
|
|||
{
|
||||
((TheApp*)be_app)->GetMainWindow()->RemoveConversation(this);
|
||||
|
||||
ProtocolLooper* looper = GetProtocolLooper();
|
||||
if (looper != NULL)
|
||||
looper->RemoveConversation(this);
|
||||
if (fLooper != NULL)
|
||||
fLooper->RemoveConversation(this);
|
||||
|
||||
delete fChatView;
|
||||
delete fConversationItem;
|
||||
|
@ -237,6 +236,27 @@ Conversation::ImMessage(BMessage* msg)
|
|||
GetView()->MessageReceived(msg);
|
||||
break;
|
||||
}
|
||||
case IM_USER_NICKNAME_SET:
|
||||
{
|
||||
BString user_id = msg->FindString("user_id");
|
||||
BString user_name = msg->FindString("user_name");
|
||||
if (user_id.IsEmpty() == false && user_name.IsEmpty() == false) {
|
||||
User* user = UserById(user_id);
|
||||
|
||||
BString text(B_TRANSLATE("** %old% has changed their nick to %new%."));
|
||||
text.ReplaceAll("%new%", user_name);
|
||||
if (user != NULL)
|
||||
text.ReplaceAll("%old%", user->GetName());
|
||||
else
|
||||
text.ReplaceAll("%old%", user_id);
|
||||
|
||||
BMessage* notify = new BMessage(IM_MESSAGE);
|
||||
notify->AddInt32("im_what", IM_MESSAGE_RECEIVED);
|
||||
notify->AddString("body", text);
|
||||
GetView()->MessageReceived(notify);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case IM_LOGS_RECEIVED:
|
||||
default:
|
||||
GetView()->MessageReceived(msg);
|
||||
|
@ -611,9 +631,8 @@ Conversation::_EnsureUser(BMessage* msg)
|
|||
NotifyInteger(INT_ROOM_MEMBERS, fUsers.CountItems());
|
||||
}
|
||||
|
||||
if (name.IsEmpty() == false) {
|
||||
if (name.IsEmpty() == false && user->GetName() != name)
|
||||
user->SetNotifyName(name);
|
||||
}
|
||||
user->RegisterObserver(this);
|
||||
return user;
|
||||
}
|
||||
|
|
|
@ -288,15 +288,32 @@ Server::ImMessage(BMessage* msg)
|
|||
}
|
||||
case IM_OWN_NICKNAME_SET:
|
||||
{
|
||||
BString nick = msg->FindString("user_name");
|
||||
BString nick;
|
||||
ProtocolLooper* looper = _LooperFromMessage(msg);
|
||||
if (looper == NULL)
|
||||
if (looper == NULL || msg->FindString("user_name", &nick) != B_OK)
|
||||
break;
|
||||
Contact* contact = looper->GetOwnContact();
|
||||
if (contact != NULL)
|
||||
contact->SetNotifyName(nick.String());
|
||||
break;
|
||||
}
|
||||
case IM_USER_NICKNAME_SET:
|
||||
{
|
||||
BString nick;
|
||||
if (msg->FindString("user_name", &nick) != B_OK)
|
||||
return B_SKIP_MESSAGE;
|
||||
|
||||
User* user = _EnsureUser(msg);
|
||||
if (user == NULL)
|
||||
break;
|
||||
|
||||
ChatMap conv = user->Conversations();
|
||||
for (int i = 0; i < conv.CountItems(); i++)
|
||||
conv.ValueAt(i)->ImMessage(msg);
|
||||
|
||||
user->SetNotifyName(nick);
|
||||
break;
|
||||
}
|
||||
case IM_USER_STATUS_SET:
|
||||
{
|
||||
int32 status;
|
||||
|
@ -984,6 +1001,7 @@ Server::_EnsureConversation(BMessage* message)
|
|||
if (item == NULL) {
|
||||
item = new Conversation(chat_id, Looper());
|
||||
item->SetProtocolLooper(looper);
|
||||
if (looper->GetOwnContact() != NULL)
|
||||
item->AddUser(looper->GetOwnContact());
|
||||
looper->AddConversation(item);
|
||||
|
||||
|
|
Ŝarĝante…
Reference in New Issue