65 lines
1.7 KiB
C++
65 lines
1.7 KiB
C++
#pragma once
|
|
|
|
#include <echoion/api.hpp>
|
|
#include <set>
|
|
#include <string>
|
|
#include <mutex>
|
|
#include <memory>
|
|
#include <vector>
|
|
|
|
namespace Echoion::Core {
|
|
|
|
/**
|
|
* Manages user subscriptions to the bot's audio output
|
|
* Subscriptions are persisted to database and survive client reloads
|
|
* Uses unique client UID instead of session-specific client ID
|
|
*/
|
|
class SubscriptionManager {
|
|
public:
|
|
struct Subscriber {
|
|
std::string uid;
|
|
std::string nickname;
|
|
};
|
|
|
|
SubscriptionManager();
|
|
~SubscriptionManager();
|
|
|
|
// Initialize and load subscriptions from database
|
|
Api::Result<void> initialize(std::shared_ptr<Api::Database> database);
|
|
void shutdown();
|
|
|
|
// Subscription management (by UID)
|
|
bool subscribe(const std::string& uid, const std::string& nickname);
|
|
bool unsubscribe(const std::string& uid);
|
|
bool isSubscribed(const std::string& uid) const;
|
|
|
|
// Get all subscribed UIDs
|
|
std::vector<std::string> getSubscribedUids() const;
|
|
|
|
// Get all subscribers with info
|
|
std::vector<Subscriber> getSubscribers() const;
|
|
|
|
// Get subscriber nickname
|
|
std::optional<std::string> getSubscriberNickname(const std::string& uid) const;
|
|
|
|
// Update nickname for subscriber
|
|
bool updateNickname(const std::string& uid, const std::string& nickname);
|
|
|
|
// Check if anyone is subscribed
|
|
bool hasSubscribers() const;
|
|
|
|
// Get subscriber count
|
|
size_t getSubscriberCount() const;
|
|
|
|
// Clear all subscriptions
|
|
bool clearAll();
|
|
|
|
private:
|
|
std::set<std::string> subscribedUids_;
|
|
mutable std::mutex mutex_;
|
|
std::shared_ptr<Api::Database> database_;
|
|
bool initialized_ = false;
|
|
};
|
|
|
|
} // namespace Echoion::Core
|