diff --git a/application/CayaProtocol.h b/application/CayaProtocol.h index bb059f6..b61ea00 100644 --- a/application/CayaProtocol.h +++ b/application/CayaProtocol.h @@ -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 +#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 diff --git a/application/Conversation.cpp b/application/Conversation.cpp index e481ce3..4149156 100644 --- a/application/Conversation.cpp +++ b/application/Conversation.cpp @@ -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; diff --git a/application/ProtocolLooper.cpp b/application/ProtocolLooper.cpp index c7cdaca..fc85826 100644 --- a/application/ProtocolLooper.cpp +++ b/application/ProtocolLooper.cpp @@ -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( protocol->MessengerInterface()); diff --git a/application/Server.cpp b/application/Server.cpp index 366b693..5420d42 100644 --- a/application/Server.cpp +++ b/application/Server.cpp @@ -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; } diff --git a/libs/libsupport/KeyMap.h b/libs/libsupport/KeyMap.h index 725707f..b7a4de0 100644 --- a/libs/libsupport/KeyMap.h +++ b/libs/libsupport/KeyMap.h @@ -24,6 +24,8 @@ public: KEY KeyAt(uint32 position) const; TYPE ValueAt(uint32 position) const; + void AddList(KeyMap appendList); + List Values() const; private: @@ -114,6 +116,17 @@ KeyMap::ValueAt(uint32 position) const } +template +inline void +KeyMap::AddList(KeyMap appendList) +{ + if (appendList.CountItems() == 0) + return; + for (int i = 0; i < appendList.CountItems(); i++) + AddItem(appendList.KeyAt(i), appendList.ValueAt(i)); +} + + template inline List KeyMap::Values() const diff --git a/libs/libsupport/List.h b/libs/libsupport/List.h index 5682db5..da9bb7c 100644 --- a/libs/libsupport/List.h +++ b/libs/libsupport/List.h @@ -20,6 +20,8 @@ public: T ItemAt(uint32 position); + void AddList(List appendList); + private: std::list fList; typedef typename std::list::iterator fIter; @@ -57,4 +59,15 @@ T List::ItemAt(uint32 position) return *i; } + +template +void List::AddList(List appendList) +{ + if (appendList.CountItems() == 0) + return; + for (int i = 0; i < appendList.CountItems(); i++) + AddItem(appendList.ItemAt(i)); +} + + #endif // _LIST_H diff --git a/protocols/xmpp/JabberHandler.cpp b/protocols/xmpp/JabberHandler.cpp index d6671be..ac56a9b 100644 --- a/protocols/xmpp/JabberHandler.cpp +++ b/protocols/xmpp/JabberHandler.cpp @@ -341,6 +341,13 @@ JabberHandler::UpdateSettings(BMessage* msg) } +CommandMap +JabberHandler::Commands() +{ + return CommandMap(); +} + + uint32 JabberHandler::GetEncoding() { diff --git a/protocols/xmpp/JabberHandler.h b/protocols/xmpp/JabberHandler.h index 0b5a03a..0ced3bb 100644 --- a/protocols/xmpp/JabberHandler.h +++ b/protocols/xmpp/JabberHandler.h @@ -34,6 +34,7 @@ #include #include +#include #include 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;