Bug 138265 - Sort userlist by channel activity
Summary: Sort userlist by channel activity
Status: RESOLVED FIXED
Alias: None
Product: konversation
Classification: Applications
Component: general (show other bugs)
Version: unspecified
Platform: Compiled Sources Linux
: NOR wishlist
Target Milestone: ---
Assignee: Konversation Developers
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-12-02 22:22 UTC by Luke-Jr
Modified: 2007-04-19 11:10 UTC (History)
0 users

See Also:
Latest Commit:
Version Fixed In:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Luke-Jr 2006-12-02 22:22:15 UTC
Version:            (using KDE Devel)
Installed from:    Compiled sources

It'd be nice to sort the channel's userlist by activity within the channel.
Comment 1 Stefan Monov 2007-03-02 19:08:05 UTC
Yep.
Comment 2 Stefan Monov 2007-03-05 05:22:16 UTC
SVN commit 639395 by logixoul:

BUG: 138265 adding option to sort the nicklist by the channel activity for the last 5 minutes

 M  +10 -2     channel.cpp  
 M  +1 -0      channel.h  
 M  +17 -0     channelnick.cpp  
 M  +7 -1      channelnick.h  
 M  +5 -0      config/konversation.kcfg  
 M  +11 -3     nicklistbehavior_preferencesui.ui  
 M  +21 -23    nicklistviewitem.cpp  
 M  +1 -1      nicklistviewitem.h  


--- trunk/extragear/network/konversation/src/channel.cpp #639394:639395
@@ -2590,8 +2590,9 @@
   emit banListCleared();
 }
 
-void Channel::append(const QString& nickname,const QString& message)
+void Channel::append(const QString& nickname, const QString& message)
 {
+    nickActive(nickname);
     if(nickname != getServer()->getNickname()) {
         Nick* nick = getNickByName(nickname);
 
@@ -2603,8 +2604,9 @@
     ChatWindow::append(nickname, message);
 }
 
-void Channel::appendAction(const QString& nickname,const QString& message, bool usenotifications)
+void Channel::appendAction(const QString& nickname, const QString& message, bool usenotifications)
 {
+    nickActive(nickname);
     if(nickname != getServer()->getNickname()) {
         Nick* nick = getNickByName(nickname);
 
@@ -2616,6 +2618,12 @@
     ChatWindow::appendAction(nickname, message, usenotifications);
 }
 
+void Channel::nickActive(const QString& nickname)
+{
+    getChannelNick(nickname)->moreActive();
+    sortNickList(); //FIXME: no need to completely resort, we can just see if this particular nick should move
+}
+
 //
 // NickList
 //
--- trunk/extragear/network/konversation/src/channel.h #639394:639395
@@ -86,6 +86,7 @@
 
         virtual void append(const QString& nickname,const QString& message);
         virtual void appendAction(const QString& nickname,const QString& message, bool usenotifications = false);
+        void nickActive(const QString& nickname);
 
 //General administrative stuff
     public:
--- trunk/extragear/network/konversation/src/channelnick.cpp #639394:639395
@@ -33,6 +33,7 @@
     this->ishalfop = ishalfop;
     this->hasvoice = hasvoice;
     m_timeStamp = 0;
+    m_recentActivity = 0;
 }
 
 ChannelNick::~ChannelNick()
@@ -234,6 +235,22 @@
   return m_timeStamp;
 }
 
+uint ChannelNick::recentActivity() const
+{
+    return m_recentActivity;
+}
+
+void ChannelNick::moreActive()
+{
+    m_recentActivity++;
+    QTimer::singleShot(5*60*1000, this, SLOT(lessActive())); //only care about the last several minutes
+}
+
+void ChannelNick::lessActive()
+{
+    m_recentActivity--;
+}
+
 void ChannelNick::setTimeStamp(uint stamp)
 {
   m_timeStamp = stamp;
--- trunk/extragear/network/konversation/src/channelnick.h #639394:639395
@@ -38,6 +38,8 @@
         bool isAnyTypeOfOp() const;
         bool hasVoice() const;
         uint timeStamp() const;
+        uint recentActivity() const;
+        void moreActive();
 
         bool setVoice(bool state);
         bool setOp(bool state);
@@ -50,7 +52,7 @@
         void setTimeStamp(uint stamp);
 
         NickInfoPtr getNickInfo() const;
-        //Purely provided for convience because they are used so often.
+        //Purely provided for convenience because they are used so often.
         //Just calls nickInfo->getNickname() etc
         QString getNickname() const;
         QString loweredNickname() const;
@@ -64,9 +66,13 @@
         bool ishalfop;
         bool hasvoice;
         uint m_timeStamp;
+        uint m_recentActivity;
 
     signals:
         void channelNickChanged();
+
+    private slots:
+        void lessActive();
 };
 
 /** A ChannelNickPtr is a pointer to a ChannelNick.  Since it is a KSharedPtr,
--- trunk/extragear/network/konversation/src/config/konversation.kcfg #639394:639395
@@ -421,6 +421,11 @@
       <label></label>
       <whatsthis></whatsthis>
     </entry>
+    <entry key="SortByActivity" type="Bool">
+      <default>false</default>
+      <label></label>
+      <whatsthis></whatsthis>
+    </entry>
     <entry key="SortCaseInsensitive" type="Bool">
       <default>true</default>
       <label></label>
--- trunk/extragear/network/konversation/src/nicklistbehavior_preferencesui.ui #639394:639395
@@ -44,8 +44,16 @@
                 <string>Sort case &amp;insensitive</string>
             </property>
         </widget>
-        <widget class="QCheckBox" row="2" column="0">
+        <widget class="QCheckBox" row="2" column="0" rowspan="1" colspan="3">
             <property name="name">
+                <cstring>kcfg_SortByActivity</cstring>
+            </property>
+            <property name="text">
+                <string>Sort by &amp;activity</string>
+            </property>
+        </widget>
+        <widget class="QCheckBox" row="3" column="0">
+            <property name="name">
                 <cstring>kcfg_SortByStatus</cstring>
             </property>
             <property name="sizePolicy">
@@ -60,7 +68,7 @@
                 <string>Sort b&amp;y user status</string>
             </property>
         </widget>
-        <widget class="KListView" row="3" column="0" rowspan="1" colspan="3">
+        <widget class="KListView" row="4" column="0" rowspan="1" colspan="3">
             <column>
                 <property name="text">
                     <string>Mode</string>
@@ -110,7 +118,7 @@
                 <cstring>kcfg_ChannelDoubleClickAction</cstring>
             </property>
         </widget>
-        <widget class="QLabel" row="2" column="1" rowspan="1" colspan="2">
+        <widget class="QLabel" row="3" column="1" rowspan="1" colspan="2">
             <property name="name">
                 <cstring>orderHintLabel</cstring>
             </property>
--- trunk/extragear/network/konversation/src/nicklistviewitem.cpp #639394:639395
@@ -148,6 +148,20 @@
 {
     NickListViewItem* otherItem = static_cast<NickListViewItem*>(item);
 
+    if(Preferences::sortByActivity())
+    {
+        uint thisRecentActivity = nick->getChannelNick()->recentActivity();
+        uint otherRecentActivity = otherItem->getNick()->getChannelNick()->recentActivity();
+        if(thisRecentActivity > otherRecentActivity)
+        {
+            return -1;
+        }
+        if(thisRecentActivity < otherRecentActivity)
+        {
+            return 1;
+        }
+    }
+
     if(Preferences::sortByStatus())
     {
         int thisFlags = getSortingValue();
@@ -166,31 +180,15 @@
     QString thisKey;
     QString otherKey;
 
-    if(col > 1)
+    if(Preferences::sortCaseInsensitive())
     {
-        if(Preferences::sortCaseInsensitive())
-        {
-            thisKey = thisKey.lower();
-            otherKey = otherKey.lower();
-        }
-        else
-        {
-            thisKey = key(col, ascending);
-            otherKey = otherItem->key(col, ascending);
-        }
+        thisKey = nick->loweredNickname();
+        otherKey = otherItem->getNick()->loweredNickname();
     }
-    else if(col == 1)
+    else
     {
-        if(Preferences::sortCaseInsensitive())
-        {
-            thisKey = nick->loweredNickname();
-            otherKey = otherItem->getNick()->loweredNickname();
-        }
-        else
-        {
-            thisKey = key(col, ascending);
-            otherKey = otherItem->key(col, ascending);
-        }
+        thisKey = key(col, ascending);
+        otherKey = otherItem->key(col, ascending);
     }
 
     return thisKey.compare(otherKey);
@@ -224,7 +222,7 @@
     return flags;
 }
 
-Nick *NickListViewItem::getNick()
+Nick *NickListViewItem::getNick() const
 {
     return nick;
 }
--- trunk/extragear/network/konversation/src/nicklistviewitem.h #639394:639395
@@ -39,7 +39,7 @@
         // returns a number thar represents the sorting order for the nicknames
         int getSortingValue() const;
         // get the Nick object
-        Nick *getNick();
+        Nick *getNick() const;
 
         virtual void paintCell(QPainter * p, const QColorGroup & cg, int column, int width, int align);
         virtual int compare(QListViewItem* item,int col,bool ascending) const;
Comment 3 Eike Hein 2007-03-05 12:06:29 UTC
The current approach doesn't work very intuitively yet, IMO. If people idle for a certain amount time they get kicked out of the activity sorting process back into alphabetical sorting and/or user status sorting regardless of overall channel activity, which breaks the perceived purpose of the mode (find the latest active chatters at the top of the nicklist) in low-traffic channels. The "Sort by activity" mode should probably fall back to a timestamp of the most recent activity (which is already stored in ChannelNick to boot, iirc) beyond the five minute smoothing thing.
Comment 4 Stefan Monov 2007-04-19 11:10:30 UTC
Should be good now :)