changed to singular recipient
This commit is contained in:
parent
8ac543e61d
commit
a2b17e6dd6
@ -41,7 +41,7 @@ json mail::mailToJson()
|
||||
jsonfile["id"] = this->id;
|
||||
jsonfile["timestamp"] = this->timestamp;
|
||||
jsonfile["sender"] = this->sender;
|
||||
jsonfile["recipients"] = this->recipients;
|
||||
jsonfile["recipients"] = this->recipient;
|
||||
jsonfile["subject"] = this->subject;
|
||||
jsonfile["filename"] = this->filename;
|
||||
jsonfile["deleted"] = this->deleted;
|
||||
|
||||
@ -18,7 +18,7 @@ struct mail {
|
||||
u_int id;
|
||||
int64_t timestamp;
|
||||
std::string sender;
|
||||
std::vector<std::string> recipients;
|
||||
std::string recipient;
|
||||
std::string subject;
|
||||
|
||||
bool deleted;
|
||||
|
||||
@ -389,7 +389,7 @@ std::string cmdSEND(std::vector<std::string>& received)
|
||||
|
||||
user_handler::getInstance().getOrCreateUser(received.at(1))->sendMail(
|
||||
new struct mail(saveToFile(user_handler::getInstance().getSpoolDir()/"messages", received.at(4)), received.at(3)),
|
||||
{received.at(2)}
|
||||
received.at(2)
|
||||
);
|
||||
|
||||
return "OK\n"; // TODO: error handling
|
||||
|
||||
@ -26,7 +26,7 @@ user::user(fs::path user_data_json) : m()
|
||||
);
|
||||
mail->id = mail_json["id"];
|
||||
mail->sender = mail_json["sender"];
|
||||
mail->recipients = mail_json["recipients"].get<std::vector<std::string>>();
|
||||
mail->recipient = mail_json["recipient"];
|
||||
mail->deleted = mail_json["deleted"];
|
||||
|
||||
this->inbox.insert(mail);
|
||||
@ -84,33 +84,25 @@ void user::addMail(mail* mail)
|
||||
this->user_data["mails"]["received"][std::to_string(mail->id)] = mail->mailToJson();
|
||||
}
|
||||
|
||||
void user::sendMail(mail* mail, std::vector<std::string> recipients)
|
||||
void user::sendMail(mail* mail, std::string recipient)
|
||||
{
|
||||
std::lock_guard<std::mutex> guard(this->m);
|
||||
|
||||
std::vector<user*> users;
|
||||
for ( auto& name : recipients) {
|
||||
// TODO: error handling for non existing user
|
||||
users.push_back(user_handler::getInstance().getOrCreateUser(name));
|
||||
}
|
||||
|
||||
mail->sender = this->name;
|
||||
mail->recipients = recipients;
|
||||
mail->recipient = recipient;
|
||||
|
||||
mail->id = this->sent.size();
|
||||
|
||||
this->sent.insert(mail);
|
||||
this->user_data["mails"]["sent"][std::to_string(mail->id)] = mail->mailToJson();
|
||||
|
||||
for ( auto& user : users ) {
|
||||
user->addMail(mail);
|
||||
}
|
||||
user_handler::getInstance().getOrCreateUser(recipient)->addMail(mail);
|
||||
}
|
||||
|
||||
mail* user::getMail(u_int id)
|
||||
{
|
||||
maillist::iterator it = std::find_if(this->inbox.begin(), this->inbox.end(), [id](auto& i){ return (*i)(id); });
|
||||
return it == this->inbox.end() ? nullptr : (*it)->filename.empty() ? nullptr : *it;
|
||||
return it == this->inbox.end() ? nullptr : (*it)->filename.empty() ? nullptr : *it; // TODO: potentially not thread safe, research if iterator points to
|
||||
}
|
||||
|
||||
bool user::delMail(u_int id)
|
||||
|
||||
@ -22,7 +22,7 @@ public:
|
||||
~user();
|
||||
|
||||
void addMail(mail* mail);
|
||||
void sendMail(mail* mail, std::vector<std::string> recipients);
|
||||
void sendMail(mail* mail, std::string recipient);
|
||||
|
||||
mail* getMail(u_int id);
|
||||
bool delMail(u_int id);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user