regression fix: reallow offline players to be added to friendslist/ignore list
authorsheepluva
Sat, 30 Nov 2013 13:42:14 +0100
changeset 9725 68b5d87cfdb0
parent 9724 b3fefde4cff7
child 9726 dfdde45181ec
regression fix: reallow offline players to be added to friendslist/ignore list
QTfrontend/model/playerslistmodel.cpp
QTfrontend/model/playerslistmodel.h
--- a/QTfrontend/model/playerslistmodel.cpp	Sat Nov 30 11:14:32 2013 +0100
+++ b/QTfrontend/model/playerslistmodel.cpp	Sat Nov 30 13:42:14 2013 +0100
@@ -146,6 +146,25 @@
 
 void PlayersListModel::setFlag(const QString &nickname, StateFlag flagType, bool isSet)
 {
+    if(flagType == Friend)
+    {
+        if(isSet)
+            m_friendsSet.insert(nickname.toLower());
+        else
+            m_friendsSet.remove(nickname.toLower());
+
+        saveSet(m_friendsSet, "friends");
+    }
+    else if(flagType == Ignore)
+    {
+        if(isSet)
+            m_ignoredSet.insert(nickname.toLower());
+        else
+            m_ignoredSet.remove(nickname.toLower());
+
+        saveSet(m_ignoredSet, "ignore");
+    }
+
     QModelIndexList mil = match(index(0), Qt::DisplayRole, nickname, 1, Qt::MatchExactly);
 
     if(mil.size())
@@ -156,26 +175,6 @@
                 || flagType == Ignore || flagType == RoomAdmin)
             updateSortData(mil[0]);
 
-        if(flagType == Friend)
-        {
-            if(isSet)
-                m_friendsSet.insert(nickname.toLower());
-            else
-                m_friendsSet.remove(nickname.toLower());
-
-            saveSet(m_friendsSet, "friends");
-        }
-
-        if(flagType == Ignore)
-        {
-            if(isSet)
-                m_ignoredSet.insert(nickname.toLower());
-            else
-                m_ignoredSet.remove(nickname.toLower());
-
-            saveSet(m_ignoredSet, "ignore");
-        }
-
         updateIcon(mil[0]);
     }
 }
@@ -187,6 +186,10 @@
 
     if(mil.size())
         return mil[0].data(flagType).toBool();
+    else if(flagType == Friend)
+        return isFriend(nickname);
+    else if(flagType == Ignore)
+        return isIgnored(nickname);
     else
         return false;
 }
@@ -344,11 +347,20 @@
         checkFriendIgnore(index(i));
 }
 
+bool PlayersListModel::isFriend(const QString & nickname)
+{
+    return m_friendsSet.contains(nickname.toLower());
+}
+
+bool PlayersListModel::isIgnored(const QString & nickname)
+{
+    return m_ignoredSet.contains(nickname.toLower());
+}
 
 void PlayersListModel::checkFriendIgnore(const QModelIndex &mi)
 {
-    setData(mi, m_friendsSet.contains(mi.data().toString().toLower()), Friend);
-    setData(mi, m_ignoredSet.contains(mi.data().toString().toLower()), Ignore);
+    setData(mi, isFriend(mi.data().toString()), Friend);
+    setData(mi, isIgnored(mi.data().toString()), Ignore);
 
     updateIcon(mi);
     updateSortData(mi);
--- a/QTfrontend/model/playerslistmodel.h	Sat Nov 30 11:14:32 2013 +0100
+++ b/QTfrontend/model/playerslistmodel.h	Sat Nov 30 13:42:14 2013 +0100
@@ -71,6 +71,8 @@
     void loadSet(QSet<QString> & set, const QString & suffix);
     void saveSet(const QSet<QString> & set, const QString & suffix);
     void checkFriendIgnore(const QModelIndex & mi);
+    bool isFriend(const QString & nickname);
+    bool isIgnored(const QString & nickname);
 };
 
 #endif // PLAYERSLISTMODEL_H