Index: protocols/twitter/twitter.c
===================================================================
--- protocols/twitter/twitter.c	(revision 90ba4161e5c24306233bc4627d1cde39a54006cf)
+++ protocols/twitter/twitter.c	(revision d6aa6dd53c3352305508ffbf62d26f59dd19b777)
@@ -40,9 +40,4 @@
 		return 0;
 
-	// If the user uses multiple private message windows we need to get the 
-	// users buddies.
-	if (g_strcasecmp(set_getstr(&ic->acc->set, "mode"), "many") == 0)
-		twitter_get_statuses_friends(ic, -1);
-
 	// Do stuff..
 	twitter_get_home_timeline(ic, -1);
@@ -56,5 +51,5 @@
 	struct twitter_data *td = ic->proto_data;
 	
-	imcb_log( ic, "Connecting to Twitter" );
+	imcb_log( ic, "Getting initial statuses" );
 
 	// Run this once. After this queue the main loop function.
@@ -66,4 +61,21 @@
 }
 
+static void twitter_oauth_start( struct im_connection *ic );
+
+void twitter_login_finish( struct im_connection *ic )
+{
+	struct twitter_data *td = ic->proto_data;
+	
+	if( set_getbool( &ic->acc->set, "oauth" ) && !td->oauth_info )
+		twitter_oauth_start( ic );
+	else if( g_strcasecmp( set_getstr( &ic->acc->set, "mode" ), "one" ) != 0 &&
+	         !( td->flags & TWITTER_HAVE_FRIENDS ) )
+	{
+		imcb_log( ic, "Getting contact list" );
+		twitter_get_statuses_friends( ic, -1 );
+	}
+	else
+		twitter_main_loop_start( ic );
+}
 
 static const struct oauth_service twitter_oauth =
@@ -128,5 +140,5 @@
 		ic->acc->pass = oauth_to_string( info );
 		
-		twitter_main_loop_start( ic );
+		twitter_login_finish( ic );
 	}
 	
@@ -211,8 +223,7 @@
 	imcb_buddy_status( ic, name, OPT_LOGGED_IN, NULL, NULL );
 	
-	if( td->oauth_info || !set_getbool( &acc->set, "oauth" ) )
-		twitter_main_loop_start( ic );
-	else
-		twitter_oauth_start( ic );
+	imcb_log( ic, "Connecting" );
+	
+	twitter_login_finish( ic );
 }
 
Index: protocols/twitter/twitter.h
===================================================================
--- protocols/twitter/twitter.h	(revision 90ba4161e5c24306233bc4627d1cde39a54006cf)
+++ protocols/twitter/twitter.h	(revision d6aa6dd53c3352305508ffbf62d26f59dd19b777)
@@ -33,4 +33,9 @@
 #endif
 
+typedef enum
+{
+	TWITTER_HAVE_FRIENDS = 1,
+} twitter_flags_t;
+
 struct twitter_data
 {
@@ -42,4 +47,5 @@
 	struct groupchat *home_timeline_gc;
 	gint http_fails;
+	twitter_flags_t flags;
 	
 	gboolean url_ssl;
@@ -56,3 +62,5 @@
 GSList *twitter_connections;
 
+void twitter_login_finish( struct im_connection *ic );
+
 #endif //_TWITTER_H
Index: protocols/twitter/twitter_lib.c
===================================================================
--- protocols/twitter/twitter_lib.c	(revision 90ba4161e5c24306233bc4627d1cde39a54006cf)
+++ protocols/twitter/twitter_lib.c	(revision d6aa6dd53c3352305508ffbf62d26f59dd19b777)
@@ -59,4 +59,6 @@
 };
 
+static void twitter_groupchat_init(struct im_connection *ic);
+
 /**
  * Frees a twitter_xml_user struct.
@@ -433,4 +435,17 @@
 }
 
+static void twitter_groupchat_init(struct im_connection *ic)
+{
+	char *name_hint;
+	struct groupchat *gc;
+	struct twitter_data *td = ic->proto_data;
+	
+	td->home_timeline_gc = gc = imcb_chat_new( ic, "home/timeline" );
+	
+	name_hint = g_strdup_printf( "Twitter_%s", ic->acc->user );
+	imcb_chat_name_hint( gc, name_hint );
+	g_free( name_hint );
+}
+
 /**
  * Function that is called to see the statuses in a groupchat window.
@@ -445,16 +460,9 @@
 	// Create a new groupchat if it does not exsist.
 	if (!td->home_timeline_gc)
-	{   
-		char *name_hint = g_strdup_printf( "Twitter_%s", ic->acc->user );
-		td->home_timeline_gc = gc = imcb_chat_new( ic, "home/timeline" );
-		imcb_chat_name_hint( gc, name_hint );
-		g_free( name_hint );
-		// Add the current user to the chat...
+		twitter_groupchat_init(ic);
+	
+	gc = td->home_timeline_gc;
+	if (!gc->joined)
 		imcb_chat_add_buddy( gc, ic->acc->user );
-	}
-	else
-	{   
-		gc = td->home_timeline_gc;
-	}
 
 	for ( l = list; l ; l = g_slist_next(l) )
@@ -604,13 +612,21 @@
 	
 	// Check if the HTTP request went well.
-	if (req->status_code != 200) {
+	if (req->status_code == 401)
+	{
+		imcb_error( ic, "Authentication failure" );
+		imc_logout( ic, FALSE );
+		return;
+	} else if (req->status_code != 200) {
 		// It didn't go well, output the error and return.
-		if (++td->http_fails >= 5)
-			imcb_error(ic, "Could not retrieve " TWITTER_SHOW_FRIENDS_URL ": %s", twitter_parse_error(req));
-		
+		imcb_error(ic, "Could not retrieve " TWITTER_SHOW_FRIENDS_URL ": %s", twitter_parse_error(req));
+		imc_logout( ic, TRUE );
 		return;
 	} else {
 		td->http_fails = 0;
 	}
+	
+	if( !td->home_timeline_gc &&
+	    g_strcasecmp( set_getstr( &ic->acc->set, "mode" ), "chat" ) == 0 )
+		twitter_groupchat_init( ic );
 
 	txl = g_new0(struct twitter_xml_list, 1);
@@ -639,4 +655,7 @@
 	txl_free(txl);
 	g_free(txl);
+	
+	td->flags |= TWITTER_HAVE_FRIENDS;
+	twitter_login_finish(ic);
 }
 
