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);
|
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-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);
|
Explicitly tie Conversations, Contacts, and Users to their ProtocolLoopers
Previously, all Conversations/Contacts/Users were stored in the Server,
each in their respective KeyMaps, identified solely by their
identifiers. This leads to the glaring problem of overlap― if the user
has multiple accounts, some users/rooms might be used or present in multiple
accounts at the same time.
Now, each accounts' Contacts, Conversations, and Users are stored in
its ProtocolLooper, making this overlap impossible. An oversight of only
allowing one user identifier to be stored (fMySelf) in Server was also fixed
this way.
This is the bulk of the work required for multi-account support― now,
the user can join the same XMPP room on two seperate accounts, and it
works perfectly.
2021-06-10 15:16:43 -05:00
|
|
|
BString GetOwnId();
|
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-06-13 02:34:11 -05:00
|
|
|
int32 GetFlags(int32 flags) { return fRoomFlags; }
|
|
|
|
|
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-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-05-24 14:20:57 -05:00
|
|
|
|
Explicitly tie Conversations, Contacts, and Users to their ProtocolLoopers
Previously, all Conversations/Contacts/Users were stored in the Server,
each in their respective KeyMaps, identified solely by their
identifiers. This leads to the glaring problem of overlap― if the user
has multiple accounts, some users/rooms might be used or present in multiple
accounts at the same time.
Now, each accounts' Contacts, Conversations, and Users are stored in
its ProtocolLooper, making this overlap impossible. An oversight of only
allowing one user identifier to be stored (fMySelf) in Server was also fixed
this way.
This is the bulk of the work required for multi-account support― now,
the user can join the same XMPP room on two seperate accounts, and it
works perfectly.
2021-06-10 15:16:43 -05:00
|
|
|
User* _EnsureUser(BMessage* msg);
|
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-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-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-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
|
|
|
|
|