From 600c370ed33ec9828ef609d68a8e46d564f0f1af Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Wed, 29 Apr 2015 21:36:44 +0300 Subject: eathena: impliment packet SMSG_MAIL_RETURN. --- src/gui/windows/mailwindow.cpp | 31 +++++++++++++++++++++++++++++++ src/gui/windows/mailwindow.h | 2 ++ src/net/eathena/mailhandler.cpp | 15 +++++++++++---- src/resources/notifications.h | 8 ++++++++ src/resources/notifytypes.h | 2 ++ 5 files changed, 54 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/gui/windows/mailwindow.cpp b/src/gui/windows/mailwindow.cpp index 15faf779a..ecef7b54e 100644 --- a/src/gui/windows/mailwindow.cpp +++ b/src/gui/windows/mailwindow.cpp @@ -164,6 +164,37 @@ void MailWindow::addMail(MailMessage *const message) mMessagesMap[message->id] = message; } +void MailWindow::removeMail(const int id) +{ + std::map::iterator it1 = mMessagesMap.find(id); + if (it1 != mMessagesMap.end()) + mMessagesMap.erase(it1); + + mMailModel->clear(); + + FOR_EACH (std::vector::iterator, it, mMessages) + { + MailMessage *message = *it; + if (message && message->id == id) + { + mMessages.erase(it); + delete message; + break; + } + } + + FOR_EACH (std::vector::iterator, it, mMessages) + { + MailMessage *message = *it; + if (message) + { + mMailModel->add(strprintf("%s %s", + message->unread ? " " : "U", + message->title.c_str())); + } + } +} + void MailWindow::showMessage(MailMessage *const mail) { if (!mail) diff --git a/src/gui/windows/mailwindow.h b/src/gui/windows/mailwindow.h index 15964aafe..23f89be0a 100644 --- a/src/gui/windows/mailwindow.h +++ b/src/gui/windows/mailwindow.h @@ -56,6 +56,8 @@ class MailWindow final : public Window, void showMessage(MailMessage *const mail); + void removeMail(const int id); + private: std::vector mMessages; std::map mMessagesMap; diff --git a/src/net/eathena/mailhandler.cpp b/src/net/eathena/mailhandler.cpp index bebd4b10b..e40d34e17 100644 --- a/src/net/eathena/mailhandler.cpp +++ b/src/net/eathena/mailhandler.cpp @@ -227,10 +227,17 @@ void MailHandler::processDeleteAck(Net::MessageIn &msg) void MailHandler::processMailReturn(Net::MessageIn &msg) { - UNIMPLIMENTEDPACKET; - - msg.readInt32("message id"); - msg.readInt16("fail flag"); + const int mail = msg.readInt32("message id"); + const int flag = msg.readInt16("fail flag"); + if (flag) + { + NotifyManager::notify(NotifyTypes::MAIL_RETURN_ERROR); + } + else + { + NotifyManager::notify(NotifyTypes::MAIL_RETURN_OK); + mailWindow->removeMail(mail); + } } void MailHandler::refresh() diff --git a/src/resources/notifications.h b/src/resources/notifications.h index 7c864325b..0aa9d1c08 100644 --- a/src/resources/notifications.h +++ b/src/resources/notifications.h @@ -583,6 +583,14 @@ namespace NotifyManager // TRANSLATORS: notification message N_("Money attach failed."), NotifyFlags::EMPTY}, + {"mail return error", + // TRANSLATORS: notification message + N_("Message return failed."), + NotifyFlags::EMPTY}, + {"mail return ok", + // TRANSLATORS: notification message + N_("Message return success."), + NotifyFlags::EMPTY}, }; } // namespace NotifyManager #endif // RESOURCES_NOTIFICATIONS_H diff --git a/src/resources/notifytypes.h b/src/resources/notifytypes.h index cdd6a22d0..36792b6b9 100644 --- a/src/resources/notifytypes.h +++ b/src/resources/notifytypes.h @@ -164,6 +164,8 @@ namespace NotifyTypes MAIL_SEND_ERROR, MAIL_ATTACH_ITEM_ERROR, MAIL_ATTACH_MONEY_ERROR, + MAIL_RETURN_ERROR, + MAIL_RETURN_OK, TYPE_END }; -- cgit v1.2.3-70-g09d2