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-08-18 14:18:24 -05:00
|
|
|
#include <StringList.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);
|
2021-06-11 20:33:28 -05:00
|
|
|
~Conversation();
|
2021-05-24 01:47:21 -05:00
|
|
|
|
|
|
|
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-06 18:06:46 -05:00
|
|
|
void SetNotifyName(const char* name);
|
2021-06-04 13:57:04 -05:00
|
|
|
void SetNotifySubject(const char* subject);
|
2021-08-04 13:51:31 -05:00
|
|
|
bool SetNotifyIconBitmap(BBitmap* icon);
|
2021-07-27 19:51:55 -05:00
|
|
|
|
2021-05-24 01:47:21 -05:00
|
|
|
BMessenger Messenger() const;
|
|
|
|
void SetMessenger(BMessenger messenger);
|
|
|
|
|
|
|
|
ProtocolLooper* GetProtocolLooper() const;
|
|
|
|
void SetProtocolLooper(ProtocolLooper* looper);
|
|
|
|
|
2021-06-21 02:32:49 -05:00
|
|
|
BString GetName() const;
|
|
|
|
BString GetSubject() const;
|
|
|
|
|
2021-06-04 13:57:04 -05:00
|
|
|
BBitmap* ProtocolBitmap() const;
|
|
|
|
BBitmap* IconBitmap() 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);
|
2021-07-06 14:46:28 -05:00
|
|
|
Contact* GetOwnContact();
|
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-08-19 00:59:03 -05:00
|
|
|
int32 GetFlags() { return fRoomFlags; }
|
|
|
|
void SetFlags(int32 flags);
|
|
|
|
int32 DisallowedFlags() { return fDisallowedFlags; }
|
2021-06-13 02:34:11 -05:00
|
|
|
|
2021-08-31 22:04:19 -05:00
|
|
|
BPath CachePath() { return fCachePath; }
|
|
|
|
|
2021-05-24 01:47:21 -05:00
|
|
|
private:
|
2021-06-15 00:19:52 -05:00
|
|
|
void _WarnUser(BString message);
|
|
|
|
|
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-06-12 21:42:10 -05:00
|
|
|
|
2021-06-13 02:34:11 -05:00
|
|
|
void _CacheRoomFlags();
|
|
|
|
void _LoadRoomFlags();
|
|
|
|
|
2021-06-12 21:42:10 -05:00
|
|
|
void _EnsureCachePath();
|
2021-08-18 14:18:24 -05:00
|
|
|
User* _EnsureUser(BMessage* msg, bool implicit = true);
|
2021-07-29 22:00:01 -05:00
|
|
|
Role* _GetRole(BMessage* msg);
|
|
|
|
|
2021-07-31 14:57:43 -05:00
|
|
|
void _UpdateIcon(User* user = NULL);
|
|
|
|
bool _IsDefaultIcon(BBitmap* icon);
|
2021-05-24 01:47:21 -05:00
|
|
|
|
2021-07-25 14:42:38 -05:00
|
|
|
void _SortConversationList();
|
|
|
|
|
2021-06-15 00:19:52 -05:00
|
|
|
Server* _GetServer();
|
|
|
|
|
2021-05-24 01:47:21 -05:00
|
|
|
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-07-17 00:23:56 -05:00
|
|
|
int32 fNotifyMessageCount;
|
|
|
|
int32 fNotifyMentionCount;
|
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-07-27 19:51:55 -05:00
|
|
|
bool fUserIcon;
|
2021-05-24 01:47:21 -05:00
|
|
|
|
2021-06-12 21:42:10 -05:00
|
|
|
BPath fCachePath;
|
2021-05-24 14:48:25 -05:00
|
|
|
BDateTimeFormat fDateFormatter;
|
2021-05-24 14:20:57 -05:00
|
|
|
|
2021-06-13 01:16:30 -05:00
|
|
|
int32 fRoomFlags;
|
|
|
|
int32 fDisallowedFlags;
|
|
|
|
|
2021-08-18 14:18:24 -05:00
|
|
|
UserMap fUsers; // For defined, certain members of the room
|
|
|
|
BStringList fGuests; // IDs of implicitly-defined users
|
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
|
|
|
|
|