6e1ca87890
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.
98 lines
2.0 KiB
C++
98 lines
2.0 KiB
C++
/*
|
|
* Copyright 2021, Jaidyn Levesque <jadedctrl@teknik.io>
|
|
* All rights reserved. Distributed under the terms of the MIT license.
|
|
*/
|
|
#ifndef CONVERSATION_H
|
|
#define CONVERSATION_H
|
|
|
|
#include <DateTimeFormat.h>
|
|
#include <Messenger.h>
|
|
#include <Path.h>
|
|
|
|
#include <libsupport/KeyMap.h>
|
|
|
|
#include "Observer.h"
|
|
#include "Role.h"
|
|
#include "Server.h"
|
|
#include "User.h"
|
|
|
|
class BBitmap;
|
|
class ConversationItem;
|
|
class ConversationView;
|
|
class ProtocolLooper;
|
|
class Server;
|
|
|
|
|
|
typedef KeyMap<BString, User*> UserMap;
|
|
typedef KeyMap<BString, Role*> RoleMap;
|
|
|
|
|
|
class Conversation : public Notifier, public Observer {
|
|
public:
|
|
Conversation(BString id, BMessenger msgn);
|
|
|
|
BString GetId() const;
|
|
|
|
void ImMessage(BMessage* msg);
|
|
|
|
// Tell the ConversationView to invalidate user list
|
|
void ObserveString(int32 what, BString str);
|
|
void ObserveInteger(int32 what, int32 value);
|
|
void ObservePointer(int32 what, void* ptr);
|
|
|
|
void SetNotifySubject(const char* subject);
|
|
|
|
BMessenger Messenger() const;
|
|
void SetMessenger(BMessenger messenger);
|
|
|
|
ProtocolLooper* GetProtocolLooper() const;
|
|
void SetProtocolLooper(ProtocolLooper* looper);
|
|
|
|
BBitmap* ProtocolBitmap() const;
|
|
BBitmap* IconBitmap() const;
|
|
BString GetName() const;
|
|
|
|
ConversationView* GetView();
|
|
void ShowView(bool typing, bool userAction);
|
|
ConversationItem* GetListItem();
|
|
|
|
UserMap Users();
|
|
User* UserById(BString id);
|
|
BString OwnUserId();
|
|
|
|
void AddUser(User* user);
|
|
void RemoveUser(User* user);
|
|
|
|
void SetRole(BString id, Role* role);
|
|
Role* GetRole(BString id);
|
|
|
|
private:
|
|
void _LogChatMessage(BMessage* msg);
|
|
BStringList _GetChatLogs();
|
|
void _EnsureLogPath();
|
|
|
|
User* _EnsureUser(BMessage* msg);
|
|
Server* _GetServer();
|
|
|
|
BMessenger fMessenger;
|
|
ProtocolLooper* fLooper;
|
|
ConversationView* fChatView;
|
|
ConversationItem* fConversationItem;
|
|
|
|
BString fID;
|
|
BString fName;
|
|
BString fSubject;
|
|
|
|
BBitmap* fIcon;
|
|
|
|
BPath fLogPath;
|
|
BDateTimeFormat fDateFormatter;
|
|
|
|
UserMap fUsers;
|
|
RoleMap fRoles;
|
|
};
|
|
|
|
|
|
#endif // CONVERSATION_H
|
|
|