Skip to content

Commit

Permalink
Implement Delete Messages
Browse files Browse the repository at this point in the history
  • Loading branch information
maxbundscherer committed Aug 4, 2022
1 parent ca5386f commit 0355da1
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 1 deletion.
84 changes: 84 additions & 0 deletions independer-app/src/device/mb-wifi.h
Original file line number Diff line number Diff line change
Expand Up @@ -221,5 +221,89 @@ String wifi_get_chat_messages(String myId, String serverUrl, int serverPort, int

i_wifi_disconnect();

return ret_status;
}

/*
* ####################################
* Clear Chat Message Section
* ####################################
*/

boolean wifi_clear_message(String myId, String serverUrl, int serverPort, int serverTimeout)
{

char *c_wifi_server_url = const_cast<char *>(serverUrl.c_str());
int c_wifi_server_port = serverPort;
int c_wifi_timeout = serverTimeout;

boolean ret_status = false;

if (i_wifi_connect())
{

// Code Start
Serial.println("[Send GET REQUEST] START");
Serial.println("Connect to server (timeout " + String(c_wifi_timeout) + ")");
if (!i_wifi_client.connect(c_wifi_server_url, c_wifi_server_port, c_wifi_timeout))
{
Serial.println("Connection failed!");
}
else
{
Serial.println("Connected to server!");
/* create HTTP request */

int c_mail_max_fails = 150;

int mail_fail_connect_counter = 0;

String send_string = String("GET ") + "/v1/clearmsg/" + myId + " HTTP/1.1\r\n" +
"Host: " + String(c_wifi_server_url) + ":" + String(c_wifi_server_port) + "\r\n" +
"Content-Type: application/json" + "\r\n" +
"Connection: close\r\n\r\n";

Serial.println("Send String is '" + send_string + "'");

i_wifi_client.print(send_string);

Serial.println("[Waiting for response] START");
while (!i_wifi_client.available() and mail_fail_connect_counter < c_mail_max_fails)
{
mail_fail_connect_counter++;
Serial.print("AM=" + String(mail_fail_connect_counter) + "/" + String(c_mail_max_fails) + " ");
delay(50); //
}
Serial.println("\n[Waiting for response] STOP");

String line = "";
while (i_wifi_client.available())
{
line += i_wifi_client.readStringUntil('\r');
}
Serial.print("Response '" + line + "'");

if (line.endsWith("OK"))
{
ret_status = true;
}

/* if the server disconnected, stop the client */
if (!i_wifi_client.connected())
{
Serial.println();
Serial.println("Server disconnected");
}

i_wifi_client.stop();
}
Serial.println("[Send GET Request] STOP");
// Mail Cod Stop
}
else
Serial.println("Could not send mail: WiFi is not connected");

i_wifi_disconnect();

return ret_status;
}
8 changes: 7 additions & 1 deletion independer-app/src/workflow/workflow-actor.h
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,13 @@ void i_communication_chat_menu()
else if (selected_wrapper.success and selected_wrapper.value == 1)
application_actor_query_msgs_from_internet(state_my_id);
else if (selected_wrapper.success and selected_wrapper.value == 2)
gui_msg_animated("Info", "Leider ist die Funktion\n'Chat leeren'\nnoch nicht verfügbar.", C_GUI_DELAY_MSG_SHORT_I);
{
gui_msg_static("Hinweis", "Chat wird\ngelöscht...");
if (wifi_clear_message(state_my_id, state_wifi_server_url, state_wifi_server_port, state_wifi_server_timeout))
gui_msg_animated("Info", "Chat wurde\ngelöscht.", C_GUI_DELAY_MSG_SHORT_I);
else
gui_msg_animated("Info", "Chat konnte nicht\ngelöscht werden.", C_GUI_DELAY_MSG_SHORT_I);
}
else
fin_flag = true;
}
Expand Down

0 comments on commit 0355da1

Please sign in to comment.