mirror of
https://github.com/profanity-im/profanity.git
synced 2025-02-02 15:08:15 -05:00
Tidy room_chat
This commit is contained in:
parent
ca9d390fcf
commit
522102d4ea
@ -39,7 +39,7 @@ GHashTable *rooms = NULL;
|
|||||||
static void _room_free(muc_room *room);
|
static void _room_free(muc_room *room);
|
||||||
|
|
||||||
void
|
void
|
||||||
room_join(const char * const jid, const char * const nick)
|
room_join(const char * const room, const char * const nick)
|
||||||
{
|
{
|
||||||
if (rooms == NULL) {
|
if (rooms == NULL) {
|
||||||
rooms = g_hash_table_new_full(g_str_hash, g_str_equal, g_free,
|
rooms = g_hash_table_new_full(g_str_hash, g_str_equal, g_free,
|
||||||
@ -47,31 +47,31 @@ room_join(const char * const jid, const char * const nick)
|
|||||||
}
|
}
|
||||||
|
|
||||||
muc_room *new_room = malloc(sizeof(muc_room));
|
muc_room *new_room = malloc(sizeof(muc_room));
|
||||||
new_room->room = strdup(jid);
|
new_room->room = strdup(room);
|
||||||
new_room->nick = strdup(nick);
|
new_room->nick = strdup(nick);
|
||||||
new_room->roster = g_hash_table_new_full(g_str_hash, g_str_equal, g_free,
|
new_room->roster = g_hash_table_new_full(g_str_hash, g_str_equal, g_free,
|
||||||
(GDestroyNotify)p_contact_free);
|
(GDestroyNotify)p_contact_free);
|
||||||
new_room->roster_received = FALSE;
|
new_room->roster_received = FALSE;
|
||||||
|
|
||||||
g_hash_table_insert(rooms, strdup(jid), new_room);
|
g_hash_table_insert(rooms, strdup(room), new_room);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
room_leave(const char * const jid)
|
room_leave(const char * const room)
|
||||||
{
|
{
|
||||||
g_hash_table_remove(rooms, jid);
|
g_hash_table_remove(rooms, room);
|
||||||
}
|
}
|
||||||
|
|
||||||
gboolean
|
gboolean
|
||||||
room_is_active(const char * const jid)
|
room_is_active(const char * const full_room_jid)
|
||||||
{
|
{
|
||||||
char **tokens = g_strsplit(jid, "/", 0);
|
char **tokens = g_strsplit(full_room_jid, "/", 0);
|
||||||
char *jid_part = tokens[0];
|
char *room_part = tokens[0];
|
||||||
|
|
||||||
if (rooms != NULL) {
|
if (rooms != NULL) {
|
||||||
muc_room *room = g_hash_table_lookup(rooms, jid_part);
|
muc_room *chat_room = g_hash_table_lookup(rooms, room_part);
|
||||||
|
|
||||||
if (room != NULL) {
|
if (chat_room != NULL) {
|
||||||
return TRUE;
|
return TRUE;
|
||||||
} else {
|
} else {
|
||||||
return FALSE;
|
return FALSE;
|
||||||
@ -82,13 +82,13 @@ room_is_active(const char * const jid)
|
|||||||
}
|
}
|
||||||
|
|
||||||
char *
|
char *
|
||||||
room_get_nick_for_room(const char * const jid)
|
room_get_nick_for_room(const char * const room)
|
||||||
{
|
{
|
||||||
if (rooms != NULL) {
|
if (rooms != NULL) {
|
||||||
muc_room *room = g_hash_table_lookup(rooms, jid);
|
muc_room *chat_room = g_hash_table_lookup(rooms, room);
|
||||||
|
|
||||||
if (room != NULL) {
|
if (chat_room != NULL) {
|
||||||
return room->nick;
|
return chat_room->nick;
|
||||||
} else {
|
} else {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@ -98,26 +98,26 @@ room_get_nick_for_room(const char * const jid)
|
|||||||
}
|
}
|
||||||
|
|
||||||
char *
|
char *
|
||||||
room_get_room_for_full_jid(const char * const jid)
|
room_get_room_for_full_jid(const char * const full_room_jid)
|
||||||
{
|
{
|
||||||
char **tokens = g_strsplit(jid, "/", 0);
|
char **tokens = g_strsplit(full_room_jid, "/", 0);
|
||||||
char *room;
|
char *room_part;
|
||||||
|
|
||||||
if (tokens == NULL || tokens[0] == NULL) {
|
if (tokens == NULL || tokens[0] == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
} else {
|
} else {
|
||||||
room = strdup(tokens[0]);
|
room_part = strdup(tokens[0]);
|
||||||
|
|
||||||
g_strfreev(tokens);
|
g_strfreev(tokens);
|
||||||
|
|
||||||
return room;
|
return room_part;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
gboolean
|
gboolean
|
||||||
room_parse_room_jid(const char * const room_jid, char **room, char **nick)
|
room_parse_room_jid(const char * const full_room_jid, char **room, char **nick)
|
||||||
{
|
{
|
||||||
char **tokens = g_strsplit(room_jid, "/", 0);
|
char **tokens = g_strsplit(full_room_jid, "/", 0);
|
||||||
|
|
||||||
if (tokens == NULL || tokens[0] == NULL || tokens[1] == NULL) {
|
if (tokens == NULL || tokens[0] == NULL || tokens[1] == NULL) {
|
||||||
return FALSE;
|
return FALSE;
|
||||||
@ -132,55 +132,55 @@ room_parse_room_jid(const char * const room_jid, char **room, char **nick)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
room_add_to_roster(const char * const jid, const char * const nick)
|
room_add_to_roster(const char * const room, const char * const nick)
|
||||||
{
|
{
|
||||||
muc_room *room = g_hash_table_lookup(rooms, jid);
|
muc_room *chat_room = g_hash_table_lookup(rooms, room);
|
||||||
|
|
||||||
if (room != NULL) {
|
if (chat_room != NULL) {
|
||||||
PContact contact = p_contact_new(nick, NULL, "online", NULL, NULL);
|
PContact contact = p_contact_new(nick, NULL, "online", NULL, NULL);
|
||||||
g_hash_table_replace(room->roster, strdup(nick), contact);
|
g_hash_table_replace(chat_room->roster, strdup(nick), contact);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
room_remove_from_roster(const char * const jid, const char * const nick)
|
room_remove_from_roster(const char * const room, const char * const nick)
|
||||||
{
|
{
|
||||||
muc_room *room = g_hash_table_lookup(rooms, jid);
|
muc_room *chat_room = g_hash_table_lookup(rooms, room);
|
||||||
|
|
||||||
if (room != NULL) {
|
if (chat_room != NULL) {
|
||||||
g_hash_table_remove(room->roster, nick);
|
g_hash_table_remove(chat_room->roster, nick);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
GList *
|
GList *
|
||||||
room_get_roster(const char * const jid)
|
room_get_roster(const char * const room)
|
||||||
{
|
{
|
||||||
muc_room *room = g_hash_table_lookup(rooms, jid);
|
muc_room *chat_room = g_hash_table_lookup(rooms, room);
|
||||||
|
|
||||||
if (room != NULL) {
|
if (chat_room != NULL) {
|
||||||
return g_hash_table_get_keys(room->roster);
|
return g_hash_table_get_keys(chat_room->roster);
|
||||||
} else {
|
} else {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
room_set_roster_received(const char * const jid)
|
room_set_roster_received(const char * const room)
|
||||||
{
|
{
|
||||||
muc_room *room = g_hash_table_lookup(rooms, jid);
|
muc_room *chat_room = g_hash_table_lookup(rooms, room);
|
||||||
|
|
||||||
if (room != NULL) {
|
if (chat_room != NULL) {
|
||||||
room->roster_received = TRUE;
|
chat_room->roster_received = TRUE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
gboolean
|
gboolean
|
||||||
room_get_roster_received(const char * const jid)
|
room_get_roster_received(const char * const room)
|
||||||
{
|
{
|
||||||
muc_room *room = g_hash_table_lookup(rooms, jid);
|
muc_room *chat_room = g_hash_table_lookup(rooms, room);
|
||||||
|
|
||||||
if (room != NULL) {
|
if (chat_room != NULL) {
|
||||||
return room->roster_received;
|
return chat_room->roster_received;
|
||||||
} else {
|
} else {
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
@ -25,17 +25,17 @@
|
|||||||
|
|
||||||
#include <glib.h>
|
#include <glib.h>
|
||||||
|
|
||||||
void room_join(const char * const jid, const char * const nick);
|
void room_join(const char * const room, const char * const nick);
|
||||||
void room_leave(const char * const jid);
|
void room_leave(const char * const room);
|
||||||
gboolean room_is_active(const char * const jid);
|
gboolean room_is_active(const char * const full_room_jid);
|
||||||
char * room_get_nick_for_room(const char * const jid);
|
char * room_get_nick_for_room(const char * const room);
|
||||||
char * room_get_room_for_full_jid(const char * const jid);
|
char * room_get_room_for_full_jid(const char * const full_room_jid);
|
||||||
gboolean room_parse_room_jid(const char * const room_jid, char **room,
|
gboolean room_parse_room_jid(const char * const full_room_jid, char **room,
|
||||||
char **nick);
|
char **nick);
|
||||||
void room_add_to_roster(const char * const jid, const char * const nick);
|
void room_add_to_roster(const char * const room, const char * const nick);
|
||||||
GList * room_get_roster(const char * const jid);
|
GList * room_get_roster(const char * const room);
|
||||||
void room_set_roster_received(const char * const jid);
|
void room_set_roster_received(const char * const room);
|
||||||
gboolean room_get_roster_received(const char * const jid);
|
gboolean room_get_roster_received(const char * const room);
|
||||||
void room_remove_from_roster(const char * const jid, const char * const nick);
|
void room_remove_from_roster(const char * const room, const char * const nick);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user