* @param[in] msgIdList list of message identifiers relevant to this notification.
*/
virtual void onMsgStorageContact(const MsgIdList &msgIdList) {};
+
+ /**
+ * @brief Message-storage updates for the given thread.
+ * @param[in] threadId Id of updated conversation.
+ */
+ virtual void onMsgStorageThreadUpdate(const ThreadId &threadId) {};
+
+ /**
+ * @brief Notification about new thread addition.
+ * @param[in] threadId Id of created conversation.
+ */
+ virtual void onMsgStorageThreadInsert(const ThreadId &threadId) {};
+
+ /**
+ * @brief Notification about thread deletion.
+ * @param[in] threadId Id of deleted conversation.
+ */
+ virtual void onMsgStorageThreadDelete(const ThreadId &threadId) {};
+
+ /**
+ * @brief Notifies that recipient stored in contacts was updated.
+ * @param[in] threadId Id of conversation identifier relevant to this notification.
+ */
+ virtual void onMsgStorageThreadContact(const ThreadId &threadId) {};
};
}
{
TRACE;
msg_reg_storage_change_callback(m_ServiceHandle, msg_storage_change_cb, this);
+ msg_reg_thread_change_callback(m_ServiceHandle, msg_thread_change_cb, this);
}
-void MsgStoragePrivate::notifyListeners(const MsgIdList &idList, ListenerMethod method)
+template <typename T>
+void MsgStoragePrivate::notifyListeners(const T& delta, ListenerMethod<T> method)
{
for(auto listener: m_Listeners)
{
- (listener->*method)(idList);
+ (listener->*method)(delta);
}
}
}
}
+void MsgStoragePrivate::msg_thread_change_cb(msg_handle_t handle, msg_storage_change_type_t storageChangeType, msg_thread_id_t threadId, void *user_param)
+{
+ TRACE;
+ MsgStoragePrivate *self = static_cast<MsgStoragePrivate *>(user_param);
+ ThreadId tId = static_cast<ThreadId>(threadId);
+
+ switch(storageChangeType)
+ {
+ case MSG_STORAGE_CHANGE_UPDATE:
+ self->notifyListeners(tId, &IMsgStorageListener::onMsgStorageThreadUpdate);
+ break;
+ case MSG_STORAGE_CHANGE_INSERT:
+ self->notifyListeners(tId, &IMsgStorageListener::onMsgStorageThreadInsert);
+ break;
+ case MSG_STORAGE_CHANGE_DELETE:
+ self->notifyListeners(tId, &IMsgStorageListener::onMsgStorageThreadDelete);
+ break;
+ case MSG_STORAGE_CHANGE_CONTACT:
+ self->notifyListeners(tId, &IMsgStorageListener::onMsgStorageThreadContact);
+ break;
+ }
+}
+
MsgStoragePrivate::~MsgStoragePrivate()
{
}
virtual MsgConversationItemRef getConversationItem(MsgId id);
private:
- typedef void (IMsgStorageListener::*ListenerMethod)(const MsgIdList &);
+ template <typename T>
+ using ListenerMethod = void (IMsgStorageListener::*)(const T&);
- void notifyListeners(const MsgIdList &idList, ListenerMethod method);
+ template <typename T>
+ void notifyListeners(const T& delta, ListenerMethod<T> method);
static void msg_storage_change_cb(msg_handle_t handle, msg_storage_change_type_t storageChangeType, msg_id_list_s *pMsgIdList, void *user_param);
+ static void msg_thread_change_cb(msg_handle_t handle, msg_storage_change_type_t storageChangeType, msg_thread_id_t threadId, void *user_param);
MessageSMS *createSms();
private:
// IMsgStorageListener:
- virtual void onMsgStorageUpdate(const MsgIdList &msgIdList);
- virtual void onMsgStorageInsert(const MsgIdList &msgIdList);
- virtual void onMsgStorageDelete(const MsgIdList &msgIdList);
+ virtual void onMsgStorageThreadUpdate(const ThreadId &threadId);
+ virtual void onMsgStorageThreadInsert(const ThreadId &threadId);
+ virtual void onMsgStorageThreadDelete(const ThreadId &threadId);
// IContactManagerListener:
virtual void onContactChanged();
virtual ~ThreadListItem();
ThreadId getThreadId() const;
- void update(const MsgThreadItem &threadItem);
- void update();
+ void updateModel(const MsgThreadItem &threadItem);
+ void updateModel();
private:
// ThreadListViewItem:
void ThreadList::update(ThreadListItem &item)
{
time_t time = item.getRawTime();
- item.update();
+ item.updateModel();
if(item.getRawTime() < time)
{
// TODO: JIRA issue TSAM-8683
{
// TODO: JIRA issue TSAM-8683
}
+ item.update();
}
std::set<ThreadId> ThreadList::getThreadIdSet(const MsgIdList &idList)
checkHandler(*it);
}
-void ThreadList::onMsgStorageUpdate(const MsgIdList &msgIdList)
+void ThreadList::onMsgStorageThreadUpdate(const ThreadId &threadId)
{
MSG_LOG("");
- updateItems(msgIdList);
+ auto* thread = getItem(threadId);
+ if(thread)
+ update(*thread);
}
-void ThreadList::onMsgStorageInsert(const MsgIdList &msgIdList)
+void ThreadList::onMsgStorageThreadInsert(const ThreadId &threadId)
{
MSG_LOG("");
- bool inserted = false;
- bool updated = false;
-
- auto threadSet = getThreadIdSet(msgIdList);
- for(ThreadId id : threadSet)
- {
- ThreadListItem *item = getItem(id);
- if(item)
- {
- update(*item);
- updated = true;
- }
- else
- {
- insertItem(id);
- inserted = true;
- }
- }
-
- if(inserted)
- updateSelectAllItem();
- if(updated)
- updateRealizedItems();
+ insertItem(threadId);
+ updateSelectAllItem();
if(m_pListener)
m_pListener->onThreadListChanged();
}
-void ThreadList::onMsgStorageDelete(const MsgIdList &msgIdList)
+void ThreadList::onMsgStorageThreadDelete(const ThreadId &threadId)
{
MSG_LOG("");
- deleteItems();
- updateItems(); // TODO: Inefficiently. How to get list of threads by dead msgIdList ?
+ auto* thread = getItem(threadId);
+ if(thread)
+ {
+ ListView::deleteItem(*thread);
+ updateSelectAllItem();
+ }
+
if(m_pListener)
m_pListener->onThreadListChanged();
}
: BaseThreadListItem(app)
, m_ThreadId()
{
- update(threadItem);
+ updateModel(threadItem);
}
ThreadListItem::~ThreadListItem()
return makeUnreadIcon(m_UnreadCount);
}
-void ThreadListItem::update(const MsgThreadItem &threadItem)
+void ThreadListItem::updateModel(const MsgThreadItem &threadItem)
{
m_ThreadId = threadItem.getId();
updateTime(threadItem.getTime());
}
-void ThreadListItem::update()
+void ThreadListItem::updateModel()
{
MsgThreadItemRef msgThread = m_App.getMsgEngine().getStorage().getThread(m_ThreadId);
if(msgThread)
- update(*msgThread);
+ updateModel(*msgThread);
}