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>
|
2021-07-18 15:39:30 -05:00
|
|
|
#include <Notification.h>
|
2010-05-07 04:47:10 -05:00
|
|
|
|
2010-05-08 14:35:28 -05:00
|
|
|
#include <libsupport/KeyMap.h>
|
|
|
|
|
2021-06-20 12:44:20 -05:00
|
|
|
#include "AppConstants.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"
|
2021-07-21 12:12:02 -05:00
|
|
|
#include "Notifier.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
|
|
|
|
2021-06-20 12:44:20 -05:00
|
|
|
class ChatProtocol;
|
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;
|
2021-07-21 12:12:02 -05:00
|
|
|
typedef KeyMap<BString, bool> BoolMap;
|
2010-05-07 04:47:10 -05:00
|
|
|
|
2021-05-27 11:15:30 -05:00
|
|
|
|
2021-07-21 12:12:02 -05:00
|
|
|
class Server: public BMessageFilter, public Notifier {
|
2010-05-07 04:47:10 -05:00
|
|
|
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);
|
2021-07-18 15:39:30 -05:00
|
|
|
void ImError(BMessage* msg);
|
2010-05-07 04:47:10 -05:00
|
|
|
|
2010-05-20 16:31:55 -05:00
|
|
|
void AddProtocolLooper(bigtime_t instanceId,
|
2021-06-20 12:44:20 -05:00
|
|
|
ChatProtocol* 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);
|
|
|
|
|
2021-07-21 12:12:02 -05:00
|
|
|
AccountInstances GetAccounts();
|
|
|
|
AccountInstances GetActiveAccounts();
|
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:59:00 -05:00
|
|
|
ChatCommand* CommandById(BString id, int64 instance);
|
2021-06-15 00:19:52 -05:00
|
|
|
|
2021-06-16 04:33:06 -05:00
|
|
|
BObjectList<BMessage> ChatPopUpItems();
|
2021-06-15 21:05:21 -05:00
|
|
|
BObjectList<BMessage> UserPopUpItems();
|
|
|
|
|
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-07-13 14:43:48 -05:00
|
|
|
Contact* _GetOwnContact(BMessage* message);
|
2021-05-24 01:47:21 -05:00
|
|
|
Conversation* _EnsureConversation(BMessage* message);
|
2021-05-31 11:56:45 -05:00
|
|
|
|
2021-07-18 15:39:30 -05:00
|
|
|
void _ProtocolNotification(ProtocolLooper* looper,
|
|
|
|
BString title, BString desc,
|
|
|
|
notification_type type=B_INFORMATION_NOTIFICATION);
|
Redesign add-on disconnection
Currently, add-ons are disconnected when ChatProtocol::Shutdown() is
called, which the add-on can do by itself― but there is no standard way
for add-ons to notify the app about their Shutdown. Because of this,
they tend to not call Shutdown()― instead (as in the case of the Jabber
add-on), they display a BAlert (IM_ERROR) notifying the user of the
connection error, but the account is considered active by Cardie (and
its threads are still existant, including its ProtocolLooper).
Zombies are bad, so this is redesigned somewhat with this commit:
Protocols should no longer call ChatProtocol::Shutdown() themselves,
they must send an IM_MESSAGE of IM_PROTOCOL_DISABLE to the app.
This will delete its ProtocolLooper, which in turn will send a
notification to the user and delete the ChatProtocol, and so
calling ChatProtocol::Shutdown().
In the included protocols, an IM_ERROR is sent right before
IM_PROTOCOL_DISABLE is sent if due to a connection error. This is not
required, but it is courteous to inform your user about the "why." :)
2021-07-18 17:52:36 -05:00
|
|
|
void _SendNotification(BString title, BString content,
|
|
|
|
BBitmap* icon=NULL,
|
|
|
|
notification_type type=B_INFORMATION_NOTIFICATION);
|
2021-07-18 15:39:30 -05:00
|
|
|
|
2021-06-20 12:44:20 -05:00
|
|
|
void _ReplicantStatusNotify(UserStatus status);
|
2011-12-14 17:36:27 -06:00
|
|
|
|
|
|
|
ProtocolLoopers fLoopers;
|
2021-07-21 12:12:02 -05:00
|
|
|
AccountInstances fAccounts;
|
|
|
|
BoolMap fAccountEnabled;
|
|
|
|
|
|
|
|
CommandMap fCommands;
|
|
|
|
BObjectList<BMessage> fChatItems;
|
|
|
|
BObjectList<BMessage> fUserItems;
|
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
|
|
|
|