=== modified file 'Ubuntu/History/historymodel.cpp'
--- Ubuntu/History/historymodel.cpp	2016-11-09 17:42:27 +0000
+++ Ubuntu/History/historymodel.cpp	2016-11-24 01:11:43 +0000
@@ -94,40 +94,29 @@
         break;
     case ParticipantsRole: {
         // FIXME: reimplement in a cleaner way
-        History::Participants participants = History::Participants::fromVariantList(properties[History::FieldParticipants].toList());
+        History::Participants participants = History::Participants::fromVariantList(properties[History::FieldParticipants].toList())
+                                             .filterByState(History::ParticipantStateRegular);
         if (mMatchContacts) {
             QVariantList finalParticipantsList;
             QVariantList participantsInfo = History::ContactMatcher::instance()->contactInfo(properties[History::FieldAccountId].toString(),
-                                                                      participants.identifiers());
-            int count = 0;
-            Q_FOREACH(const QVariant &participantInfo, participantsInfo) {
-                QVariantMap newMap = participantInfo.toMap();
-                if (participants.at(count).state() != History::ParticipantStateRegular) {
-                   count++;
-                   continue;
-                }
-                newMap[History::FieldParticipantState] = participants.at(count).state();
-                newMap[History::FieldParticipantRoles] = participants.at(count++).roles();
+                                                                                             participants.identifiers());
+            for (int i = 0; i < participantsInfo.count(); ++i) {
+                QVariantMap newMap = participantsInfo[i].toMap();
+                History::Participant participant = participants[i];
+                newMap[History::FieldParticipantState] = participant.state();
+                newMap[History::FieldParticipantRoles] = participant.roles();
                 finalParticipantsList << newMap;
             }
             result = finalParticipantsList;
         } else {
             //FIXME: handle contact changes
-            result = properties[History::FieldParticipants];
+            result = participants.identifiers();
         }
         break;
     }
     case ParticipantsRemotePendingRole: {
-        // FIXME: reimplement in a cleaner way
-        QStringList identifiers;
-        History::Participants participants;
-        // filter remote pending participants
-        Q_FOREACH(const History::Participant &participant, History::Participants::fromVariantList(properties[History::FieldParticipants].toList())) {
-            if (participant.state() == History::ParticipantStateRemotePending) {
-                participants << participant;
-            }
-        }
-
+        History::Participants participants = History::Participants::fromVariantList(properties[History::FieldParticipants].toList())
+                                             .filterByState(History::ParticipantStateRemotePending);
         if (mMatchContacts) {
             QVariantList finalParticipantsList;
             QVariantList participantsInfo = History::ContactMatcher::instance()->contactInfo(properties[History::FieldAccountId].toString(),
@@ -148,19 +137,12 @@
         break;
     }
     case ParticipantsLocalPendingRole: {
-        // FIXME: reimplement in a cleaner way
-        QStringList identifiers;
-        History::Participants participants;
-        Q_FOREACH(const History::Participant &participant, History::Participants::fromVariantList(properties[History::FieldParticipants].toList())) {
-            if (participant.state() == History::ParticipantStateLocalPending) {
-                participants << participant;
-            }
-        }
-
+        History::Participants participants = History::Participants::fromVariantList(properties[History::FieldParticipants].toList())
+                                             .filterByState(History::ParticipantStateLocalPending);
         if (mMatchContacts) {
             QVariantList finalParticipantsList;
             QVariantList participantsInfo = History::ContactMatcher::instance()->contactInfo(properties[History::FieldAccountId].toString(),
-                                                                      identifiers);
+                                                                      participants.identifiers());
             int count = 0;
             Q_FOREACH(const QVariant &participantInfo, participantsInfo) {
                 QVariantMap newMap = participantInfo.toMap();
@@ -171,7 +153,7 @@
             result = finalParticipantsList;
         } else {
             //FIXME: handle contact changes
-            result = identifiers;
+            result = participants.identifiers();
         }
 
         break;

=== modified file 'src/participant.cpp'
--- src/participant.cpp	2016-08-25 03:19:41 +0000
+++ src/participant.cpp	2016-11-24 01:11:43 +0000
@@ -242,6 +242,17 @@
     return list;
 }
 
+Participants Participants::filterByState(uint state) const
+{
+    Participants filtered;
+    Q_FOREACH(const Participant &participant, *this) {
+        if (participant.state() == state) {
+            filtered << participant;
+        }
+    }
+    return filtered;
+}
+
 const QDBusArgument &operator>>(const QDBusArgument &argument, Participants &participants)
 {
     argument.beginArray();

=== modified file 'src/participant.h'
--- src/participant.h	2016-08-25 03:19:41 +0000
+++ src/participant.h	2016-11-24 01:11:43 +0000
@@ -81,7 +81,7 @@
     static Participants fromVariantList(const QVariantList &list);
     static Participants fromStringList(const QStringList &list);
     QVariantList toVariantList() const;
-
+    History::Participants filterByState(uint state) const;
 };
 
 const QDBusArgument &operator>>(const QDBusArgument &argument, Participants &participants);

