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:
parent
dd77f246f8
commit
83e98bd5a8
|
@ -1,6 +1,7 @@
|
|||
/*
|
||||
* Copyright 2009-2011, Andrea Anzani. 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.
|
||||
*/
|
||||
#ifndef _CAYA_PROTOCOL_H
|
||||
|
@ -8,14 +9,18 @@
|
|||
|
||||
#include <Messenger.h>
|
||||
|
||||
#include "ChatCommand.h"
|
||||
|
||||
class BBitmap;
|
||||
|
||||
|
||||
// Caya protocol interface version
|
||||
#define CAYA_VERSION_1_PRE_ALPHA_1 0x00000001
|
||||
#define CAYA_VERSION_1_ALPHA_1 0x00000100
|
||||
|
||||
#define CAYA_VERSION CAYA_VERSION_1_PRE_ALPHA_1
|
||||
|
||||
|
||||
class CayaProtocolMessengerInterface {
|
||||
public:
|
||||
virtual status_t SendMessage(BMessage* message) = 0;
|
||||
|
@ -47,9 +52,6 @@ public:
|
|||
//! Protocol icon
|
||||
virtual BBitmap* Icon() const = 0;
|
||||
|
||||
//! Use local logs to populate chat
|
||||
virtual bool SaveLogs() const = 0;
|
||||
|
||||
//! Add-on's path
|
||||
virtual void SetAddOnPath(BPath path) = 0;
|
||||
virtual BPath AddOnPath() = 0;
|
||||
|
@ -63,6 +65,9 @@ public:
|
|||
|
||||
//! Messenger interface used
|
||||
virtual CayaProtocolMessengerInterface* MessengerInterface() const = 0;
|
||||
|
||||
//! Return a map of any custom commands
|
||||
virtual CommandMap Commands() = 0;
|
||||
};
|
||||
|
||||
#endif // _CAYA_PROTOCOL_H
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
#include "NotifyMessage.h"
|
||||
#include "ProtocolLooper.h"
|
||||
#include "ProtocolManager.h"
|
||||
#include "RoomFlags.h"
|
||||
#include "Server.h"
|
||||
#include "TheApp.h"
|
||||
|
||||
|
@ -264,7 +265,7 @@ Conversation::GetView()
|
|||
|
||||
fChatView = new ConversationView(this);
|
||||
|
||||
if (fLooper->Protocol()->SaveLogs() == false)
|
||||
if (!(fRoomFlags & ROOM_POPULATE_LOGS))
|
||||
return fChatView;
|
||||
|
||||
BMessage logMsg;
|
||||
|
|
|
@ -24,7 +24,8 @@ ProtocolLooper::ProtocolLooper(CayaProtocol* protocol, int64 instance)
|
|||
BLooper(),
|
||||
fProtocol(protocol),
|
||||
fInstance(instance),
|
||||
fListItem(NULL)
|
||||
fListItem(NULL),
|
||||
fCommands(protocol->Commands())
|
||||
{
|
||||
Account* account = reinterpret_cast<Account*>(
|
||||
protocol->MessengerInterface());
|
||||
|
|
|
@ -134,9 +134,13 @@ Server::Filter(BMessage* message, BHandler **target)
|
|||
}
|
||||
}
|
||||
else {
|
||||
CommandMap combinedCmds;
|
||||
combinedCmds.AddList(fCommands);
|
||||
combinedCmds.AddList(chat->GetProtocolLooper()->Commands());
|
||||
|
||||
body << "** Commands: ";
|
||||
for (int i = 0; i < fCommands.CountItems(); i++) {
|
||||
ChatCommand* cmd = fCommands.ValueAt(i);
|
||||
for (int i = 0; i < combinedCmds.CountItems(); i++) {
|
||||
ChatCommand* cmd = combinedCmds.ValueAt(i);
|
||||
if (i > 0) body << ", ";
|
||||
body << cmd->GetName();
|
||||
}
|
||||
|
@ -649,10 +653,7 @@ Server::Contacts() const
|
|||
for (int i = 0; i < fAccounts.CountItems(); i++) {
|
||||
ProtocolLooper* fruitLoop = fLoopers.ValueFor(fAccounts.ValueAt(i));
|
||||
if (fruitLoop == NULL) continue;
|
||||
|
||||
RosterMap accContacts = fruitLoop->Contacts();
|
||||
for (int i = 0; i < accContacts.CountItems(); i++)
|
||||
contacts.AddItem(accContacts.KeyAt(i), accContacts.ValueAt(i));
|
||||
contacts.AddList(fruitLoop->Contacts());
|
||||
}
|
||||
|
||||
return contacts;
|
||||
|
@ -686,10 +687,7 @@ Server::Users() const
|
|||
for (int i = 0; i < fAccounts.CountItems(); i++) {
|
||||
ProtocolLooper* fruitLoop = fLoopers.ValueFor(fAccounts.ValueAt(i));
|
||||
if (fruitLoop == NULL) continue;
|
||||
|
||||
UserMap accUsers = fruitLoop->Users();
|
||||
for (int i = 0; i < accUsers.CountItems(); i++)
|
||||
users.AddItem(accUsers.KeyAt(i), accUsers.ValueAt(i));
|
||||
users.AddList(fruitLoop->Users());
|
||||
}
|
||||
|
||||
return users;
|
||||
|
@ -724,10 +722,7 @@ Server::Conversations() const
|
|||
for (int i = 0; i < fAccounts.CountItems(); i++) {
|
||||
ProtocolLooper* fruitLoop = fLoopers.ValueFor(fAccounts.ValueAt(i));
|
||||
if (fruitLoop == NULL) continue;
|
||||
|
||||
ChatMap accChats = fruitLoop->Conversations();
|
||||
for (int i = 0; i < accChats.CountItems(); i++)
|
||||
chats.AddItem(accChats.KeyAt(i), accChats.ValueAt(i));
|
||||
chats.AddList(fruitLoop->Conversations());
|
||||
}
|
||||
|
||||
return chats;
|
||||
|
@ -761,10 +756,7 @@ Server::Commands()
|
|||
for (int i = 0; i < fAccounts.CountItems(); i++) {
|
||||
ProtocolLooper* fruitLoop = fLoopers.ValueFor(fAccounts.ValueAt(i));
|
||||
if (fruitLoop == NULL) continue;
|
||||
|
||||
CommandMap cmds = fruitLoop->Commands();
|
||||
for (int i = 0; i < cmds.CountItems(); i++)
|
||||
commands.AddItem(cmds.KeyAt(i), cmds.ValueAt(i));
|
||||
commands.AddList(fruitLoop->Commands());
|
||||
}
|
||||
return fCommands;
|
||||
}
|
||||
|
|
|
@ -24,6 +24,8 @@ public:
|
|||
KEY KeyAt(uint32 position) const;
|
||||
TYPE ValueAt(uint32 position) const;
|
||||
|
||||
void AddList(KeyMap<KEY, TYPE> appendList);
|
||||
|
||||
List<TYPE> Values() const;
|
||||
|
||||
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>
|
||||
inline List<TYPE>
|
||||
KeyMap<KEY, TYPE>::Values() const
|
||||
|
|
|
@ -20,6 +20,8 @@ public:
|
|||
|
||||
T ItemAt(uint32 position);
|
||||
|
||||
void AddList(List<T> appendList);
|
||||
|
||||
private:
|
||||
std::list<T> fList;
|
||||
typedef typename std::list<T>::iterator fIter;
|
||||
|
@ -57,4 +59,15 @@ T List<T>::ItemAt(uint32 position)
|
|||
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
|
||||
|
|
|
@ -341,6 +341,13 @@ JabberHandler::UpdateSettings(BMessage* msg)
|
|||
}
|
||||
|
||||
|
||||
CommandMap
|
||||
JabberHandler::Commands()
|
||||
{
|
||||
return CommandMap();
|
||||
}
|
||||
|
||||
|
||||
uint32
|
||||
JabberHandler::GetEncoding()
|
||||
{
|
||||
|
|
|
@ -34,6 +34,7 @@
|
|||
|
||||
#include <CayaProtocol.h>
|
||||
#include <CayaConstants.h>
|
||||
#include <ChatCommand.h>
|
||||
#include <libsupport/KeyMap.h>
|
||||
|
||||
class BList;
|
||||
|
@ -70,9 +71,9 @@ public:
|
|||
|
||||
virtual status_t UpdateSettings(BMessage* msg);
|
||||
|
||||
virtual uint32 GetEncoding();
|
||||
virtual CommandMap Commands();
|
||||
|
||||
virtual bool SaveLogs() const { return true; }
|
||||
virtual uint32 GetEncoding();
|
||||
|
||||
virtual CayaProtocolMessengerInterface*
|
||||
MessengerInterface() const;
|
||||
|
|
Ŝarĝante…
Reference in New Issue