Index: irc.h
===================================================================
--- irc.h	(revision 5014380af58a2fa51b3ef5afa49d7751eaf6cea1)
+++ irc.h	(revision b8c336b12e7645075a8e642382911d26b9b8e50f)
@@ -147,4 +147,7 @@
 	IRC_CHANNEL_TEMP = 2,   /* Erase the channel when the user leaves,
 	                           and don't save it. */
+
+	/* Show a placeholder of the channel in listings, but don't save it */
+	IRC_CHANNEL_KEEP_PLACEHOLDER = 4,
 
 	/* Hack: Set this flag right before jumping into IM when we expect
Index: irc_channel.c
===================================================================
--- irc_channel.c	(revision 5014380af58a2fa51b3ef5afa49d7751eaf6cea1)
+++ irc_channel.c	(revision b8c336b12e7645075a8e642382911d26b9b8e50f)
@@ -276,5 +276,5 @@
 		if (ic->irc->status & USTATUS_SHUTDOWN) {
 			/* Don't do anything fancy when we're shutting down anyway. */
-		} else if (ic->flags & IRC_CHANNEL_TEMP) {
+		} else if (ic->flags & IRC_CHANNEL_TEMP && !(ic->flags & IRC_CHANNEL_KEEP_PLACEHOLDER)) {
 			irc_channel_free_soon(ic);
 		} else {
Index: irc_im.c
===================================================================
--- irc_im.c	(revision 5014380af58a2fa51b3ef5afa49d7751eaf6cea1)
+++ irc_im.c	(revision b8c336b12e7645075a8e642382911d26b9b8e50f)
@@ -576,9 +576,17 @@
 	ic->data = c;
 
-	topic = g_strdup_printf(
-	        "BitlBee groupchat: \"%s\". Please keep in mind that root-commands won't work here. Have fun!",
-	        c->title);
-	irc_channel_set_topic(ic, topic, irc->root);
-	g_free(topic);
+	if (ic->topic == NULL) {
+		/* New channel with no preset topic - make up a generic one */
+		topic = g_strdup_printf(
+		        "BitlBee groupchat: \"%s\". Please keep in mind that root-commands won't work here. Have fun!",
+		        c->title);
+		irc_channel_set_topic(ic, topic, irc->root);
+	} else {
+		/* Preset topic from the channel we picked */
+		topic = g_strdup(ic->topic);
+	}
+
+	g_free(c->topic);
+	c->topic = topic;         /* Let groupchat borrow this pointer */
 
 	return TRUE;
@@ -600,4 +608,25 @@
 	c->ui_data = NULL;
 	irc_channel_del_user(ic, ic->irc->user, IRC_CDU_KICK, "Chatroom closed by server");
+
+	return TRUE;
+}
+
+static gboolean bee_irc_chat_placeholder_new(bee_t *bee, struct im_connection *ic, const char *handle,
+                                             const char *name, const char *topic)
+{
+	irc_t *irc = bee->ui_data;
+	irc_channel_t *ircc;
+	char *full_name = irc_channel_name_gen(irc, name);
+
+	ircc = irc_channel_new(irc, full_name);
+
+	set_setstr(&ircc->set, "type", "chat");
+	set_setstr(&ircc->set, "chat_type", "placeholder");
+	set_setstr(&ircc->set, "account", ic->acc->tag);
+	set_setstr(&ircc->set, "room", (char *) handle);
+
+	irc_channel_set_topic(ircc, topic, NULL);
+
+	g_free(full_name);
 
 	return TRUE;
@@ -826,8 +855,10 @@
 static gboolean bee_irc_channel_chat_join(irc_channel_t *ic)
 {
-	char *acc_s, *room;
+	char *acc_s, *room, *chat_type;
 	account_t *acc;
 
-	if (strcmp(set_getstr(&ic->set, "chat_type"), "room") != 0) {
+	chat_type = set_getstr(&ic->set, "chat_type");
+
+	if (strcmp(chat_type, "room") != 0 && strcmp(chat_type, "placeholder") != 0) {
 		return TRUE;
 	}
@@ -985,8 +1016,12 @@
 	struct irc_channel *ic = set->data;
 
+	ic->flags &= ~(IRC_CHANNEL_TEMP | IRC_CHANNEL_KEEP_PLACEHOLDER);
+
 	if (strcmp(value, "groupchat") == 0) {
 		ic->flags |= IRC_CHANNEL_TEMP;
 	} else if (strcmp(value, "room") == 0) {
-		ic->flags &= ~IRC_CHANNEL_TEMP;
+		// beep boop
+	} else if (strcmp(value, "placeholder") == 0) {
+		ic->flags |= IRC_CHANNEL_TEMP | IRC_CHANNEL_KEEP_PLACEHOLDER;
 	} else {
 		return NULL;
@@ -1072,4 +1107,5 @@
 	bee_irc_chat_new,
 	bee_irc_chat_free,
+	bee_irc_chat_placeholder_new,
 	bee_irc_chat_log,
 	bee_irc_chat_msg,
Index: protocols/bee.h
===================================================================
--- protocols/bee.h	(revision 5014380af58a2fa51b3ef5afa49d7751eaf6cea1)
+++ protocols/bee.h	(revision b8c336b12e7645075a8e642382911d26b9b8e50f)
@@ -115,4 +115,6 @@
 	gboolean (*chat_new)(bee_t *bee, struct groupchat *c);
 	gboolean (*chat_free)(bee_t *bee, struct groupchat *c);
+	gboolean (*chat_placeholder_new)(bee_t *bee, struct im_connection *ic, const char *handle,
+	                                 const char *name, const char *topic);
 	/* System messages of any kind. */
 	gboolean (*chat_log)(bee_t *bee, struct groupchat *c, const char *text);
@@ -165,4 +167,6 @@
  *   user, too. */
 G_MODULE_EXPORT struct groupchat *imcb_chat_new(struct im_connection *ic, const char *handle);
+G_MODULE_EXPORT void imcb_chat_placeholder_new(struct im_connection *ic, const char *handle, const char *name,
+                                               const char *topic);
 G_MODULE_EXPORT void imcb_chat_name_hint(struct groupchat *c, const char *name);
 G_MODULE_EXPORT void imcb_chat_free(struct groupchat *c);
Index: protocols/bee_chat.c
===================================================================
--- protocols/bee_chat.c	(revision 5014380af58a2fa51b3ef5afa49d7751eaf6cea1)
+++ protocols/bee_chat.c	(revision b8c336b12e7645075a8e642382911d26b9b8e50f)
@@ -54,4 +54,13 @@
 }
 
+void imcb_chat_placeholder_new(struct im_connection *ic, const char *handle, const char *name, const char *topic)
+{
+	bee_t *bee = ic->bee;
+
+	if (bee->ui->chat_placeholder_new) {
+		bee->ui->chat_placeholder_new(bee, ic, handle, name, topic);
+	}
+}
+
 void imcb_chat_name_hint(struct groupchat *c, const char *name)
 {
Index: protocols/jabber/conference.c
===================================================================
--- protocols/jabber/conference.c	(revision 5014380af58a2fa51b3ef5afa49d7751eaf6cea1)
+++ protocols/jabber/conference.c	(revision b8c336b12e7645075a8e642382911d26b9b8e50f)
@@ -354,77 +354,87 @@
 	struct xt_node *subject = xt_find_node(node->children, "subject");
 	struct xt_node *body = xt_find_node(node->children, "body");
-	struct groupchat *chat = bud ? jabber_chat_by_jid(ic, bud->bare_jid) : NULL;
-	struct jabber_chat *jc = chat ? chat->data : NULL;
-	char *s;
+	struct groupchat *chat = NULL;
+	struct jabber_chat *jc = NULL;
+	char *from = NULL;
+	char *nick = NULL;
+	char *final_from = NULL;
+	char *bare_jid = NULL;
+
+	from = (bud) ? bud->full_jid : xt_find_attr(node, "from");
+
+	if (from) {
+		nick = strchr(from, '/');
+		if (nick) {
+			*nick = 0;
+		}
+		chat = jabber_chat_by_jid(ic, from);
+		if (nick) {
+			*nick = '/';
+			nick++;
+		}
+	}
+
+	jc = (chat) ? chat->data : NULL;
+
+	if (!bud) {
+		struct xt_node *c;
+		char *s;
+
+		/* Try some clever stuff to find out the real JID here */
+		c = xt_find_node_by_attr(node->children, "delay", "xmlns", XMLNS_DELAY);
+
+		if (c && ((s = xt_find_attr(c, "from")) ||
+		          (s = xt_find_attr(c, "from_jid")))) {
+			/* This won't be useful if it's the MUC JID */
+			if (!(jc && jabber_compare_jid(s, jc->name))) {
+				/* Hopefully this one makes more sense! */
+				bud = jabber_buddy_by_jid(ic, s, GET_BUDDY_FIRST | GET_BUDDY_CREAT);
+			}
+		}
+
+	}
 
 	if (subject && chat) {
-		s = (bud && bud->ext_jid) ? strchr(bud->ext_jid, '/') : NULL;
-		if (s) {
-			*s = 0;
-		}
-		imcb_chat_topic(chat, bud ? bud->ext_jid : NULL, subject->text_len > 0 ?
-		                subject->text : NULL, jabber_get_timestamp(node));
-		if (s) {
-			*s = '/';
-		}
-	}
-
-	if (bud == NULL || (jc && ~jc->flags & JCFLAG_MESSAGE_SENT && bud == jc->me)) {
-		char *nick;
-
-		if (body == NULL || body->text_len == 0) {
-			/* Meh. Empty messages aren't very interesting, no matter
-			   how much some servers love to send them. */
-			return;
-		}
-
-		s = xt_find_attr(node, "from");   /* pkt_message() already NULL-checked this one. */
-		nick = strchr(s, '/');
-		if (nick) {
-			/* If this message included a resource/nick we don't know,
-			   we might still know the groupchat itself. */
-			*nick = 0;
-			chat = jabber_chat_by_jid(ic, s);
-			*nick = '/';
-
-			nick++;
+		char *subject_text = subject->text_len > 0 ? subject->text : NULL;
+		if (g_strcmp0(chat->topic, subject_text) != 0) {
+			bare_jid = (bud) ? jabber_get_bare_jid(bud->ext_jid) : NULL;
+			imcb_chat_topic(chat, bare_jid, subject_text,
+			                jabber_get_timestamp(node));
+			g_free(bare_jid);
+		}
+	}
+
+	if (body == NULL || body->text_len == 0) {
+		/* Meh. Empty messages aren't very interesting, no matter
+		   how much some servers love to send them. */
+		return;
+	}
+
+	if (chat == NULL) {
+		if (nick == NULL) {
+			imcb_log(ic, "System message from unknown groupchat %s: %s", from, body->text);
 		} else {
-			/* message.c uses the EXACT_JID option, so bud should
-			   always be NULL here for bare JIDs. */
-			chat = jabber_chat_by_jid(ic, s);
-		}
-
-		if (nick == NULL) {
-			/* This is fine, the groupchat itself isn't in jd->buddies. */
-			if (chat) {
-				imcb_chat_log(chat, "From conference server: %s", body->text);
-			} else {
-				imcb_log(ic, "System message from unknown groupchat %s: %s", s, body->text);
-			}
-		} else {
-			/* This can happen too, at least when receiving a backlog when
-			   just joining a channel. */
-			if (chat) {
-				imcb_chat_log(chat, "Message from unknown participant %s: %s", nick, body->text);
-			} else {
-				imcb_log(ic, "Groupchat message from unknown JID %s: %s", s, body->text);
-			}
+			imcb_log(ic, "Groupchat message from unknown JID %s: %s", from, body->text);
 		}
 
 		return;
-	} else if (chat == NULL) {
-		/* How could this happen?? We could do kill( self, 11 )
-		   now or just wait for the OS to do it. :-) */
+	} else if (chat != NULL && bud == NULL && nick == NULL) {
+		imcb_chat_log(chat, "From conference server: %s", body->text);
 		return;
-	}
-	if (body && body->text_len > 0) {
-		s = (bud->ext_jid) ? strchr(bud->ext_jid, '/') : NULL;
-		if (s) {
-			*s = 0;
-		}
-		imcb_chat_msg(chat, bud->ext_jid, body->text, 0, jabber_get_timestamp(node));
-		if (s) {
-			*s = '/';
-		}
-	}
-}
+	} else if (jc && jc->flags & JCFLAG_MESSAGE_SENT && bud == jc->me) {
+		/* exclude self-messages since they would get filtered out
+		 * but not the ones in the backlog */
+		return;
+	}
+
+	if (bud && jc && bud != jc->me) {
+		bare_jid = jabber_get_bare_jid(bud->ext_jid ? bud->ext_jid : bud->full_jid);
+		final_from = bare_jid;
+	} else {
+		final_from = nick;
+	}
+
+	imcb_chat_msg(chat, final_from, body->text, 0, jabber_get_timestamp(node));
+
+	g_free(bare_jid);
+}
Index: protocols/jabber/hipchat.c
===================================================================
--- protocols/jabber/hipchat.c	(revision 5014380af58a2fa51b3ef5afa49d7751eaf6cea1)
+++ protocols/jabber/hipchat.c	(revision b8c336b12e7645075a8e642382911d26b9b8e50f)
@@ -27,7 +27,8 @@
 {
 	struct jabber_data *jd = ic->proto_data;
-	char *sep, *jid;
+	char *sep, *jid, *muc_host;
 
 	jid = xt_find_attr(node, "jid");
+	muc_host = xt_find_attr(node, "muc_host");
 
 	sep = strchr(jid, '/');
@@ -48,5 +49,6 @@
 	if (!jabber_get_roster(ic) ||
 	    !jabber_iq_disco_server(ic) ||
-	    !jabber_get_hipchat_profile(ic)) {
+	    !jabber_get_hipchat_profile(ic) ||
+            !jabber_iq_disco_muc(ic, muc_host)) {
 		return XT_ABORT;
 	}
@@ -92,2 +94,49 @@
 
 }
+
+int jabber_iq_disco_muc(struct im_connection *ic, char *muc_server)
+{
+	struct xt_node *node;
+	int st;
+
+	imcb_log(ic, "Fetching MUC list");
+
+	node = xt_new_node("query", NULL, NULL);
+	xt_add_attr(node, "xmlns", XMLNS_DISCO_ITEMS);
+	node = jabber_make_packet("iq", "get", muc_server, node);
+
+	jabber_cache_add(ic, node, jabber_parse_muc_list);
+	st = jabber_write_packet(ic, node);
+
+	return st;
+}
+
+xt_status jabber_parse_muc_list(struct im_connection *ic, struct xt_node *node, struct xt_node *orig)
+{
+	struct xt_node *query, *c;
+
+	if (!(query = xt_find_node(node->children, "query"))) {
+		imcb_log(ic, "Warning: Received NULL MUC list packet");
+		return XT_HANDLED;
+	}
+
+	c = query->children;
+	while ((c = xt_find_node(c, "item"))) {
+		struct xt_node *c2;
+		char *topic = NULL;
+		char *jid = xt_find_attr(c, "jid");
+		char *name = xt_find_attr(c, "name");
+
+		imcb_log(ic, "Debug: adding MUC to channel list: %s - '%s'", jid, name);
+
+		if ((c2 = xt_find_node_by_attr(c->children, "x", "xmlns", XMLNS_HIPCHAT_MUC)) &&
+		    (c2 = xt_find_node(c2->children, "topic"))) {
+			topic = c2->text;
+		}
+
+		imcb_chat_placeholder_new(ic, jid, name, topic);
+		c = c->next;
+	}
+	return XT_HANDLED;
+
+}
Index: protocols/jabber/jabber.h
===================================================================
--- protocols/jabber/jabber.h	(revision 5014380af58a2fa51b3ef5afa49d7751eaf6cea1)
+++ protocols/jabber/jabber.h	(revision b8c336b12e7645075a8e642382911d26b9b8e50f)
@@ -239,4 +239,5 @@
 #define XMLNS_HIPCHAT         "http://hipchat.com"
 #define XMLNS_HIPCHAT_PROFILE "http://hipchat.com/protocol/profile"
+#define XMLNS_HIPCHAT_MUC     "http://hipchat.com/protocol/muc#room"
 
 /* jabber.c */
@@ -249,4 +250,5 @@
 int jabber_get_roster(struct im_connection *ic);
 int jabber_get_vcard(struct im_connection *ic, char *bare_jid);
+int jabber_iq_disco_muc(struct im_connection *ic, char *muc_server);
 int jabber_add_to_roster(struct im_connection *ic, const char *handle, const char *name, const char *group);
 int jabber_remove_from_roster(struct im_connection *ic, char *handle);
@@ -312,4 +314,5 @@
 void jabber_error_free(struct jabber_error *err);
 gboolean jabber_set_me(struct im_connection *ic, const char *me);
+char *jabber_get_bare_jid(char *jid);
 
 extern const struct jabber_away_state jabber_away_state_list[];
@@ -351,4 +354,5 @@
 xt_status jabber_parse_hipchat_profile(struct im_connection *ic, struct xt_node *node, struct xt_node *orig);
 xt_status hipchat_handle_success(struct im_connection *ic, struct xt_node *node);
+xt_status jabber_parse_muc_list(struct im_connection *ic, struct xt_node *node, struct xt_node *orig);
 
 #endif
Index: protocols/jabber/jabber_util.c
===================================================================
--- protocols/jabber/jabber_util.c	(revision 5014380af58a2fa51b3ef5afa49d7751eaf6cea1)
+++ protocols/jabber/jabber_util.c	(revision b8c336b12e7645075a8e642382911d26b9b8e50f)
@@ -820,2 +820,18 @@
 	return TRUE;
 }
+
+/* Returns new reference! g_free() afterwards. */
+char *jabber_get_bare_jid(char *jid)
+{
+	char *s = NULL;
+
+	if (jid == NULL) {
+		return NULL;
+	}
+
+	if ((s = strchr(jid, '/'))) {
+		return g_strndup(jid, s - jid);
+	} else {
+		return g_strdup(jid);
+	}
+}
