2021-05-24 01:47:21 -05:00
|
|
|
/*
|
|
|
|
* Copyright 2021, Jaidyn Levesque <jadedctrl@teknik.io>
|
|
|
|
* All rights reserved. Distributed under the terms of the MIT license.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "Conversation.h"
|
|
|
|
|
2021-05-24 14:48:25 -05:00
|
|
|
#include <DateTimeFormat.h>
|
|
|
|
#include <Locale.h>
|
2021-05-24 19:12:42 -05:00
|
|
|
#include <StringList.h>
|
2021-05-24 14:48:25 -05:00
|
|
|
|
2021-05-24 01:47:21 -05:00
|
|
|
#include "CayaPreferences.h"
|
|
|
|
#include "CayaProtocolMessages.h"
|
2021-05-28 22:26:32 -05:00
|
|
|
#include "CayaRenderView.h"
|
2021-05-24 14:20:57 -05:00
|
|
|
#include "CayaUtils.h"
|
2021-05-27 11:15:30 -05:00
|
|
|
#include "ConversationItem.h"
|
2021-05-28 22:26:32 -05:00
|
|
|
#include "ConversationView.h"
|
2021-05-24 01:47:21 -05:00
|
|
|
#include "MainWindow.h"
|
2021-06-04 13:57:04 -05:00
|
|
|
#include "NotifyMessage.h"
|
2021-05-24 14:20:57 -05:00
|
|
|
#include "ProtocolLooper.h"
|
|
|
|
#include "ProtocolManager.h"
|
2021-05-24 01:47:21 -05:00
|
|
|
#include "Server.h"
|
|
|
|
#include "TheApp.h"
|
|
|
|
|
|
|
|
|
|
|
|
Conversation::Conversation(BString id, BMessenger msgn)
|
|
|
|
:
|
|
|
|
fID(id),
|
|
|
|
fName(id),
|
|
|
|
fMessenger(msgn),
|
2021-05-28 22:26:32 -05:00
|
|
|
fChatView(NULL),
|
2021-05-24 14:48:25 -05:00
|
|
|
fLooper(NULL),
|
2021-06-04 13:57:04 -05:00
|
|
|
fIcon(NULL),
|
2021-05-24 14:48:25 -05:00
|
|
|
fDateFormatter()
|
2021-05-24 01:47:21 -05:00
|
|
|
{
|
2021-05-27 11:15:30 -05:00
|
|
|
fConversationItem = new ConversationItem(fName.String(), this);
|
2021-06-03 23:39:50 -05:00
|
|
|
RegisterObserver(fConversationItem);
|
2021-05-24 01:47:21 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
BString
|
|
|
|
Conversation::GetId() const
|
|
|
|
{
|
|
|
|
return fID;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
Conversation::ImMessage(BMessage* msg)
|
|
|
|
{
|
|
|
|
int32 im_what = msg->FindInt32("im_what");
|
|
|
|
|
|
|
|
switch(im_what)
|
|
|
|
{
|
|
|
|
case IM_MESSAGE_RECEIVED:
|
|
|
|
{
|
|
|
|
_EnsureUser(msg);
|
2021-05-24 14:20:57 -05:00
|
|
|
_LogChatMessage(msg);
|
2021-05-28 22:26:32 -05:00
|
|
|
GetView()->MessageReceived(msg);
|
2021-05-24 01:47:21 -05:00
|
|
|
break;
|
|
|
|
}
|
2021-05-30 19:07:50 -05:00
|
|
|
case IM_MESSAGE_SENT:
|
2021-05-24 14:20:57 -05:00
|
|
|
{
|
|
|
|
_LogChatMessage(msg);
|
2021-05-30 19:07:50 -05:00
|
|
|
GetView()->MessageReceived(msg);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case IM_SEND_MESSAGE:
|
|
|
|
{
|
2021-05-24 14:20:57 -05:00
|
|
|
fMessenger.SendMessage(msg);
|
|
|
|
break;
|
|
|
|
}
|
2021-05-30 19:07:50 -05:00
|
|
|
case IM_LOGS_RECEIVED:
|
2021-05-24 01:47:21 -05:00
|
|
|
default:
|
2021-05-28 22:26:32 -05:00
|
|
|
GetView()->MessageReceived(msg);
|
2021-05-24 01:47:21 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
Conversation::ObserveString(int32 what, BString str)
|
|
|
|
{
|
2021-06-03 23:39:50 -05:00
|
|
|
GetView()->InvalidateUserList();
|
2021-05-24 01:47:21 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2021-06-03 23:39:50 -05:00
|
|
|
Conversation::ObserveInteger(int32 what, int32 value)
|
2021-05-24 01:47:21 -05:00
|
|
|
{
|
2021-06-03 23:39:50 -05:00
|
|
|
GetView()->InvalidateUserList();
|
2021-05-24 01:47:21 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2021-06-03 23:39:50 -05:00
|
|
|
Conversation::ObservePointer(int32 what, void* ptr)
|
2021-05-24 01:47:21 -05:00
|
|
|
{
|
2021-06-03 23:39:50 -05:00
|
|
|
GetView()->InvalidateUserList();
|
2021-05-24 01:47:21 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-06 18:06:46 -05:00
|
|
|
void
|
|
|
|
Conversation::SetNotifyName(const char* name)
|
|
|
|
{
|
|
|
|
if (BString(name) == fName)
|
|
|
|
return;
|
|
|
|
|
|
|
|
fName = name;
|
|
|
|
NotifyString(STR_ROOM_NAME, fName.String());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-04 13:57:04 -05:00
|
|
|
void
|
|
|
|
Conversation::SetNotifySubject(const char* subject)
|
|
|
|
{
|
|
|
|
if (BString(subject) == fSubject)
|
|
|
|
return;
|
|
|
|
|
|
|
|
fSubject = subject;
|
|
|
|
NotifyString(STR_ROOM_SUBJECT, fSubject.String());
|
|
|
|
}
|
|
|
|
|
2021-06-03 23:39:50 -05:00
|
|
|
|
2021-05-24 01:47:21 -05:00
|
|
|
BMessenger
|
|
|
|
Conversation::Messenger() const
|
|
|
|
{
|
|
|
|
return fMessenger;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
Conversation::SetMessenger(BMessenger messenger)
|
|
|
|
{
|
|
|
|
fMessenger = messenger;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ProtocolLooper*
|
|
|
|
Conversation::GetProtocolLooper() const
|
|
|
|
{
|
|
|
|
return fLooper;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
Conversation::SetProtocolLooper(ProtocolLooper* looper)
|
|
|
|
{
|
|
|
|
fLooper = looper;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-04 13:57:04 -05:00
|
|
|
BBitmap*
|
|
|
|
Conversation::ProtocolBitmap() const
|
|
|
|
{
|
|
|
|
CayaProtocol* protocol = fLooper->Protocol();
|
|
|
|
CayaProtocolAddOn* addOn
|
|
|
|
= ProtocolManager::Get()->ProtocolAddOn(protocol->Signature());
|
|
|
|
|
|
|
|
return addOn->ProtoIcon();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
BBitmap*
|
|
|
|
Conversation::IconBitmap() const
|
|
|
|
{
|
|
|
|
return fIcon;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-05-24 01:47:21 -05:00
|
|
|
BString
|
|
|
|
Conversation::GetName() const
|
|
|
|
{
|
|
|
|
return fName;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
Support for "Roles" (user, moderator, admin, etc.)
Add scaffodling support for arbitrary roles and permission-based (and
varying!) UI.
A new class, Role, represents a user's role in a given room, with three
values:
* The role's title
* The role's permission-set
* The role's priority
The permission set is a bitmask value for various permissions (e.g.,
PERM_WRITE, PERM_BAN, etc), and priority is position in the hierarchy.
A user with higher priority (and PERM_BAN) can ban a user with lower
priority, but not vice-versa. Two users with the same priority can't
ban/kick/mute each other, etc.
These permissions should be used to determine what UI elements are
displayed― if the user doesn't have permission to ban users, then a
"Ban" button shouldn't exist. If the user is muted, they shouldn't be
able to type. So on and so forth.
For now, permissions are sent with a IM_ROLECHANGE message and stored
by the Conversation, but aren't really in use yet.
This system should be flexible groundwork to account for the varying
administrative hierarchies and norms of different protocols.
2021-06-06 00:41:45 -05:00
|
|
|
ConversationView*
|
|
|
|
Conversation::GetView()
|
|
|
|
{
|
|
|
|
if (fChatView != NULL)
|
|
|
|
return fChatView;
|
|
|
|
|
|
|
|
fChatView = new ConversationView(this);
|
|
|
|
|
|
|
|
if (fLooper->Protocol()->SaveLogs() == false)
|
|
|
|
return fChatView;
|
|
|
|
|
2021-06-06 12:02:26 -05:00
|
|
|
BMessage logMsg;
|
|
|
|
if (_GetChatLogs(&logMsg) == B_OK)
|
|
|
|
fChatView->MessageReceived(&logMsg);
|
Support for "Roles" (user, moderator, admin, etc.)
Add scaffodling support for arbitrary roles and permission-based (and
varying!) UI.
A new class, Role, represents a user's role in a given room, with three
values:
* The role's title
* The role's permission-set
* The role's priority
The permission set is a bitmask value for various permissions (e.g.,
PERM_WRITE, PERM_BAN, etc), and priority is position in the hierarchy.
A user with higher priority (and PERM_BAN) can ban a user with lower
priority, but not vice-versa. Two users with the same priority can't
ban/kick/mute each other, etc.
These permissions should be used to determine what UI elements are
displayed― if the user doesn't have permission to ban users, then a
"Ban" button shouldn't exist. If the user is muted, they shouldn't be
able to type. So on and so forth.
For now, permissions are sent with a IM_ROLECHANGE message and stored
by the Conversation, but aren't really in use yet.
This system should be flexible groundwork to account for the varying
administrative hierarchies and norms of different protocols.
2021-06-06 00:41:45 -05:00
|
|
|
|
|
|
|
RegisterObserver(fChatView);
|
|
|
|
return fChatView;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
Conversation::ShowView(bool typing, bool userAction)
|
|
|
|
{
|
|
|
|
((TheApp*)be_app)->GetMainWindow()->SetConversation(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ConversationItem*
|
|
|
|
Conversation::GetListItem()
|
|
|
|
{
|
|
|
|
return fConversationItem;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-05-24 01:47:21 -05:00
|
|
|
UserMap
|
|
|
|
Conversation::Users()
|
|
|
|
{
|
|
|
|
return fUsers;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-05-31 11:56:45 -05:00
|
|
|
User*
|
2021-05-24 01:47:21 -05:00
|
|
|
Conversation::UserById(BString id)
|
|
|
|
{
|
|
|
|
bool found = false;
|
|
|
|
return fUsers.ValueFor(id, &found);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
Conversation::AddUser(User* user)
|
|
|
|
{
|
|
|
|
BMessage msg;
|
|
|
|
msg.AddString("user_id", user->GetId());
|
2021-06-02 16:53:03 -05:00
|
|
|
msg.AddString("user_name", user->GetName());
|
2021-05-24 01:47:21 -05:00
|
|
|
_EnsureUser(&msg);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-02 16:53:03 -05:00
|
|
|
void
|
|
|
|
Conversation::RemoveUser(User* user)
|
|
|
|
{
|
|
|
|
fUsers.RemoveItemFor(user->GetId());
|
2021-06-03 23:39:50 -05:00
|
|
|
user->UnregisterObserver(this);
|
2021-06-02 16:53:03 -05:00
|
|
|
GetView()->UpdateUserList(fUsers);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
Support for "Roles" (user, moderator, admin, etc.)
Add scaffodling support for arbitrary roles and permission-based (and
varying!) UI.
A new class, Role, represents a user's role in a given room, with three
values:
* The role's title
* The role's permission-set
* The role's priority
The permission set is a bitmask value for various permissions (e.g.,
PERM_WRITE, PERM_BAN, etc), and priority is position in the hierarchy.
A user with higher priority (and PERM_BAN) can ban a user with lower
priority, but not vice-versa. Two users with the same priority can't
ban/kick/mute each other, etc.
These permissions should be used to determine what UI elements are
displayed― if the user doesn't have permission to ban users, then a
"Ban" button shouldn't exist. If the user is muted, they shouldn't be
able to type. So on and so forth.
For now, permissions are sent with a IM_ROLECHANGE message and stored
by the Conversation, but aren't really in use yet.
This system should be flexible groundwork to account for the varying
administrative hierarchies and norms of different protocols.
2021-06-06 00:41:45 -05:00
|
|
|
BString
|
|
|
|
Conversation::OwnUserId()
|
2021-05-30 20:45:24 -05:00
|
|
|
{
|
Support for "Roles" (user, moderator, admin, etc.)
Add scaffodling support for arbitrary roles and permission-based (and
varying!) UI.
A new class, Role, represents a user's role in a given room, with three
values:
* The role's title
* The role's permission-set
* The role's priority
The permission set is a bitmask value for various permissions (e.g.,
PERM_WRITE, PERM_BAN, etc), and priority is position in the hierarchy.
A user with higher priority (and PERM_BAN) can ban a user with lower
priority, but not vice-versa. Two users with the same priority can't
ban/kick/mute each other, etc.
These permissions should be used to determine what UI elements are
displayed― if the user doesn't have permission to ban users, then a
"Ban" button shouldn't exist. If the user is muted, they shouldn't be
able to type. So on and so forth.
For now, permissions are sent with a IM_ROLECHANGE message and stored
by the Conversation, but aren't really in use yet.
This system should be flexible groundwork to account for the varying
administrative hierarchies and norms of different protocols.
2021-06-06 00:41:45 -05:00
|
|
|
return _GetServer()->GetOwnContact();
|
2021-05-30 20:45:24 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
Support for "Roles" (user, moderator, admin, etc.)
Add scaffodling support for arbitrary roles and permission-based (and
varying!) UI.
A new class, Role, represents a user's role in a given room, with three
values:
* The role's title
* The role's permission-set
* The role's priority
The permission set is a bitmask value for various permissions (e.g.,
PERM_WRITE, PERM_BAN, etc), and priority is position in the hierarchy.
A user with higher priority (and PERM_BAN) can ban a user with lower
priority, but not vice-versa. Two users with the same priority can't
ban/kick/mute each other, etc.
These permissions should be used to determine what UI elements are
displayed― if the user doesn't have permission to ban users, then a
"Ban" button shouldn't exist. If the user is muted, they shouldn't be
able to type. So on and so forth.
For now, permissions are sent with a IM_ROLECHANGE message and stored
by the Conversation, but aren't really in use yet.
This system should be flexible groundwork to account for the varying
administrative hierarchies and norms of different protocols.
2021-06-06 00:41:45 -05:00
|
|
|
void
|
|
|
|
Conversation::SetRole(BString id, Role* role)
|
2021-05-24 01:47:21 -05:00
|
|
|
{
|
Support for "Roles" (user, moderator, admin, etc.)
Add scaffodling support for arbitrary roles and permission-based (and
varying!) UI.
A new class, Role, represents a user's role in a given room, with three
values:
* The role's title
* The role's permission-set
* The role's priority
The permission set is a bitmask value for various permissions (e.g.,
PERM_WRITE, PERM_BAN, etc), and priority is position in the hierarchy.
A user with higher priority (and PERM_BAN) can ban a user with lower
priority, but not vice-versa. Two users with the same priority can't
ban/kick/mute each other, etc.
These permissions should be used to determine what UI elements are
displayed― if the user doesn't have permission to ban users, then a
"Ban" button shouldn't exist. If the user is muted, they shouldn't be
able to type. So on and so forth.
For now, permissions are sent with a IM_ROLECHANGE message and stored
by the Conversation, but aren't really in use yet.
This system should be flexible groundwork to account for the varying
administrative hierarchies and norms of different protocols.
2021-06-06 00:41:45 -05:00
|
|
|
Role* oldRole = fRoles.ValueFor(id);
|
|
|
|
if (oldRole != NULL) {
|
|
|
|
fRoles.RemoveItemFor(id);
|
|
|
|
delete oldRole;
|
|
|
|
}
|
2021-05-30 19:07:50 -05:00
|
|
|
|
Support for "Roles" (user, moderator, admin, etc.)
Add scaffodling support for arbitrary roles and permission-based (and
varying!) UI.
A new class, Role, represents a user's role in a given room, with three
values:
* The role's title
* The role's permission-set
* The role's priority
The permission set is a bitmask value for various permissions (e.g.,
PERM_WRITE, PERM_BAN, etc), and priority is position in the hierarchy.
A user with higher priority (and PERM_BAN) can ban a user with lower
priority, but not vice-versa. Two users with the same priority can't
ban/kick/mute each other, etc.
These permissions should be used to determine what UI elements are
displayed― if the user doesn't have permission to ban users, then a
"Ban" button shouldn't exist. If the user is muted, they shouldn't be
able to type. So on and so forth.
For now, permissions are sent with a IM_ROLECHANGE message and stored
by the Conversation, but aren't really in use yet.
This system should be flexible groundwork to account for the varying
administrative hierarchies and norms of different protocols.
2021-06-06 00:41:45 -05:00
|
|
|
fRoles.AddItem(id, role);
|
2021-05-24 01:47:21 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
Support for "Roles" (user, moderator, admin, etc.)
Add scaffodling support for arbitrary roles and permission-based (and
varying!) UI.
A new class, Role, represents a user's role in a given room, with three
values:
* The role's title
* The role's permission-set
* The role's priority
The permission set is a bitmask value for various permissions (e.g.,
PERM_WRITE, PERM_BAN, etc), and priority is position in the hierarchy.
A user with higher priority (and PERM_BAN) can ban a user with lower
priority, but not vice-versa. Two users with the same priority can't
ban/kick/mute each other, etc.
These permissions should be used to determine what UI elements are
displayed― if the user doesn't have permission to ban users, then a
"Ban" button shouldn't exist. If the user is muted, they shouldn't be
able to type. So on and so forth.
For now, permissions are sent with a IM_ROLECHANGE message and stored
by the Conversation, but aren't really in use yet.
This system should be flexible groundwork to account for the varying
administrative hierarchies and norms of different protocols.
2021-06-06 00:41:45 -05:00
|
|
|
Role*
|
|
|
|
Conversation::GetRole(BString id)
|
2021-05-30 20:45:24 -05:00
|
|
|
{
|
Support for "Roles" (user, moderator, admin, etc.)
Add scaffodling support for arbitrary roles and permission-based (and
varying!) UI.
A new class, Role, represents a user's role in a given room, with three
values:
* The role's title
* The role's permission-set
* The role's priority
The permission set is a bitmask value for various permissions (e.g.,
PERM_WRITE, PERM_BAN, etc), and priority is position in the hierarchy.
A user with higher priority (and PERM_BAN) can ban a user with lower
priority, but not vice-versa. Two users with the same priority can't
ban/kick/mute each other, etc.
These permissions should be used to determine what UI elements are
displayed― if the user doesn't have permission to ban users, then a
"Ban" button shouldn't exist. If the user is muted, they shouldn't be
able to type. So on and so forth.
For now, permissions are sent with a IM_ROLECHANGE message and stored
by the Conversation, but aren't really in use yet.
This system should be flexible groundwork to account for the varying
administrative hierarchies and norms of different protocols.
2021-06-06 00:41:45 -05:00
|
|
|
return fRoles.ValueFor(id);
|
2021-05-30 20:45:24 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-05-24 14:20:57 -05:00
|
|
|
void
|
|
|
|
Conversation::_LogChatMessage(BMessage* msg)
|
|
|
|
{
|
2021-05-24 14:48:25 -05:00
|
|
|
BString date;
|
|
|
|
fDateFormatter.Format(date, time(0), B_SHORT_DATE_FORMAT, B_MEDIUM_TIME_FORMAT);
|
|
|
|
|
2021-05-24 14:20:57 -05:00
|
|
|
BString id = msg->FindString("user_id");
|
2021-06-06 12:02:26 -05:00
|
|
|
BString body = msg->FindString("body");
|
|
|
|
|
|
|
|
// Binary logs
|
|
|
|
// TODO: Don't hardcode 21, expose maximum as a setting
|
|
|
|
BStringList users, bodies;
|
|
|
|
|
|
|
|
BMessage logMsg;
|
|
|
|
if (_GetChatLogs(&logMsg) == B_OK) {
|
|
|
|
logMsg.FindStrings("body", &bodies);
|
|
|
|
logMsg.FindStrings("user_id", &users);
|
|
|
|
bodies.Remove(21);
|
|
|
|
users.Remove(21);
|
|
|
|
bodies.Add(body, 0);
|
|
|
|
users.Add(id, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
BMessage newLogMsg(IM_MESSAGE);
|
|
|
|
newLogMsg.AddInt32("im_what", IM_LOGS_RECEIVED);
|
|
|
|
newLogMsg.AddStrings("body", bodies);
|
|
|
|
newLogMsg.AddStrings("user_id", users);
|
|
|
|
|
|
|
|
BFile logFile(fLogPath.Path(), B_READ_WRITE | B_OPEN_AT_END | B_CREATE_FILE);
|
|
|
|
WriteAttributeMessage(&logFile, "logs", &newLogMsg);
|
2021-05-24 14:20:57 -05:00
|
|
|
|
2021-06-06 12:02:26 -05:00
|
|
|
// Plain-text logs
|
|
|
|
BString uname;
|
2021-05-24 14:20:57 -05:00
|
|
|
if (id.IsEmpty() == false)
|
|
|
|
uname = UserById(id)->GetName();
|
|
|
|
else
|
|
|
|
uname = "You";
|
|
|
|
|
2021-05-24 14:48:25 -05:00
|
|
|
BString logLine("[");
|
|
|
|
logLine << date;
|
|
|
|
logLine << "] ";
|
|
|
|
logLine << uname;
|
2021-05-24 14:20:57 -05:00
|
|
|
logLine << ": ";
|
2021-06-06 12:02:26 -05:00
|
|
|
logLine << body;
|
2021-05-24 14:20:57 -05:00
|
|
|
logLine << "\n";
|
|
|
|
|
2021-06-06 12:02:26 -05:00
|
|
|
logFile.Write(logLine.String(), logLine.Length());
|
2021-05-24 19:12:42 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-06 12:02:26 -05:00
|
|
|
status_t
|
|
|
|
Conversation::_GetChatLogs(BMessage* msg)
|
2021-05-24 19:12:42 -05:00
|
|
|
{
|
|
|
|
_EnsureLogPath();
|
|
|
|
|
|
|
|
BFile logFile(fLogPath.Path(), B_READ_WRITE | B_CREATE_FILE);
|
|
|
|
|
2021-06-06 12:02:26 -05:00
|
|
|
return ReadAttributeMessage(&logFile, "logs", msg);
|
2021-05-24 14:20:57 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
Conversation::_EnsureLogPath()
|
|
|
|
{
|
|
|
|
if (fLogPath.InitCheck() == B_OK)
|
|
|
|
return;
|
|
|
|
|
|
|
|
const char* sig = fLooper->Protocol()->Signature();
|
|
|
|
CayaProtocolAddOn* protoAdd = ProtocolManager::Get()->ProtocolAddOn(sig);
|
|
|
|
|
|
|
|
fLogPath.SetTo(CayaLogPath(protoAdd->Signature(), protoAdd->ProtoSignature()));
|
|
|
|
fLogPath.Append(fID);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-05-31 11:56:45 -05:00
|
|
|
User*
|
2021-05-24 01:47:21 -05:00
|
|
|
Conversation::_EnsureUser(BMessage* msg)
|
|
|
|
{
|
|
|
|
BString id = msg->FindString("user_id");
|
|
|
|
if (id.IsEmpty() == true) return NULL;
|
|
|
|
|
2021-05-31 11:56:45 -05:00
|
|
|
User* user = UserById(id);
|
|
|
|
User* serverUser = _GetServer()->UserById(id);
|
2021-05-24 01:47:21 -05:00
|
|
|
|
|
|
|
if (user == NULL && serverUser != NULL) {
|
|
|
|
fUsers.AddItem(id, serverUser);
|
|
|
|
user = serverUser;
|
2021-05-31 10:50:43 -05:00
|
|
|
GetView()->UpdateUserList(fUsers);
|
2021-05-24 01:47:21 -05:00
|
|
|
}
|
|
|
|
else if (user == NULL) {
|
2021-05-31 11:56:45 -05:00
|
|
|
user = new User(id, _GetServer()->Looper());
|
2021-05-24 01:47:21 -05:00
|
|
|
user->SetProtocolLooper(fLooper);
|
|
|
|
|
2021-05-31 11:56:45 -05:00
|
|
|
_GetServer()->AddUser(user);
|
2021-05-24 01:47:21 -05:00
|
|
|
fUsers.AddItem(id, user);
|
2021-05-31 10:50:43 -05:00
|
|
|
GetView()->UpdateUserList(fUsers);
|
2021-05-24 01:47:21 -05:00
|
|
|
}
|
2021-06-03 23:39:50 -05:00
|
|
|
user->RegisterObserver(this);
|
2021-05-24 01:47:21 -05:00
|
|
|
return user;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Server*
|
|
|
|
Conversation::_GetServer()
|
|
|
|
{
|
|
|
|
return ((TheApp*)be_app)->GetMainWindow()->GetServer();
|
|
|
|
}
|
|
|
|
|
|
|
|
|