1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-11-03 19:37:16 -05:00

Create room list on muc_init

This commit is contained in:
James Booth 2014-09-26 00:43:00 +01:00
parent 70169f8ab9
commit ccbaa67a01

125
src/muc.c
View File

@ -69,17 +69,16 @@ void
muc_init(void)
{
invite_ac = autocomplete_new();
rooms = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, (GDestroyNotify)_free_room);
}
void
muc_close(void)
{
autocomplete_free(invite_ac);
if (rooms) {
g_hash_table_destroy(rooms);
rooms = NULL;
}
}
void
muc_add_invite(char *room)
@ -145,11 +144,6 @@ void
muc_join_room(const char * const room, const char * const nick,
const char * const password, gboolean autojoin)
{
if (!rooms) {
rooms = g_hash_table_new_full(g_str_hash, g_str_equal, g_free,
(GDestroyNotify)_free_room);
}
ChatRoom *new_room = malloc(sizeof(ChatRoom));
new_room->room = strdup(room);
new_room->nick = strdup(nick);
@ -177,41 +171,28 @@ muc_join_room(const char * const room, const char * const nick,
void
muc_leave_room(const char * const room)
{
if (rooms) {
g_hash_table_remove(rooms, room);
}
}
gboolean
muc_requires_config(const char * const room)
{
if (!rooms) {
return FALSE;
}
ChatRoom *chat_room = g_hash_table_lookup(rooms, room);
if (!chat_room) {
if (chat_room) {
return chat_room->pending_config;
} else {
return FALSE;
}
return chat_room->pending_config;
}
void
muc_set_requires_config(const char * const room, gboolean val)
{
if (!rooms) {
return;
}
ChatRoom *chat_room = g_hash_table_lookup(rooms, room);
if (!chat_room) {
return;
}
if (chat_room) {
chat_room->pending_config = val;
return;
}
}
/*
@ -220,87 +201,72 @@ muc_set_requires_config(const char * const room, gboolean val)
gboolean
muc_room_is_active(const char * const room)
{
if (rooms) {
ChatRoom *chat_room = g_hash_table_lookup(rooms, room);
return (chat_room != NULL);
} else {
return FALSE;
}
}
gboolean
muc_room_is_autojoin(const char * const room)
{
if (rooms) {
ChatRoom *chat_room = g_hash_table_lookup(rooms, room);
if (chat_room) {
return chat_room->autojoin;
}
}
} else {
return FALSE;
}
}
void
muc_set_subject(const char * const room, const char * const subject)
{
if (rooms) {
ChatRoom *chat_room = g_hash_table_lookup(rooms, room);
if (chat_room) {
free(chat_room->subject);
chat_room->subject = strdup(subject);
}
}
}
char *
muc_get_subject(const char * const room)
{
if (rooms) {
ChatRoom *chat_room = g_hash_table_lookup(rooms, room);
if (chat_room) {
return chat_room->subject;
}
}
} else {
return NULL;
}
}
void
muc_add_pending_broadcast(const char * const room, const char * const message)
{
if (rooms) {
ChatRoom *chat_room = g_hash_table_lookup(rooms, room);
if (chat_room) {
chat_room->pending_broadcasts = g_list_append(chat_room->pending_broadcasts, strdup(message));
}
}
}
GList *
muc_get_pending_broadcasts(const char * const room)
{
if (rooms) {
ChatRoom *chat_room = g_hash_table_lookup(rooms, room);
if (chat_room) {
return chat_room->pending_broadcasts;
}
}
} else {
return NULL;
}
}
char *
muc_get_old_nick(const char * const room, const char * const new_nick)
{
ChatRoom *chat_room = g_hash_table_lookup(rooms, room);
if (chat_room && chat_room->pending_nick_change) {
return g_hash_table_lookup(chat_room->nick_changes, new_nick);
}
} else {
return NULL;
}
}
/*
* Flag that the user has sent a nick change to the service
@ -310,7 +276,6 @@ void
muc_set_room_pending_nick_change(const char * const room, const char * const new_nick)
{
ChatRoom *chat_room = g_hash_table_lookup(rooms, room);
if (chat_room) {
chat_room->pending_nick_change = TRUE;
g_hash_table_insert(chat_room->nick_changes, strdup(new_nick), strdup(chat_room->nick));
@ -325,7 +290,6 @@ gboolean
muc_is_room_pending_nick_change(const char * const room)
{
ChatRoom *chat_room = g_hash_table_lookup(rooms, room);
if (chat_room) {
return chat_room->pending_nick_change;
} else {
@ -341,7 +305,6 @@ void
muc_complete_room_nick_change(const char * const room, const char * const nick)
{
ChatRoom *chat_room = g_hash_table_lookup(rooms, room);
if (chat_room) {
free(chat_room->nick);
chat_room->nick = strdup(nick);
@ -358,11 +321,7 @@ muc_complete_room_nick_change(const char * const room, const char * const nick)
GList *
muc_get_active_room_list(void)
{
if (rooms) {
return g_hash_table_get_keys(rooms);
} else {
return NULL;
}
}
/*
@ -372,15 +331,13 @@ muc_get_active_room_list(void)
char *
muc_get_room_nick(const char * const room)
{
if (rooms) {
ChatRoom *chat_room = g_hash_table_lookup(rooms, room);
if (chat_room) {
return chat_room->nick;
}
}
} else {
return NULL;
}
}
/*
* Return password for the specified room
@ -389,15 +346,13 @@ muc_get_room_nick(const char * const room)
char *
muc_get_room_password(const char * const room)
{
if (rooms) {
ChatRoom *chat_room = g_hash_table_lookup(rooms, room);
if (chat_room) {
return chat_room->password;
}
}
} else {
return NULL;
}
}
/*
* Returns TRUE if the specified nick exists in the room's roster
@ -406,14 +361,13 @@ gboolean
muc_nick_in_roster(const char * const room, const char * const nick)
{
ChatRoom *chat_room = g_hash_table_lookup(rooms, room);
if (chat_room) {
PContact contact = g_hash_table_lookup(chat_room->roster, nick);
return (contact != NULL);
}
} else {
return FALSE;
}
}
/*
* Add a new chat room member to the room's roster
@ -453,7 +407,6 @@ void
muc_remove_from_roster(const char * const room, const char * const nick)
{
ChatRoom *chat_room = g_hash_table_lookup(rooms, room);
if (chat_room) {
g_hash_table_remove(chat_room->roster, nick);
autocomplete_remove(chat_room->nick_ac, nick);
@ -464,14 +417,13 @@ PContact
muc_get_participant(const char * const room, const char * const nick)
{
ChatRoom *chat_room = g_hash_table_lookup(rooms, room);
if (chat_room) {
PContact participant = g_hash_table_lookup(chat_room->roster, nick);
return participant;
}
} else {
return NULL;
}
}
/*
* Return a list of PContacts representing the room members in the room's roster
@ -481,7 +433,6 @@ GList *
muc_get_roster(const char * const room)
{
ChatRoom *chat_room = g_hash_table_lookup(rooms, room);
if (chat_room) {
GList *result = NULL;
GHashTableIter iter;
@ -506,7 +457,6 @@ Autocomplete
muc_get_roster_ac(const char * const room)
{
ChatRoom *chat_room = g_hash_table_lookup(rooms, room);
if (chat_room) {
return chat_room->nick_ac;
} else {
@ -521,7 +471,6 @@ void
muc_set_roster_received(const char * const room)
{
ChatRoom *chat_room = g_hash_table_lookup(rooms, room);
if (chat_room) {
chat_room->roster_received = TRUE;
}
@ -534,7 +483,6 @@ gboolean
muc_get_roster_received(const char * const room)
{
ChatRoom *chat_room = g_hash_table_lookup(rooms, room);
if (chat_room) {
return chat_room->roster_received;
} else {
@ -551,7 +499,6 @@ muc_set_roster_pending_nick_change(const char * const room,
const char * const new_nick, const char * const old_nick)
{
ChatRoom *chat_room = g_hash_table_lookup(rooms, room);
if (chat_room) {
g_hash_table_insert(chat_room->nick_changes, strdup(new_nick), strdup(old_nick));
muc_remove_from_roster(room, old_nick);
@ -569,7 +516,6 @@ muc_complete_roster_nick_change(const char * const room,
const char * const nick)
{
ChatRoom *chat_room = g_hash_table_lookup(rooms, room);
if (chat_room) {
char *old_nick = g_hash_table_lookup(chat_room->nick_changes, nick);
if (old_nick) {
@ -586,21 +532,10 @@ muc_complete_roster_nick_change(const char * const room,
void
muc_autocomplete(char *input, int *size)
{
if (!rooms) {
return;
}
char *recipient = ui_current_recipient();
ChatRoom *chat_room = g_hash_table_lookup(rooms, recipient);
if (!chat_room) {
return;
}
if (!chat_room->nick_ac) {
return;
}
if (chat_room && chat_room->nick_ac) {
input[*size] = '\0';
char *search_str = NULL;
@ -628,23 +563,14 @@ muc_autocomplete(char *input, int *size)
g_string_free(replace_with, TRUE);
g_free(result);
}
return;
}
}
void
muc_reset_autocomplete(const char * const room)
{
if (!rooms) {
return;
}
ChatRoom *chat_room = g_hash_table_lookup(rooms, room);
if (!chat_room) {
return;
}
if (chat_room) {
if (chat_room->nick_ac) {
autocomplete_reset(chat_room->nick_ac);
}
@ -654,6 +580,7 @@ muc_reset_autocomplete(const char * const room)
chat_room->autocomplete_prefix = NULL;
}
}
}
static void
_free_room(ChatRoom *room)