Remove obselete CayaProtocol::SaveLogs(), add ::Commands()

With the new use of RoomFlags for signifying whether or not a room's
chat should be populated with local logs (ROOM_POPULATE_LOGS),
SaveLogs() is redundant.

A Commands() method was added to the CayaProtocol class returning a
CommandMap, which will be used by Caya when searching for commands.

KeyList::AddList() and List::AddList() were also added to libsupport,
for convenience.
This commit is contained in:
Jaidyn Ann 2021-06-15 14:40:28 -05:00
parent dd77f246f8
commit 83e98bd5a8
8 changed files with 58 additions and 25 deletions

View File

@ -1,6 +1,7 @@
/* /*
* Copyright 2009-2011, Andrea Anzani. All rights reserved. * Copyright 2009-2011, Andrea Anzani. All rights reserved.
* Copyright 2009-2011, Pier Luigi Fiorini. All rights reserved. * Copyright 2009-2011, Pier Luigi Fiorini. All rights reserved.
* Copyright 2021, Jaidyn Levesque. All rights reserved.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
*/ */
#ifndef _CAYA_PROTOCOL_H #ifndef _CAYA_PROTOCOL_H
@ -8,14 +9,18 @@
#include <Messenger.h> #include <Messenger.h>
#include "ChatCommand.h"
class BBitmap; class BBitmap;
// Caya protocol interface version // Caya protocol interface version
#define CAYA_VERSION_1_PRE_ALPHA_1 0x00000001 #define CAYA_VERSION_1_PRE_ALPHA_1 0x00000001
#define CAYA_VERSION_1_ALPHA_1 0x00000100 #define CAYA_VERSION_1_ALPHA_1 0x00000100
#define CAYA_VERSION CAYA_VERSION_1_PRE_ALPHA_1 #define CAYA_VERSION CAYA_VERSION_1_PRE_ALPHA_1
class CayaProtocolMessengerInterface { class CayaProtocolMessengerInterface {
public: public:
virtual status_t SendMessage(BMessage* message) = 0; virtual status_t SendMessage(BMessage* message) = 0;
@ -47,9 +52,6 @@ public:
//! Protocol icon //! Protocol icon
virtual BBitmap* Icon() const = 0; virtual BBitmap* Icon() const = 0;
//! Use local logs to populate chat
virtual bool SaveLogs() const = 0;
//! Add-on's path //! Add-on's path
virtual void SetAddOnPath(BPath path) = 0; virtual void SetAddOnPath(BPath path) = 0;
virtual BPath AddOnPath() = 0; virtual BPath AddOnPath() = 0;
@ -63,6 +65,9 @@ public:
//! Messenger interface used //! Messenger interface used
virtual CayaProtocolMessengerInterface* MessengerInterface() const = 0; virtual CayaProtocolMessengerInterface* MessengerInterface() const = 0;
//! Return a map of any custom commands
virtual CommandMap Commands() = 0;
}; };
#endif // _CAYA_PROTOCOL_H #endif // _CAYA_PROTOCOL_H

View File

@ -20,6 +20,7 @@
#include "NotifyMessage.h" #include "NotifyMessage.h"
#include "ProtocolLooper.h" #include "ProtocolLooper.h"
#include "ProtocolManager.h" #include "ProtocolManager.h"
#include "RoomFlags.h"
#include "Server.h" #include "Server.h"
#include "TheApp.h" #include "TheApp.h"
@ -264,7 +265,7 @@ Conversation::GetView()
fChatView = new ConversationView(this); fChatView = new ConversationView(this);
if (fLooper->Protocol()->SaveLogs() == false) if (!(fRoomFlags & ROOM_POPULATE_LOGS))
return fChatView; return fChatView;
BMessage logMsg; BMessage logMsg;

View File

@ -24,7 +24,8 @@ ProtocolLooper::ProtocolLooper(CayaProtocol* protocol, int64 instance)
BLooper(), BLooper(),
fProtocol(protocol), fProtocol(protocol),
fInstance(instance), fInstance(instance),
fListItem(NULL) fListItem(NULL),
fCommands(protocol->Commands())
{ {
Account* account = reinterpret_cast<Account*>( Account* account = reinterpret_cast<Account*>(
protocol->MessengerInterface()); protocol->MessengerInterface());

View File

@ -134,9 +134,13 @@ Server::Filter(BMessage* message, BHandler **target)
} }
} }
else { else {
CommandMap combinedCmds;
combinedCmds.AddList(fCommands);
combinedCmds.AddList(chat->GetProtocolLooper()->Commands());
body << "** Commands: "; body << "** Commands: ";
for (int i = 0; i < fCommands.CountItems(); i++) { for (int i = 0; i < combinedCmds.CountItems(); i++) {
ChatCommand* cmd = fCommands.ValueAt(i); ChatCommand* cmd = combinedCmds.ValueAt(i);
if (i > 0) body << ", "; if (i > 0) body << ", ";
body << cmd->GetName(); body << cmd->GetName();
} }
@ -649,10 +653,7 @@ Server::Contacts() const
for (int i = 0; i < fAccounts.CountItems(); i++) { for (int i = 0; i < fAccounts.CountItems(); i++) {
ProtocolLooper* fruitLoop = fLoopers.ValueFor(fAccounts.ValueAt(i)); ProtocolLooper* fruitLoop = fLoopers.ValueFor(fAccounts.ValueAt(i));
if (fruitLoop == NULL) continue; if (fruitLoop == NULL) continue;
contacts.AddList(fruitLoop->Contacts());
RosterMap accContacts = fruitLoop->Contacts();
for (int i = 0; i < accContacts.CountItems(); i++)
contacts.AddItem(accContacts.KeyAt(i), accContacts.ValueAt(i));
} }
return contacts; return contacts;
@ -686,10 +687,7 @@ Server::Users() const
for (int i = 0; i < fAccounts.CountItems(); i++) { for (int i = 0; i < fAccounts.CountItems(); i++) {
ProtocolLooper* fruitLoop = fLoopers.ValueFor(fAccounts.ValueAt(i)); ProtocolLooper* fruitLoop = fLoopers.ValueFor(fAccounts.ValueAt(i));
if (fruitLoop == NULL) continue; if (fruitLoop == NULL) continue;
users.AddList(fruitLoop->Users());
UserMap accUsers = fruitLoop->Users();
for (int i = 0; i < accUsers.CountItems(); i++)
users.AddItem(accUsers.KeyAt(i), accUsers.ValueAt(i));
} }
return users; return users;
@ -724,10 +722,7 @@ Server::Conversations() const
for (int i = 0; i < fAccounts.CountItems(); i++) { for (int i = 0; i < fAccounts.CountItems(); i++) {
ProtocolLooper* fruitLoop = fLoopers.ValueFor(fAccounts.ValueAt(i)); ProtocolLooper* fruitLoop = fLoopers.ValueFor(fAccounts.ValueAt(i));
if (fruitLoop == NULL) continue; if (fruitLoop == NULL) continue;
chats.AddList(fruitLoop->Conversations());
ChatMap accChats = fruitLoop->Conversations();
for (int i = 0; i < accChats.CountItems(); i++)
chats.AddItem(accChats.KeyAt(i), accChats.ValueAt(i));
} }
return chats; return chats;
@ -761,10 +756,7 @@ Server::Commands()
for (int i = 0; i < fAccounts.CountItems(); i++) { for (int i = 0; i < fAccounts.CountItems(); i++) {
ProtocolLooper* fruitLoop = fLoopers.ValueFor(fAccounts.ValueAt(i)); ProtocolLooper* fruitLoop = fLoopers.ValueFor(fAccounts.ValueAt(i));
if (fruitLoop == NULL) continue; if (fruitLoop == NULL) continue;
commands.AddList(fruitLoop->Commands());
CommandMap cmds = fruitLoop->Commands();
for (int i = 0; i < cmds.CountItems(); i++)
commands.AddItem(cmds.KeyAt(i), cmds.ValueAt(i));
} }
return fCommands; return fCommands;
} }

View File

@ -24,6 +24,8 @@ public:
KEY KeyAt(uint32 position) const; KEY KeyAt(uint32 position) const;
TYPE ValueAt(uint32 position) const; TYPE ValueAt(uint32 position) const;
void AddList(KeyMap<KEY, TYPE> appendList);
List<TYPE> Values() const; List<TYPE> Values() const;
private: private:
@ -114,6 +116,17 @@ KeyMap<KEY, TYPE>::ValueAt(uint32 position) const
} }
template<class KEY, class TYPE>
inline void
KeyMap<KEY, TYPE>::AddList(KeyMap<KEY, TYPE> appendList)
{
if (appendList.CountItems() == 0)
return;
for (int i = 0; i < appendList.CountItems(); i++)
AddItem(appendList.KeyAt(i), appendList.ValueAt(i));
}
template<class KEY, class TYPE> template<class KEY, class TYPE>
inline List<TYPE> inline List<TYPE>
KeyMap<KEY, TYPE>::Values() const KeyMap<KEY, TYPE>::Values() const

View File

@ -20,6 +20,8 @@ public:
T ItemAt(uint32 position); T ItemAt(uint32 position);
void AddList(List<T> appendList);
private: private:
std::list<T> fList; std::list<T> fList;
typedef typename std::list<T>::iterator fIter; typedef typename std::list<T>::iterator fIter;
@ -57,4 +59,15 @@ T List<T>::ItemAt(uint32 position)
return *i; return *i;
} }
template<class T>
void List<T>::AddList(List<T> appendList)
{
if (appendList.CountItems() == 0)
return;
for (int i = 0; i < appendList.CountItems(); i++)
AddItem(appendList.ItemAt(i));
}
#endif // _LIST_H #endif // _LIST_H

View File

@ -341,6 +341,13 @@ JabberHandler::UpdateSettings(BMessage* msg)
} }
CommandMap
JabberHandler::Commands()
{
return CommandMap();
}
uint32 uint32
JabberHandler::GetEncoding() JabberHandler::GetEncoding()
{ {

View File

@ -34,6 +34,7 @@
#include <CayaProtocol.h> #include <CayaProtocol.h>
#include <CayaConstants.h> #include <CayaConstants.h>
#include <ChatCommand.h>
#include <libsupport/KeyMap.h> #include <libsupport/KeyMap.h>
class BList; class BList;
@ -70,9 +71,9 @@ public:
virtual status_t UpdateSettings(BMessage* msg); virtual status_t UpdateSettings(BMessage* msg);
virtual uint32 GetEncoding(); virtual CommandMap Commands();
virtual bool SaveLogs() const { return true; } virtual uint32 GetEncoding();
virtual CayaProtocolMessengerInterface* virtual CayaProtocolMessengerInterface*
MessengerInterface() const; MessengerInterface() const;