about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2014-04-23 22:19:14 +0100
committerJames Booth <boothj5@gmail.com>2014-04-23 22:19:14 +0100
commitc7b3ff02ff00c8266710a11dc5728f769d643570 (patch)
treeddede67e28d562335e6cfb84cb34deea819a84ff
parent4384a1f4688968bcf621ddcaae58438374cad29d (diff)
downloadprofani-tty-c7b3ff02ff00c8266710a11dc5728f769d643570.tar.gz
Rejoin private rooms after reconnecting
-rw-r--r--src/muc.c20
-rw-r--r--src/muc.h3
-rw-r--r--src/server_events.c12
3 files changed, 34 insertions, 1 deletions
diff --git a/src/muc.c b/src/muc.c
index 4ba88191..88b5e2cd 100644
--- a/src/muc.c
+++ b/src/muc.c
@@ -298,6 +298,26 @@ muc_get_room_nick(const char * const room)
 }
 
 /*
+ * Return password for the specified room
+ * The password is owned by the chat room and should not be modified or freed
+ */
+char *
+muc_get_room_password(const char * const room)
+{
+    if (rooms != NULL) {
+        ChatRoom *chat_room = g_hash_table_lookup(rooms, room);
+
+        if (chat_room != NULL) {
+            return chat_room->password;
+        } else {
+            return NULL;
+        }
+    } else {
+        return NULL;
+    }
+}
+
+/*
  * Returns TRUE if the specified nick exists in the room's roster
  */
 gboolean
diff --git a/src/muc.h b/src/muc.h
index 34058bfe..2dc4aa85 100644
--- a/src/muc.h
+++ b/src/muc.h
@@ -37,7 +37,8 @@ void muc_leave_room(const char * const room);
 gboolean muc_room_is_active(const char * const room);
 gboolean muc_room_is_autojoin(const char * const room);
 GList* muc_get_active_room_list(void);
-char * muc_get_room_nick(const char * const room);
+char* muc_get_room_nick(const char * const room);
+char* muc_get_room_password(const char * const room);
 
 void muc_set_room_pending_nick_change(const char * const room, const char * const new_nick);
 gboolean muc_is_room_pending_nick_change(const char * const room);
diff --git a/src/server_events.c b/src/server_events.c
index faedac83..d18f1beb 100644
--- a/src/server_events.c
+++ b/src/server_events.c
@@ -94,6 +94,18 @@ handle_login_account_success(char *account_name)
 
     ui_handle_login_account_success(account);
 
+    // attempt to rejoin rooms with passwords
+    GList *curr = muc_get_active_room_list();
+    while (curr != NULL) {
+        char *password = muc_get_room_password(curr->data);
+        if (password != NULL) {
+            char *nick = muc_get_room_nick(curr->data);
+            presence_join_room(curr->data, nick, password);
+        }
+        curr = g_list_next(curr);
+    }
+    g_list_free(curr);
+
     log_info("%s logged in successfully", account->jid);
     account_free(account);
 }