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