Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,9 @@ createTopic: $(SRCS) $(EXAMPLES_DIR)/messaging/topics/createTopic.cpp
updateTopic: $(SRCS) $(EXAMPLES_DIR)/messaging/topics/updateTopic.cpp
@mkdir -p ./$(TESTS_DIR)
$(CXX) $(CXXFLAGS) -o ./$(TESTS_DIR)/updateTopic $(SRCS) $(EXAMPLES_DIR)/messaging/topics/updateTopic.cpp $(LDFLAGS)

list_Topic_logs: $(SRCS) $(EXAMPLES_DIR)/messaging/topics/list_Topic_logs.cpp
@mkdir -p ./$(TESTS_DIR)
$(CXX) $(CXXFLAGS) -o ./$(TESTS_DIR)/list_Topic_logs $(SRCS) $(EXAMPLES_DIR)/messaging/topics/list_Topic_logs.cpp $(LDFLAGS)
# Messaging - subscribers
getSubscriber: $(SRCS) $(EXAMPLES_DIR)/messaging/subscribers/getSubscriber.cpp
@mkdir -p ./$(TESTS_DIR)
Expand Down
21 changes: 21 additions & 0 deletions examples/messaging/topics/list_Topic_logs.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#include "Appwrite.hpp"
#include <iostream>

int main() {
std::string projectId = "";
std::string apiKey = "";
Appwrite appwrite(projectId, apiKey);

std::string topicId = "";

std::vector<std::string> queries = {};

try {
std::string response = appwrite.getMessaging().listTopicLogs(topicId, queries);

std::cout << "Topic Logs: " << response << std::endl;
} catch (const AppwriteException &e) {
std::cerr << "Appwrite error: " << e.what() << std::endl;
}
return 0;
}
9 changes: 9 additions & 0 deletions include/classes/Messaging.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,15 @@ class Messaging {
*/
std::string listTargets(const std::string &messageId,
const std::vector<std::string> &queries = {});

/**
* @brief List all logs for a given topic.
* @param topicID ID of the message.
* @param queries Optional query filters.
* @return JSON response.
*/
std::string listTopicLogs(const std::string &topicId,
const std::vector<std::string> &queries = {});

private:
std::string projectId; ///< Project ID
Expand Down
30 changes: 30 additions & 0 deletions src/services/Messaging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -681,3 +681,33 @@ std::string Messaging::listTargets(const std::string &messageId,
}
}

std::string Messaging::listTopicLogs(const std::string &topicId,
const std::vector<std::string> &queries) {
if (topicId.empty()) {
throw AppwriteException("Missing required parameter: 'topicId'");
}

std::string url = Config::API_BASE_URL + "/messaging/topics/" + topicId + "/logs";

std::string queryParam = "";
if (!queries.empty()) {
queryParam += "?queries[]=" + Utils::urlEncode(queries[0]);
for (size_t i = 1; i < queries.size(); ++i) {
queryParam += "&queries[]=" + Utils::urlEncode(queries[i]);
}
}
url += queryParam;

std::vector<std::string> headers = Config::getHeaders(projectId);
headers.push_back("X-Appwrite-Key: " + apiKey);
std::string response;

int statusCode = Utils::getRequest(url, headers, response);
if (statusCode == HttpStatus::OK) {
return response;
} else {
throw AppwriteException(
"Error fetching topic logs. Status code: " + std::to_string(statusCode) +
"\n\nResponse: " + response);
}
}