Skip to content

Commit

Permalink
Alter the definition of ObservedConversation to allow observing multi…
Browse files Browse the repository at this point in the history
…ple groups

This is a minorly backwards-incompatible change.

The ObservedConversation property now expects a QVariantList with each
item a QVariantList containing (string, string, uint). Previously, it
accepted only one such list.
  • Loading branch information
John Brooks committed Apr 3, 2013
1 parent 33df7bb commit 1d1fff2
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 40 deletions.
68 changes: 31 additions & 37 deletions src/notificationmanager.cpp
Expand Up @@ -360,10 +360,6 @@ bool NotificationManager::isCurrentlyObservedByUI(const CommHistory::Event& even
const QString &channelTargetId,
CommHistory::Group::ChatType chatType)
{
if (m_ObservedChannelLocalId.isNull()
|| m_ObservedChannelRemoteId.isNull())
return false;

// Return false if it's not message event (IM or SMS/MMS)
CommHistory::Event::EventType eventType = event.type();
if (eventType != CommHistory::Event::IMEvent
Expand All @@ -373,30 +369,36 @@ bool NotificationManager::isCurrentlyObservedByUI(const CommHistory::Event& even
return false;
}

bool remoteIdMatch = false;
bool localIdMatch = false;
bool chatTypeMatch = false;

// check contextkit property status, if not ready, we assume
// ui is not observed
if (m_ObservedConversation) {
if (!m_ObservedConversation->value().isNull()) {
QString remoteMatch;
if (chatType == CommHistory::Group::ChatTypeP2P)
remoteMatch = event.remoteUid();
else
remoteMatch = channelTargetId;
if (!m_ObservedConversation)
return false;

remoteIdMatch = (CommHistory::remoteAddressMatch(remoteMatch,
m_ObservedChannelRemoteId));
QString remoteMatch;
if (chatType == CommHistory::Group::ChatTypeP2P)
remoteMatch = event.remoteUid();
else
remoteMatch = channelTargetId;

localIdMatch = MAP_MMS_TO_RING(event.localUid()) == m_ObservedChannelLocalId;
QVariantList conversations = m_ObservedConversation->value().toList();
foreach (const QVariant &conversation, conversations) {
QVariantList values = conversation.toList();
if (values.size() != 3)
continue;

chatTypeMatch = chatType == m_ObservedChannelChatType;
}
if (MAP_MMS_TO_RING(event.localUid()) != values[0].toString())
continue;

if (!CommHistory::remoteAddressMatch(remoteMatch, values[1].toString()))
continue;

if (chatType != (CommHistory::Group::ChatType)values[2].toUInt())
continue;

return true;
}

return localIdMatch && remoteIdMatch && chatTypeMatch;
return false;
}

void NotificationManager::removeNotifications(const QString &accountPath, bool messagesOnly)
Expand Down Expand Up @@ -486,22 +488,14 @@ void NotificationManager::removeConversationNotifications(const QString &localId
void NotificationManager::slotObservedConversationChanged()
{
if (m_ObservedConversation) {
QVariant value = m_ObservedConversation->value(QVariant());
if (!value.isNull()) {
QVariantList values = value.toList();
if (values.count() > 1) {
m_ObservedChannelLocalId = values.takeFirst().toString();
m_ObservedChannelRemoteId = values.takeFirst().toString();
m_ObservedChannelChatType = (CommHistory::Group::ChatType)(values.takeFirst().toUInt());

removeConversationNotifications(m_ObservedChannelLocalId,
m_ObservedChannelRemoteId,
m_ObservedChannelChatType);
}
} else {
m_ObservedChannelLocalId = QString();
m_ObservedChannelRemoteId = QString();
m_ObservedChannelChatType = CommHistory::Group::ChatTypeP2P;
QVariantList conversations = m_ObservedConversation->value(QVariant()).toList();
foreach (const QVariant &conversation, conversations) {
QVariantList values = conversation.toList();
if (values.size() != 3)
continue;

removeConversationNotifications(values[0].toString(), values[1].toString(),
(CommHistory::Group::ChatType)values[2].toUInt());
}
}
}
Expand Down
3 changes: 0 additions & 3 deletions src/notificationmanager.h
Expand Up @@ -228,9 +228,6 @@ private Q_SLOTS:
ContextProperty* m_ObservedInbox;
ContextProperty* m_FilteredInbox;
ContextProperty* m_ObservedCallHistory;
QString m_ObservedChannelLocalId;
QString m_ObservedChannelRemoteId;
CommHistory::Group::ChatType m_ObservedChannelChatType;
QFile m_Storage;
bool m_Initialised;

Expand Down

0 comments on commit 1d1fff2

Please sign in to comment.