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

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 @@ -300,7 +300,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)

listTopicLogs: $(SRCS) $(EXAMPLES_DIR)/messaging/topics/listTopicLogs.cpp
@mkdir -p ./$(TESTS_DIR)
$(CXX) $(CXXFLAGS) -o ./$(TESTS_DIR)/listTopicLogs $(SRCS) $(EXAMPLES_DIR)/messaging/topics/listTopicLogs.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/listTopicLogs.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 @@ -261,6 +261,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
31 changes: 31 additions & 0 deletions src/services/Messaging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -737,3 +737,34 @@ 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);
}
}

Loading