Skip to content

Commit 8dfae7d

Browse files
committed
list message logs function
1 parent d7d4563 commit 8dfae7d

File tree

4 files changed

+49
-2
lines changed

4 files changed

+49
-2
lines changed

Makefile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,10 @@ getMessages: $(SRCS) $(EXAMPLES_DIR)/messaging/messages/getMessages.cpp
254254
createMessage: $(SRCS) $(EXAMPLES_DIR)/messaging/messages/createMessage.cpp
255255
@mkdir -p ./$(TESTS_DIR)
256256
$(CXX) $(CXXFLAGS) -o ./$(TESTS_DIR)/createMessage $(SRCS) $(EXAMPLES_DIR)/messaging/messages/createMessage.cpp $(LDFLAGS)
257-
257+
listMessageLogs: $(SRCS) $(EXAMPLES_DIR)/messaging/messages/listMessageLogs.cpp
258+
@mkdir -p ./$(TESTS_DIR)
259+
$(CXX) $(CXXFLAGS) -o ./$(TESTS_DIR)/listMessageLogs $(SRCS) $(EXAMPLES_DIR)/messaging/messages/listMessageLogs.cpp $(LDFLAGS)
260+
258261
# Messaging - Topics
259262
getTopic: $(SRCS) $(EXAMPLES_DIR)/messaging/topics/getTopic.cpp
260263
@mkdir -p ./$(TESTS_DIR)
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#include "Appwrite.hpp"
2+
#include <iostream>
3+
int main() {
4+
std::string projectId = "68853010003a3f4fc106";
5+
std::string apiKey = "";
6+
std::string messageId = "688e98ba00107a10f041";
7+
Appwrite appwrite(projectId, apiKey);
8+
Queries queries;
9+
queries.queryLimit(50);
10+
try {
11+
std::string response =
12+
appwrite.getMessaging().listMessageLogs(messageId, queries);
13+
std::cout << "Message logs fetched! \nResponse: " << response<< std::endl;
14+
} catch (const AppwriteException &ex) {
15+
std::cerr << "Exception: " << ex.what() << std::endl;
16+
}
17+
return 0;
18+
}

include/classes/Messaging.hpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,13 @@ class Messaging {
174174
const std::vector<std::string> &topicId = {},
175175
const std::vector<std::string> &userId = {});
176176

177-
177+
/**
178+
* @brief List all message logs with optional filters.
179+
* @param messageId ID of the message
180+
* @param queries Query parameters for filtering
181+
* @return JSON string of messageLog list
182+
*/
183+
std::string listMessageLogs(const std::string &messageId, Queries &queries);
178184
private:
179185
std::string projectId; ///< Project ID
180186
std::string apiKey; ///< API Key

src/services/Messaging.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -528,4 +528,24 @@ std::string Messaging::updatePush(const std::string &messageId,
528528
"Error updating push message. Status code: " + std::to_string(statusCode) +
529529
"\n\nResponse: " + response);
530530
}
531+
}
532+
533+
std::string Messaging::listMessageLogs(const std::string &messageId,
534+
Queries &queries) {
535+
if (messageId.empty()) {
536+
throw AppwriteException("Missing required parameter: messageId");
537+
}
538+
std::string url =
539+
Config::API_BASE_URL + "/messaging/messages/" + messageId + "/logs";
540+
std::vector<std::string> headers = Config::getHeaders(projectId);
541+
headers.push_back("X-Appwrite-Key: " + apiKey);
542+
std::string response;
543+
int statusCode = Utils::getRequest(url, headers, response);
544+
if (statusCode == HttpStatus::OK) {
545+
return response;
546+
} else {
547+
throw AppwriteException("Error listing message logs. Status code: " +
548+
std::to_string(statusCode) +
549+
"\nResponse: " + response);
550+
}
531551
}

0 commit comments

Comments
 (0)