-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathChatRoom.cpp
37 lines (28 loc) · 897 Bytes
/
ChatRoom.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include "ChatRoom.h"
#include <ctime>
ChatRoom::ChatRoom() {}
ChatRoom::ChatRoom(int message_lifetime, int message_rate_limit)
: message_lifetime(message_lifetime), message_rate_limit(message_rate_limit) {}
bool ChatRoom::add_message(const std::string &content) {
if (!content.empty()) {
messages.push({content});
}
// clean_up();
return true;
}
std::string ChatRoom::get_chat_history() {
// clean_up();
std::string chat_history;
std::queue<Message> temp_messages = messages;
while (!temp_messages.empty()) {
chat_history += temp_messages.front().content + "\n";
temp_messages.pop();
}
return chat_history;
}
void ChatRoom::clean_up() {
time_t current_time = std::time(nullptr);
// while (!messages.empty() && current_time - messages.front().timestamp > message_lifetime) {
// messages.pop();
// }
}