48d0b7bc96
This is a commit with it's foot in a lot of places, but: The Conversation class was created as the abstraction of chats: All ImMessages that are relevant to a conversation get routed through it, meta-data on chats is stored in it (even if right now that's basically limited to the user list and ID). Server was given more methods to help accessing contacts― ContactById(BString) and AddContact(Contact*). This better allows Conversations to add and fetch Contacts as necessary. Right now, all users in chats are treated as Contacts, so in the future creating an independent userlist for Server (fUserMap?) would be useful. Server also now stores all Conversations (fChatMap) and has some convenience methods like for Contacts: Conversations(), ConversationById(BString), and AddConversation(Conversation*). CayaRenderView has been changed to not store user nicks, and will use the appropriate nick of any arbitrarily-numbered user. Users also have a map of all Conversations they are a part of (fChatMap). The Remove* methods of KeyMap now return the removed item.
75 lines
1.5 KiB
C++
75 lines
1.5 KiB
C++
/*
|
|
* Copyright 2021, Jaidyn Levesque <jadedctrl@teknik.io>
|
|
* All rights reserved. Distributed under the terms of the MIT license.
|
|
*/
|
|
#ifndef CONVERSATION_H
|
|
#define CONVERSATION_H
|
|
|
|
#include <Messenger.h>
|
|
|
|
#include <libsupport/KeyMap.h>
|
|
|
|
#include "Notifier.h"
|
|
#include "User.h"
|
|
|
|
class ChatWindow;
|
|
class Contact;
|
|
class ProtocolLooper;
|
|
class Server;
|
|
|
|
|
|
typedef KeyMap<BString, Contact*> UserMap;
|
|
|
|
|
|
class Conversation : public Observer {
|
|
public:
|
|
Conversation(BString id, BMessenger msgn);
|
|
|
|
BString GetId() const;
|
|
|
|
// Handles required state changes from an IM message; forwards to ChatWindow
|
|
void ImMessage(BMessage* msg);
|
|
|
|
// Observer inherits; just forwards to ChatWindow
|
|
void ObserveString(int32 what, BString str);
|
|
void ObserveInteger(int32 what, int32 value);
|
|
void ObservePointer(int32 what, void* ptr);
|
|
|
|
ChatWindow* GetChatWindow();
|
|
void DeleteWindow();
|
|
|
|
void ShowWindow(bool typing = false, bool userAction = false);
|
|
void HideWindow();
|
|
|
|
BMessenger Messenger() const;
|
|
void SetMessenger(BMessenger messenger);
|
|
|
|
ProtocolLooper* GetProtocolLooper() const;
|
|
void SetProtocolLooper(ProtocolLooper* looper);
|
|
|
|
BString GetName() const;
|
|
|
|
UserMap Users();
|
|
Contact* UserById(BString id);
|
|
void AddUser(User* user);
|
|
|
|
private:
|
|
void _CreateChatWindow();
|
|
Contact* _EnsureUser(BMessage* msg);
|
|
Server* _GetServer();
|
|
|
|
BMessenger fMessenger;
|
|
ProtocolLooper* fLooper;
|
|
ChatWindow* fChatWindow;
|
|
bool fNewWindow;
|
|
|
|
BString fID;
|
|
BString fName;
|
|
|
|
UserMap fUsers;
|
|
};
|
|
|
|
|
|
#endif // CONVERSATION_H
|
|
|