Commit fcdd0160 authored by Rafał Malinowski's avatar Rafał Malinowski

messages: changed semantics of markAllMessagesAsRead

Signed-off-by: Rafał Malinowski's avatarRafał Malinowski <rafal.przemyslaw.malinowski@gmail.com>
parent 806a46cd
......@@ -147,7 +147,7 @@ ChatWidget * ChatWidgetManager::byChat(const Chat &chat, const bool create)
void ChatWidgetManager::chatWidgetCreated(ChatWidget *chatWidget)
{
// We need to append unread messages before chat widget container could mark them as read.
const QList<Message> &messages = loadUnreadMessages(chatWidget->chat());
auto messages = loadUnreadMessages(chatWidget->chat());
chatWidget->appendMessages(messages);
bool handled = false;
......@@ -163,11 +163,11 @@ void ChatWidgetManager::chatWidgetCreated(ChatWidget *chatWidget)
}
}
QList<Message> ChatWidgetManager::loadUnreadMessages(const Chat &chat)
QVector<Message> ChatWidgetManager::loadUnreadMessages(const Chat &chat)
{
const Chat &buddyChat = BuddyChatManager::instance()->buddyChat(chat);
const Chat &unreadChat = buddyChat ? buddyChat : chat;
const QList<Message> &unreadMessages = Core::instance()->unreadMessageRepository()->chatUnreadMessages(unreadChat);
auto buddyChat = BuddyChatManager::instance()->buddyChat(chat);
auto unreadChat = buddyChat ? buddyChat : chat;
auto unreadMessages = Core::instance()->unreadMessageRepository()->unreadMessagesForChat(unreadChat);
foreach (const Message &message, unreadMessages)
{
......
......@@ -156,7 +156,7 @@ private:
/**
* @todo remove - reading pending messages should be out of scope of this class
*/
QList<Message> loadUnreadMessages(const Chat &chat);
QVector<Message> loadUnreadMessages(const Chat &chat);
void openPersistedChatWindows();
bool shouldOpenChatWidget(const Message &message);
......
......@@ -477,7 +477,7 @@ QIcon ChatWidget::icon()
return KaduIcon("internet-group-chat").icon();
}
void ChatWidget::appendMessages(const QList<Message> &messages)
void ChatWidget::appendMessages(const QVector<Message> &messages)
{
if (messages.isEmpty())
return;
......
......@@ -163,7 +163,7 @@ public:
void close();
public slots:
void appendMessages(const QList<Message> &messages);
void appendMessages(const QVector<Message> &messages);
void appendMessage(const Message &message);
void sendMessage();
......
......@@ -237,7 +237,11 @@ void ChatWindow::changeEvent(QEvent *event)
if (_isActiveWindow(this))
{
if (m_unreadMessageRepository)
m_unreadMessageRepository.data()->markAllMessagesAsRead(m_chatWidget->chat());
{
auto messages = m_unreadMessageRepository.data()->unreadMessagesForChat(m_chatWidget->chat());
m_unreadMessageRepository.data()->markMessagesAsRead(messages);
}
setWindowTitle(m_chatWidget->title());
m_titleTimer->stop();
}
......@@ -269,7 +273,10 @@ void ChatWindow::alertChatWidget(ChatWidget *chatWidget)
if (isChatWidgetActive(chatWidget))
{
if (m_unreadMessageRepository)
m_unreadMessageRepository.data()->markAllMessagesAsRead(m_chatWidget->chat());
{
auto messages = m_unreadMessageRepository.data()->unreadMessagesForChat(m_chatWidget->chat());
m_unreadMessageRepository.data()->markMessagesAsRead(messages);
}
return;
}
......
......@@ -135,9 +135,9 @@ const QList<Message> & UnreadMessageRepository::allUnreadMessages() const
return UnreadMessages;
}
QList<Message> UnreadMessageRepository::chatUnreadMessages(const Chat &chat) const
QVector<Message> UnreadMessageRepository::unreadMessagesForChat(const Chat &chat) const
{
auto result = QList<Message>();
auto result = QVector<Message>();
auto chats = QSet<Chat>();
auto details = chat.details();
......@@ -166,20 +166,17 @@ quint16 UnreadMessageRepository::unreadMessagesCount() const
return UnreadMessages.count();
}
void UnreadMessageRepository::markAllMessagesAsRead(const Chat &chat)
void UnreadMessageRepository::markMessagesAsRead(const QVector<Message> &messages)
{
auto messages = chatUnreadMessages(chat);
foreach (const auto &message, messages)
{
UnreadMessages.removeAll(message);
message.setStatus(MessageStatusRead);
message.setPending(false);
message.data()->removeFromStorage();
if (UnreadMessages.removeAll(message) > 0)
{
message.setStatus(MessageStatusRead);
message.setPending(false);
message.data()->removeFromStorage();
emit unreadMessageRemoved(message);
}
emit unreadMessageRemoved(message);
}
}
Message UnreadMessageRepository::unreadMessage() const
......
......@@ -88,7 +88,7 @@ public:
*
* Returns list of all unread messages for given chat.
*/
QList<Message> chatUnreadMessages(const Chat &chat) const;
QVector<Message> unreadMessagesForChat(const Chat &chat) const;
/**
* @short Returns true if there is any unread message in manager.
......@@ -109,15 +109,15 @@ public:
quint16 unreadMessagesCount() const;
/**
* @short Marks all unread messages of given chat as read.
* @short Marks messages from list as read.
* @author Rafał 'Vogel' Malinowski
* @param chat chat to operate on
* @param messages list of messages to be marked as read
*
* Marks all unread messages of given chat as read. Messages are removed from unread list, its statuses
* Marks given messages as read. Messages are removed from unread list, its statuses
* are updated to MessageStatusRead and its pending statues are set to false.
* Signal unreadMessageRemoved is emited for each changed message.
*/
void markAllMessagesAsRead(const Chat &chat);
void markMessagesAsRead(const QVector<Message> &messages);
/**
* @short Returns one of unread messages.
......
......@@ -329,7 +329,7 @@ void HintManager::processButtonPress(const QString &buttonName, Hint *hint)
case 2:
if (hint->chat() && config_file.readBoolEntry("Hints", "DeletePendingMsgWhenHintDeleted"))
{
QList<Message> unreadMessages = Core::instance()->unreadMessageRepository()->chatUnreadMessages(hint->chat());
auto unreadMessages = Core::instance()->unreadMessageRepository()->unreadMessagesForChat(hint->chat());
foreach (const Message &message, unreadMessages)
{
message.setStatus(MessageStatusRead);
......
......@@ -180,7 +180,8 @@ void SingleWindow::changeEvent(QEvent *event)
ChatWidget *chatWidget = static_cast<ChatWidget *>(m_tabs->currentWidget());
if (chatWidget && _isActiveWindow(this))
{
Core::instance()->unreadMessageRepository()->markAllMessagesAsRead(chatWidget->chat());
auto messages = Core::instance()->unreadMessageRepository()->unreadMessagesForChat(chatWidget->chat());
Core::instance()->unreadMessageRepository()->markMessagesAsRead(messages);
updateTabIcon(chatWidget);
updateTabName(chatWidget);
}
......@@ -322,7 +323,8 @@ void SingleWindow::alertChatWidget(ChatWidget *chatWidget)
if (isChatWidgetActive(chatWidget))
{
Core::instance()->unreadMessageRepository()->markAllMessagesAsRead(chatWidget->chat());
auto messages = Core::instance()->unreadMessageRepository()->unreadMessagesForChat(chatWidget->chat());
Core::instance()->unreadMessageRepository()->markMessagesAsRead(messages);
return;
}
......@@ -351,7 +353,10 @@ void SingleWindow::onTabChange(int index)
return;
ChatWidget *chatWidget = (ChatWidget *)m_tabs->widget(index);
Core::instance()->unreadMessageRepository()->markAllMessagesAsRead(chatWidget->chat());
auto messages = Core::instance()->unreadMessageRepository()->unreadMessagesForChat(chatWidget->chat());
Core::instance()->unreadMessageRepository()->markMessagesAsRead(messages);
updateTabIcon(chatWidget);
updateTabName(chatWidget);
}
......
......@@ -208,7 +208,8 @@ void TabWidget::alertChatWidget(ChatWidget *chatWidget)
if (isChatWidgetActive(chatWidget))
{
Core::instance()->unreadMessageRepository()->markAllMessagesAsRead(chatWidget->chat());
auto messages = Core::instance()->unreadMessageRepository()->unreadMessagesForChat(chatWidget->chat());
Core::instance()->unreadMessageRepository()->markMessagesAsRead(messages);
return;
}
......@@ -428,7 +429,10 @@ void TabWidget::changeEvent(QEvent *event)
kdebugf();
ChatWidget *chatWidget = static_cast<ChatWidget *>(currentWidget());
if (chatWidget && _isActiveWindow(this))
Core::instance()->unreadMessageRepository()->markAllMessagesAsRead(chatWidget->chat());
{
auto messages = Core::instance()->unreadMessageRepository()->unreadMessagesForChat(chatWidget->chat());
Core::instance()->unreadMessageRepository()->markMessagesAsRead(messages);
}
kdebugf2();
}
}
......
......@@ -283,7 +283,8 @@ void TabsManager::onTabChange(int index)
const Chat &chat = chatWidget->chat();
if (chat.unreadMessagesCount() > 0)
{
Core::instance()->unreadMessageRepository()->markAllMessagesAsRead(chat);
auto messages = Core::instance()->unreadMessageRepository()->unreadMessagesForChat(chat);
Core::instance()->unreadMessageRepository()->markMessagesAsRead(messages);
updateTabName(chatWidget);
removeChatWidgetFromChatWidgetsWithMessage(chatWidget);
......@@ -423,7 +424,8 @@ void TabsManager::onTimer()
{
if (currentChatWidget == chatWidget)
{
Core::instance()->unreadMessageRepository()->markAllMessagesAsRead(chatWidget->chat());
auto messages = Core::instance()->unreadMessageRepository()->unreadMessagesForChat(chatWidget->chat());
Core::instance()->unreadMessageRepository()->markMessagesAsRead(messages);
removeChatWidgetFromChatWidgetsWithMessage(chatWidget);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment