2010-05-07 04:47:10 -05:00
|
|
|
/*
|
2011-12-03 16:38:03 -06:00
|
|
|
* Copyright 2009-2011, Andrea Anzani. All rights reserved.
|
|
|
|
* Copyright 2009-2011, Pier Luigi Fiorini. All rights reserved.
|
2010-05-07 04:47:10 -05:00
|
|
|
* Distributed under the terms of the MIT License.
|
|
|
|
*/
|
|
|
|
#ifndef _SERVER_H
|
|
|
|
#define _SERVER_H
|
|
|
|
|
|
|
|
#include <Message.h>
|
|
|
|
#include <MessageFilter.h>
|
|
|
|
|
2010-05-08 14:35:28 -05:00
|
|
|
#include <libsupport/KeyMap.h>
|
|
|
|
|
2010-05-07 04:47:10 -05:00
|
|
|
#include "CayaConstants.h"
|
2021-06-15 00:19:52 -05:00
|
|
|
#include "ChatCommand.h"
|
2021-05-23 14:39:07 -05:00
|
|
|
#include "Contact.h"
|
2021-05-24 01:47:21 -05:00
|
|
|
#include "Conversation.h"
|
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
|
|
|
#include "ProtocolLooper.h"
|
2021-05-31 11:56:45 -05:00
|
|
|
#include "User.h"
|
2010-05-07 04:47:10 -05:00
|
|
|
|
2010-05-16 16:02:50 -05:00
|
|
|
class CayaProtocol;
|
2010-05-07 04:47:10 -05:00
|
|
|
class RosterItem;
|
2010-05-16 16:02:50 -05:00
|
|
|
class ProtocolLooper;
|
2010-05-07 04:47:10 -05:00
|
|
|
|
2021-05-27 11:15:30 -05:00
|
|
|
|
2010-05-16 16:02:50 -05:00
|
|
|
typedef KeyMap<bigtime_t, ProtocolLooper*> ProtocolLoopers;
|
2021-06-01 21:43:19 -05:00
|
|
|
typedef KeyMap<BString, bigtime_t> AccountInstances;
|
2010-05-07 04:47:10 -05:00
|
|
|
|
2021-05-27 11:15:30 -05:00
|
|
|
|
2010-05-07 04:47:10 -05:00
|
|
|
class Server: public BMessageFilter {
|
|
|
|
public:
|
2010-05-16 16:02:50 -05:00
|
|
|
Server();
|
2021-05-31 13:04:58 -05:00
|
|
|
void Quit();
|
|
|
|
void LoginAll();
|
2010-05-07 04:47:10 -05:00
|
|
|
|
|
|
|
virtual filter_result Filter(BMessage* message, BHandler** target);
|
|
|
|
filter_result ImMessage(BMessage* msg);
|
|
|
|
|
2010-05-20 16:31:55 -05:00
|
|
|
void AddProtocolLooper(bigtime_t instanceId,
|
|
|
|
CayaProtocol* cayap);
|
2010-05-16 16:02:50 -05:00
|
|
|
void RemoveProtocolLooper(bigtime_t instanceId);
|
2021-06-01 21:43:19 -05:00
|
|
|
ProtocolLooper* GetProtocolLooper(bigtime_t instanceId);
|
|
|
|
|
|
|
|
AccountInstances
|
|
|
|
GetAccounts();
|
2010-05-07 04:47:10 -05:00
|
|
|
|
|
|
|
void SendProtocolMessage(BMessage* msg);
|
2010-05-16 16:02:50 -05:00
|
|
|
void SendAllProtocolMessage(BMessage* msg);
|
2010-05-07 04:47:10 -05:00
|
|
|
|
2021-05-24 01:47:21 -05:00
|
|
|
RosterMap Contacts() const;
|
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
|
|
|
Contact* ContactById(BString id, int64 instance);
|
|
|
|
void AddContact(Contact* contact, int64 instance);
|
2021-05-24 01:47:21 -05:00
|
|
|
|
2021-05-31 11:56:45 -05:00
|
|
|
UserMap Users() const;
|
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* UserById(BString id, int64 instance);
|
|
|
|
void AddUser(User* user, int64 instance);
|
2021-05-31 11:56:45 -05:00
|
|
|
|
2021-05-24 01:47:21 -05:00
|
|
|
ChatMap Conversations() const;
|
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
|
|
|
Conversation* ConversationById(BString id, int64 instance);
|
|
|
|
void AddConversation(Conversation* chat, int64 instance);
|
2010-05-07 04:47:10 -05:00
|
|
|
|
2021-06-15 00:19:52 -05:00
|
|
|
CommandMap Commands();
|
|
|
|
ChatCommand* CommandById(BString id);
|
|
|
|
|
2010-05-07 04:47:10 -05:00
|
|
|
private:
|
2011-12-14 17:36:27 -06:00
|
|
|
ProtocolLooper* _LooperFromMessage(BMessage* message);
|
2021-05-31 11:56:45 -05:00
|
|
|
|
2021-05-24 01:47:21 -05:00
|
|
|
Contact* _EnsureContact(BMessage* message);
|
2021-05-31 11:56:45 -05:00
|
|
|
User* _EnsureUser(BMessage* message);
|
2021-06-02 16:53:03 -05:00
|
|
|
User* _EnsureUser(BString id, ProtocolLooper* protoLooper);
|
2021-05-24 01:47:21 -05:00
|
|
|
Conversation* _EnsureConversation(BMessage* message);
|
2021-05-31 11:56:45 -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
|
|
|
Role* _GetRole(BMessage* msg);
|
|
|
|
|
2021-06-15 00:19:52 -05:00
|
|
|
void _InitDefaultCommands();
|
2011-12-14 17:36:27 -06:00
|
|
|
void _ReplicantStatusNotify(CayaStatus status);
|
|
|
|
|
|
|
|
ProtocolLoopers fLoopers;
|
2021-06-01 21:43:19 -05:00
|
|
|
AccountInstances
|
|
|
|
fAccounts;
|
2021-06-15 00:19:52 -05:00
|
|
|
CommandMap fCommands;
|
2021-05-31 13:04:58 -05:00
|
|
|
BString fMySelf;
|
2010-05-07 04:47:10 -05:00
|
|
|
};
|
|
|
|
|
2021-05-27 11:15:30 -05:00
|
|
|
|
2010-05-07 04:47:10 -05:00
|
|
|
#endif // _SERVER_H
|
2021-05-27 11:15:30 -05:00
|
|
|
|