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.
|
|
|
|
*/
|
|
|
|
#ifndef CONVERSATION_H
|
|
|
|
#define CONVERSATION_H
|
|
|
|
|
2021-05-24 14:48:25 -05:00
|
|
|
#include <DateTimeFormat.h>
|
2021-05-24 01:47:21 -05:00
|
|
|
#include <Messenger.h>
|
2021-05-24 14:20:57 -05:00
|
|
|
#include <Path.h>
|
2021-05-24 01:47:21 -05:00
|
|
|
|
|
|
|
#include <libsupport/KeyMap.h>
|
|
|
|
|
2021-05-27 11:15:30 -05:00
|
|
|
#include "Observer.h"
|
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
|
|
|
#include "Role.h"
|
2021-05-31 11:56:45 -05:00
|
|
|
#include "Server.h"
|
2021-05-24 01:47:21 -05:00
|
|
|
#include "User.h"
|
|
|
|
|
2021-06-04 13:57:04 -05:00
|
|
|
class BBitmap;
|
2021-05-27 11:15:30 -05:00
|
|
|
class ConversationItem;
|
2021-05-28 22:26:32 -05:00
|
|
|
class ConversationView;
|
2021-05-24 01:47:21 -05:00
|
|
|
class ProtocolLooper;
|
|
|
|
class Server;
|
|
|
|
|
|
|
|
|
2021-05-31 11:56:45 -05:00
|
|
|
typedef KeyMap<BString, User*> UserMap;
|
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
|
|
|
typedef KeyMap<BString, Role*> RoleMap;
|
2021-05-24 01:47:21 -05:00
|
|
|
|
|
|
|
|
2021-06-03 23:39:50 -05:00
|
|
|
class Conversation : public Notifier, public Observer {
|
2021-05-24 01:47:21 -05:00
|
|
|
public:
|
|
|
|
Conversation(BString id, BMessenger msgn);
|
|
|
|
|
|
|
|
BString GetId() const;
|
|
|
|
|
|
|
|
void ImMessage(BMessage* msg);
|
|
|
|
|
2021-06-03 23:39:50 -05:00
|
|
|
// Tell the ConversationView to invalidate user list
|
2021-05-24 01:47:21 -05:00
|
|
|
void ObserveString(int32 what, BString str);
|
|
|
|
void ObserveInteger(int32 what, int32 value);
|
|
|
|
void ObservePointer(int32 what, void* ptr);
|
|
|
|
|
2021-06-04 13:57:04 -05:00
|
|
|
void SetNotifySubject(const char* subject);
|
|
|
|
|
2021-05-24 01:47:21 -05:00
|
|
|
BMessenger Messenger() const;
|
|
|
|
void SetMessenger(BMessenger messenger);
|
|
|
|
|
|
|
|
ProtocolLooper* GetProtocolLooper() const;
|
|
|
|
void SetProtocolLooper(ProtocolLooper* looper);
|
|
|
|
|
2021-06-04 13:57:04 -05:00
|
|
|
BBitmap* ProtocolBitmap() const;
|
|
|
|
BBitmap* IconBitmap() const;
|
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 GetName() const;
|
2021-05-30 20:45:24 -05:00
|
|
|
|
|
|
|
ConversationView* GetView();
|
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 ShowView(bool typing, bool userAction);
|
2021-05-30 20:45:24 -05:00
|
|
|
ConversationItem* GetListItem();
|
2021-05-27 11:15:30 -05:00
|
|
|
|
2021-05-24 01:47:21 -05:00
|
|
|
UserMap Users();
|
2021-05-31 11:56:45 -05:00
|
|
|
User* UserById(BString id);
|
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 OwnUserId();
|
2021-06-02 16:53:03 -05:00
|
|
|
|
2021-05-24 01:47:21 -05:00
|
|
|
void AddUser(User* user);
|
2021-06-02 16:53:03 -05:00
|
|
|
void RemoveUser(User* user);
|
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
|
|
|
void SetRole(BString id, Role* role);
|
|
|
|
Role* GetRole(BString id);
|
|
|
|
|
2021-05-24 01:47:21 -05:00
|
|
|
private:
|
2021-05-24 14:20:57 -05:00
|
|
|
void _LogChatMessage(BMessage* msg);
|
2021-06-06 12:02:26 -05:00
|
|
|
status_t _GetChatLogs(BMessage* msg);
|
2021-05-24 14:20:57 -05:00
|
|
|
void _EnsureLogPath();
|
|
|
|
|
2021-05-31 11:56:45 -05:00
|
|
|
User* _EnsureUser(BMessage* msg);
|
2021-05-24 01:47:21 -05:00
|
|
|
Server* _GetServer();
|
|
|
|
|
|
|
|
BMessenger fMessenger;
|
|
|
|
ProtocolLooper* fLooper;
|
2021-05-28 22:26:32 -05:00
|
|
|
ConversationView* fChatView;
|
2021-05-27 11:15:30 -05:00
|
|
|
ConversationItem* fConversationItem;
|
2021-05-24 01:47:21 -05:00
|
|
|
|
|
|
|
BString fID;
|
|
|
|
BString fName;
|
2021-06-04 13:57:04 -05:00
|
|
|
BString fSubject;
|
|
|
|
|
|
|
|
BBitmap* fIcon;
|
2021-05-24 01:47:21 -05:00
|
|
|
|
2021-05-24 14:20:57 -05:00
|
|
|
BPath fLogPath;
|
2021-05-24 14:48:25 -05:00
|
|
|
BDateTimeFormat fDateFormatter;
|
2021-05-24 14:20:57 -05:00
|
|
|
|
2021-05-24 01:47:21 -05:00
|
|
|
UserMap 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
|
|
|
RoleMap fRoles;
|
2021-05-24 01:47:21 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#endif // CONVERSATION_H
|
|
|
|
|