changeset 1996:7837d5a3f509

Going back to the first buddy with /roster next_unread when there is no more unread messages.
author Simon Jacquin
date Sun, 22 May 2011 23:30:37 +0200
parents 7f7c6b87f1b1
children 555e342556e7
files mcabber/mcabber/roster.c mcabber/mcabber/roster.h mcabber/mcabber/screen.c
diffstat 3 files changed, 35 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/mcabber/mcabber/roster.c	Sat Apr 16 09:25:21 2011 +0200
+++ b/mcabber/mcabber/roster.c	Sun May 22 23:30:37 2011 +0200
@@ -127,6 +127,7 @@
 GList *buddylist;
 GList *current_buddy;
 GList *alternate_buddy;
+GList *last_activity_buddy;
 
 static roster roster_special;
 
@@ -960,6 +961,7 @@
   roster *roster_elt;
   roster *roster_current_buddy = NULL;
   roster *roster_alternate_buddy = NULL;
+  roster *roster_last_activity_buddy = NULL;
   int shrunk_group;
 
   // We need to remember which buddy is selected.
@@ -969,6 +971,9 @@
   if (alternate_buddy)
     roster_alternate_buddy = BUDDATA(alternate_buddy);
   alternate_buddy = NULL;
+  if (last_activity_buddy)
+    roster_last_activity_buddy = BUDDATA(last_activity_buddy);
+  last_activity_buddy = NULL;
 
   // Destroy old buddylist
   if (buddylist) {
@@ -1026,6 +1031,8 @@
     current_buddy = g_list_find(buddylist, roster_current_buddy);
   if (roster_alternate_buddy)
     alternate_buddy = g_list_find(buddylist, roster_alternate_buddy);
+  if (roster_last_activity_buddy)
+    last_activity_buddy = g_list_find(buddylist, roster_last_activity_buddy);
   // current_buddy initialization
   if (!current_buddy || (g_list_position(buddylist, current_buddy) == -1))
     current_buddy = g_list_first(buddylist);
--- a/mcabber/mcabber/roster.h	Sat Apr 16 09:25:21 2011 +0200
+++ b/mcabber/mcabber/roster.h	Sun May 22 23:30:37 2011 +0200
@@ -168,6 +168,7 @@
 extern GList *buddylist;
 extern GList *current_buddy;
 extern GList *alternate_buddy;
+extern GList *last_activity_buddy;
 
 // Macros...
 
--- a/mcabber/mcabber/screen.c	Sat Apr 16 09:25:21 2011 +0200
+++ b/mcabber/mcabber/screen.c	Sun May 22 23:30:37 2011 +0200
@@ -2393,8 +2393,10 @@
 void scr_roster_top(void)
 {
   set_current_buddy(buddylist);
-  if (chatmode)
+  if (chatmode) {
+    last_activity_buddy = current_buddy;
     scr_show_buddy_window();
+  }
 }
 
 //  scr_roster_bottom()
@@ -2402,8 +2404,10 @@
 void scr_roster_bottom(void)
 {
   set_current_buddy(g_list_last(buddylist));
-  if (chatmode)
+  if (chatmode) {
+    last_activity_buddy = current_buddy;
     scr_show_buddy_window();
+  }
 }
 
 //  scr_roster_up_down(updown, n)
@@ -2420,8 +2424,10 @@
     for (i = 0; i < n; i++)
       set_current_buddy(g_list_next(current_buddy));
   }
-  if (chatmode)
+  if (chatmode) {
+    last_activity_buddy = current_buddy;
     scr_show_buddy_window();
+  }
 }
 
 //  scr_roster_prev_group()
@@ -2436,8 +2442,10 @@
       break;
     if (buddy_gettype(BUDDATA(bud)) & ROSTER_TYPE_GROUP) {
       set_current_buddy(bud);
-      if (chatmode)
+      if (chatmode) {
+        last_activity_buddy = current_buddy;
         scr_show_buddy_window();
+      }
       break;
     }
   }
@@ -2455,8 +2463,10 @@
       break;
     if (buddy_gettype(BUDDATA(bud)) & ROSTER_TYPE_GROUP) {
       set_current_buddy(bud);
-      if (chatmode)
+      if (chatmode) {
+        last_activity_buddy = current_buddy;
         scr_show_buddy_window();
+      }
       break;
     }
   }
@@ -2467,8 +2477,10 @@
 void scr_roster_search(char *str)
 {
   set_current_buddy(buddy_search(str));
-  if (chatmode)
+  if (chatmode) {
+    last_activity_buddy = current_buddy;
     scr_show_buddy_window();
+  }
 }
 
 //  scr_roster_jump_jid(bjid)
@@ -2489,8 +2501,10 @@
   buddylist_build();
   // Jump to the buddy
   set_current_buddy(buddy_search_jid(barejid));
-  if (chatmode)
+  if (chatmode) {
+    last_activity_buddy = current_buddy;
     scr_show_buddy_window();
+  }
 }
 
 //  scr_roster_unread_message(next)
@@ -2509,7 +2523,11 @@
   else      refbuddata = NULL;
 
   unread_ptr = unread_msg(refbuddata);
-  if (!unread_ptr) return;
+  if (!unread_ptr) {
+    if (!last_activity_buddy || g_list_position(buddylist, last_activity_buddy) == -1)
+      return;
+    unread_ptr = BUDDATA(last_activity_buddy);
+  }
 
   if (!(buddy_gettype(unread_ptr) & ROSTER_TYPE_SPECIAL)) {
     gpointer ngroup;
@@ -3487,6 +3505,7 @@
 int readline_accept_line(int down_history)
 {
   scr_check_auto_away(TRUE);
+  last_activity_buddy = current_buddy;
   if (process_line(inputLine))
     return 255;
   // Add line to history