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.
91 lines
2.2 KiB
C++
91 lines
2.2 KiB
C++
/*
|
|
* Copyright 2009-2011, Andrea Anzani. All rights reserved.
|
|
* Copyright 2009-2011, Pier Luigi Fiorini. All rights reserved.
|
|
* Distributed under the terms of the MIT License.
|
|
*/
|
|
#ifndef _SERVER_H
|
|
#define _SERVER_H
|
|
|
|
#include <Message.h>
|
|
#include <MessageFilter.h>
|
|
|
|
#include <libsupport/KeyMap.h>
|
|
|
|
#include "CayaConstants.h"
|
|
#include "Contact.h"
|
|
#include "Conversation.h"
|
|
#include "User.h"
|
|
|
|
class CayaProtocol;
|
|
class RosterItem;
|
|
class ProtocolLooper;
|
|
|
|
|
|
typedef KeyMap<BString, Contact*> RosterMap;
|
|
typedef KeyMap<BString, User*> UserMap;
|
|
typedef KeyMap<BString, Conversation*> ChatMap;
|
|
typedef KeyMap<bigtime_t, ProtocolLooper*> ProtocolLoopers;
|
|
typedef KeyMap<BString, bigtime_t> AccountInstances;
|
|
|
|
|
|
class Server: public BMessageFilter {
|
|
public:
|
|
Server();
|
|
void Quit();
|
|
void LoginAll();
|
|
|
|
virtual filter_result Filter(BMessage* message, BHandler** target);
|
|
filter_result ImMessage(BMessage* msg);
|
|
|
|
void AddProtocolLooper(bigtime_t instanceId,
|
|
CayaProtocol* cayap);
|
|
void RemoveProtocolLooper(bigtime_t instanceId);
|
|
ProtocolLooper* GetProtocolLooper(bigtime_t instanceId);
|
|
|
|
AccountInstances
|
|
GetAccounts();
|
|
|
|
void SendProtocolMessage(BMessage* msg);
|
|
void SendAllProtocolMessage(BMessage* msg);
|
|
|
|
RosterMap Contacts() const;
|
|
Contact* ContactById(BString id);
|
|
void AddContact(Contact* contact);
|
|
|
|
UserMap Users() const;
|
|
User* UserById(BString id);
|
|
void AddUser(User* user);
|
|
|
|
ChatMap Conversations() const;
|
|
Conversation* ConversationById(BString id);
|
|
void AddConversation(Conversation* chat);
|
|
void RemoveConversation(Conversation* chat);
|
|
|
|
// TODO: there should be a contact for each account.
|
|
BString GetOwnContact();
|
|
|
|
private:
|
|
ProtocolLooper* _LooperFromMessage(BMessage* message);
|
|
|
|
Contact* _EnsureContact(BMessage* message);
|
|
User* _EnsureUser(BMessage* message);
|
|
User* _EnsureUser(BString id, ProtocolLooper* protoLooper);
|
|
Conversation* _EnsureConversation(BMessage* message);
|
|
|
|
Role* _GetRole(BMessage* msg);
|
|
|
|
void _ReplicantStatusNotify(CayaStatus status);
|
|
|
|
RosterMap fRosterMap;
|
|
UserMap fUserMap;
|
|
ChatMap fChatMap;
|
|
ProtocolLoopers fLoopers;
|
|
AccountInstances
|
|
fAccounts;
|
|
BString fMySelf;
|
|
};
|
|
|
|
|
|
#endif // _SERVER_H
|
|
|