diff mcabber/src/jabglue.c @ 1395:d431cd75eb53

Use bookmarked nickname when manually joining a room
author Mikael Berthe <mikael@lilotux.net>
date Mon, 10 Dec 2007 21:45:24 +0100
parents 7ca57f7e313c
children 8f9928839a36
line wrap: on
line diff
--- a/mcabber/src/jabglue.c	Sun Dec 09 19:26:37 2007 +0100
+++ b/mcabber/src/jabglue.c	Mon Dec 10 21:45:24 2007 +0100
@@ -1352,7 +1352,7 @@
   jb_reset_keepalive();
 }
 
-//  jb_is_bookmarked()
+//  jb_is_bookmarked(roomjid)
 // Return TRUE if there's a bookmark for the given jid.
 guint jb_is_bookmarked(const char *bjid)
 {
@@ -1377,6 +1377,32 @@
   return FALSE;
 }
 
+//  jb_get_bookmark_nick(roomjid)
+// Return the room nickname if it is present in a bookmark.
+const char *jb_get_bookmark_nick(const char *bjid)
+{
+  xmlnode x;
+
+  if (!bookmarks || !bjid)
+    return NULL;
+
+  // Walk through the storage bookmark tags
+  x = xmlnode_get_firstchild(bookmarks);
+  for ( ; x; x = xmlnode_get_nextsibling(x)) {
+    const char *fjid;
+    const char *p;
+    p = xmlnode_get_name(x);
+    // If the node is a conference item, check the jid.
+    if (p && !strcmp(p, "conference")) {
+      fjid = xmlnode_get_attrib(x, "jid");
+      if (fjid && !strcasecmp(bjid, fjid))
+        return xmlnode_get_tag_data(x, "nick");
+    }
+  }
+  return NULL;
+}
+
+
 //  jb_get_all_storage_bookmarks()
 // Return a GSList with all storage bookmarks.
 // The caller should g_free the list (not the MUC jids).
@@ -2790,7 +2816,7 @@
   // evcontext: 0, 1 == reject, accept
 
   if (evcontext & ~EVS_CONTEXT_USER) {
-    char *nickname = default_muc_nickname();
+    char *nickname = default_muc_nickname(invitation->to);
     jb_room_join(invitation->to, nickname, invitation->passwd);
     g_free(nickname);
   } else {