mirror of
https://github.com/profanity-im/profanity.git
synced 2024-12-04 14:46:46 -05:00
Changed rooms to use Occupant type instead of PContact
This commit is contained in:
parent
2dacfc823a
commit
4f7feedb65
@ -737,9 +737,9 @@ _who_room(const char * const presence)
|
|||||||
GList *filtered = NULL;
|
GList *filtered = NULL;
|
||||||
|
|
||||||
while (list != NULL) {
|
while (list != NULL) {
|
||||||
PContact contact = list->data;
|
Occupant *occupant = list->data;
|
||||||
if (p_contact_is_available(contact)) {
|
if (muc_occupant_available(occupant)) {
|
||||||
filtered = g_list_append(filtered, contact);
|
filtered = g_list_append(filtered, occupant);
|
||||||
}
|
}
|
||||||
list = g_list_next(list);
|
list = g_list_next(list);
|
||||||
}
|
}
|
||||||
@ -751,51 +751,24 @@ _who_room(const char * const presence)
|
|||||||
GList *filtered = NULL;
|
GList *filtered = NULL;
|
||||||
|
|
||||||
while (list != NULL) {
|
while (list != NULL) {
|
||||||
PContact contact = list->data;
|
Occupant *occupant = list->data;
|
||||||
if (!p_contact_is_available(contact)) {
|
if (!muc_occupant_available(occupant)) {
|
||||||
filtered = g_list_append(filtered, contact);
|
filtered = g_list_append(filtered, occupant);
|
||||||
}
|
}
|
||||||
list = g_list_next(list);
|
list = g_list_next(list);
|
||||||
}
|
}
|
||||||
|
|
||||||
ui_room_roster(room, filtered, "unavailable");
|
ui_room_roster(room, filtered, "unavailable");
|
||||||
|
|
||||||
// online, available resources
|
|
||||||
} else if (strcmp("online", presence) == 0) {
|
|
||||||
GList *filtered = NULL;
|
|
||||||
|
|
||||||
while (list != NULL) {
|
|
||||||
PContact contact = list->data;
|
|
||||||
if (p_contact_has_available_resource(contact)) {
|
|
||||||
filtered = g_list_append(filtered, contact);
|
|
||||||
}
|
|
||||||
list = g_list_next(list);
|
|
||||||
}
|
|
||||||
|
|
||||||
ui_room_roster(room, filtered, "online");
|
|
||||||
|
|
||||||
// offline, no available resources
|
|
||||||
} else if (strcmp("offline", presence) == 0) {
|
|
||||||
GList *filtered = NULL;
|
|
||||||
|
|
||||||
while (list != NULL) {
|
|
||||||
PContact contact = list->data;
|
|
||||||
if (!p_contact_has_available_resource(contact)) {
|
|
||||||
filtered = g_list_append(filtered, contact);
|
|
||||||
}
|
|
||||||
list = g_list_next(list);
|
|
||||||
}
|
|
||||||
|
|
||||||
ui_room_roster(room, filtered, "offline");
|
|
||||||
|
|
||||||
// show specific status
|
// show specific status
|
||||||
} else {
|
} else {
|
||||||
GList *filtered = NULL;
|
GList *filtered = NULL;
|
||||||
|
|
||||||
while (list != NULL) {
|
while (list != NULL) {
|
||||||
PContact contact = list->data;
|
Occupant *occupant = list->data;
|
||||||
if (strcmp(p_contact_presence(contact), presence) == 0) {
|
const char *presence_str = string_from_resource_presence(occupant->presence);
|
||||||
filtered = g_list_append(filtered, contact);
|
if (strcmp(presence_str, presence) == 0) {
|
||||||
|
filtered = g_list_append(filtered, occupant);
|
||||||
}
|
}
|
||||||
list = g_list_next(list);
|
list = g_list_next(list);
|
||||||
}
|
}
|
||||||
@ -1464,6 +1437,7 @@ cmd_info(gchar **args, struct cmd_help_t help)
|
|||||||
jabber_conn_status_t conn_status = jabber_get_connection_status();
|
jabber_conn_status_t conn_status = jabber_get_connection_status();
|
||||||
win_type_t win_type = ui_current_win_type();
|
win_type_t win_type = ui_current_win_type();
|
||||||
PContact pcontact = NULL;
|
PContact pcontact = NULL;
|
||||||
|
Occupant *occupant = NULL;
|
||||||
|
|
||||||
if (conn_status != JABBER_CONNECTED) {
|
if (conn_status != JABBER_CONNECTED) {
|
||||||
cons_show("You are not currently connected.");
|
cons_show("You are not currently connected.");
|
||||||
@ -1473,28 +1447,34 @@ cmd_info(gchar **args, struct cmd_help_t help)
|
|||||||
switch (win_type)
|
switch (win_type)
|
||||||
{
|
{
|
||||||
case WIN_MUC:
|
case WIN_MUC:
|
||||||
if (usr != NULL) {
|
if (usr) {
|
||||||
ui_info_room(usr);
|
char *room = ui_current_recipient();
|
||||||
|
occupant = muc_roster_item(room, usr);
|
||||||
|
if (occupant) {
|
||||||
|
ui_info_room(room, occupant);
|
||||||
|
} else {
|
||||||
|
ui_current_print_line("No such occupant \"%s\" in room.", usr);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
ui_current_print_line("You must specify a nickname.");
|
ui_current_print_line("You must specify a nickname.");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case WIN_CHAT:
|
case WIN_CHAT:
|
||||||
if (usr != NULL) {
|
if (usr) {
|
||||||
ui_current_print_line("No parameter required when in chat.");
|
ui_current_print_line("No parameter required when in chat.");
|
||||||
} else {
|
} else {
|
||||||
ui_info();
|
ui_info();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case WIN_PRIVATE:
|
case WIN_PRIVATE:
|
||||||
if (usr != NULL) {
|
if (usr) {
|
||||||
ui_current_print_line("No parameter required when in chat.");
|
ui_current_print_line("No parameter required when in chat.");
|
||||||
} else {
|
} else {
|
||||||
ui_info_private();
|
ui_info_private();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case WIN_CONSOLE:
|
case WIN_CONSOLE:
|
||||||
if (usr != NULL) {
|
if (usr) {
|
||||||
char *usr_jid = roster_barejid_from_name(usr);
|
char *usr_jid = roster_barejid_from_name(usr);
|
||||||
if (usr_jid == NULL) {
|
if (usr_jid == NULL) {
|
||||||
usr_jid = usr;
|
usr_jid = usr;
|
||||||
@ -1522,6 +1502,7 @@ cmd_caps(gchar **args, struct cmd_help_t help)
|
|||||||
jabber_conn_status_t conn_status = jabber_get_connection_status();
|
jabber_conn_status_t conn_status = jabber_get_connection_status();
|
||||||
win_type_t win_type = ui_current_win_type();
|
win_type_t win_type = ui_current_win_type();
|
||||||
PContact pcontact = NULL;
|
PContact pcontact = NULL;
|
||||||
|
Occupant *occupant = NULL;
|
||||||
|
|
||||||
if (conn_status != JABBER_CONNECTED) {
|
if (conn_status != JABBER_CONNECTED) {
|
||||||
cons_show("You are not currently connected.");
|
cons_show("You are not currently connected.");
|
||||||
@ -1533,11 +1514,10 @@ cmd_caps(gchar **args, struct cmd_help_t help)
|
|||||||
case WIN_MUC:
|
case WIN_MUC:
|
||||||
if (args[0] != NULL) {
|
if (args[0] != NULL) {
|
||||||
char *room = ui_current_recipient();
|
char *room = ui_current_recipient();
|
||||||
pcontact = muc_roster_item(room, args[0]);
|
occupant = muc_roster_item(room, args[0]);
|
||||||
if (pcontact != NULL) {
|
if (occupant) {
|
||||||
Jid *jidp = jid_create_from_bare_and_resource(room, args[0]);
|
Jid *jidp = jid_create_from_bare_and_resource(room, args[0]);
|
||||||
Resource *resource = p_contact_get_resource(pcontact, args[0]);
|
cons_show_caps(jidp->fulljid, occupant->presence);
|
||||||
cons_show_caps(jidp->fulljid, resource);
|
|
||||||
jid_destroy(jidp);
|
jid_destroy(jidp);
|
||||||
} else {
|
} else {
|
||||||
cons_show("No such participant \"%s\" in room.", args[0]);
|
cons_show("No such participant \"%s\" in room.", args[0]);
|
||||||
@ -1562,7 +1542,7 @@ cmd_caps(gchar **args, struct cmd_help_t help)
|
|||||||
if (resource == NULL) {
|
if (resource == NULL) {
|
||||||
cons_show("Could not find resource %s, for contact %s", jid->barejid, jid->resourcepart);
|
cons_show("Could not find resource %s, for contact %s", jid->barejid, jid->resourcepart);
|
||||||
} else {
|
} else {
|
||||||
cons_show_caps(jid->fulljid, resource);
|
cons_show_caps(jid->fulljid, resource->presence);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1578,9 +1558,8 @@ cmd_caps(gchar **args, struct cmd_help_t help)
|
|||||||
char *recipient = ui_current_recipient();
|
char *recipient = ui_current_recipient();
|
||||||
Jid *jid = jid_create(recipient);
|
Jid *jid = jid_create(recipient);
|
||||||
if (jid) {
|
if (jid) {
|
||||||
pcontact = muc_roster_item(jid->barejid, jid->resourcepart);
|
occupant = muc_roster_item(jid->barejid, jid->resourcepart);
|
||||||
Resource *resource = p_contact_get_resource(pcontact, jid->resourcepart);
|
cons_show_caps(jid->resourcepart, occupant->presence);
|
||||||
cons_show_caps(jid->resourcepart, resource);
|
|
||||||
jid_destroy(jid);
|
jid_destroy(jid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1598,7 +1577,7 @@ cmd_software(gchar **args, struct cmd_help_t help)
|
|||||||
{
|
{
|
||||||
jabber_conn_status_t conn_status = jabber_get_connection_status();
|
jabber_conn_status_t conn_status = jabber_get_connection_status();
|
||||||
win_type_t win_type = ui_current_win_type();
|
win_type_t win_type = ui_current_win_type();
|
||||||
PContact pcontact = NULL;
|
Occupant *occupant = NULL;
|
||||||
char *recipient;
|
char *recipient;
|
||||||
|
|
||||||
if (conn_status != JABBER_CONNECTED) {
|
if (conn_status != JABBER_CONNECTED) {
|
||||||
@ -1611,8 +1590,8 @@ cmd_software(gchar **args, struct cmd_help_t help)
|
|||||||
case WIN_MUC:
|
case WIN_MUC:
|
||||||
if (args[0] != NULL) {
|
if (args[0] != NULL) {
|
||||||
recipient = ui_current_recipient();
|
recipient = ui_current_recipient();
|
||||||
pcontact = muc_roster_item(recipient, args[0]);
|
occupant = muc_roster_item(recipient, args[0]);
|
||||||
if (pcontact != NULL) {
|
if (occupant) {
|
||||||
Jid *jid = jid_create_from_bare_and_resource(recipient, args[0]);
|
Jid *jid = jid_create_from_bare_and_resource(recipient, args[0]);
|
||||||
iq_send_software_version(jid->fulljid);
|
iq_send_software_version(jid->fulljid);
|
||||||
jid_destroy(jid);
|
jid_destroy(jid);
|
||||||
|
105
src/muc.c
105
src/muc.c
@ -42,21 +42,7 @@
|
|||||||
#include "jid.h"
|
#include "jid.h"
|
||||||
#include "tools/autocomplete.h"
|
#include "tools/autocomplete.h"
|
||||||
#include "ui/ui.h"
|
#include "ui/ui.h"
|
||||||
|
#include "muc.h"
|
||||||
typedef enum {
|
|
||||||
MUC_ROLE_NONE,
|
|
||||||
MUC_ROLE_VISITOR,
|
|
||||||
MUC_ROLE_PARTICIPANT,
|
|
||||||
MUC_ROLE_MODERATOR
|
|
||||||
} muc_role_t;
|
|
||||||
|
|
||||||
typedef enum {
|
|
||||||
MUC_AFFILIATION_NONE,
|
|
||||||
MUC_AFFILIATION_OUTCAST,
|
|
||||||
MUC_AFFILIATION_MEMBER,
|
|
||||||
MUC_AFFILIATION_ADMIN,
|
|
||||||
MUC_AFFILIATION_OWNER
|
|
||||||
} muc_affiliation_t;
|
|
||||||
|
|
||||||
typedef struct _muc_room_t {
|
typedef struct _muc_room_t {
|
||||||
char *room; // e.g. test@conference.server
|
char *room; // e.g. test@conference.server
|
||||||
@ -80,11 +66,13 @@ GHashTable *rooms = NULL;
|
|||||||
Autocomplete invite_ac;
|
Autocomplete invite_ac;
|
||||||
|
|
||||||
static void _free_room(ChatRoom *room);
|
static void _free_room(ChatRoom *room);
|
||||||
static gint _compare_participants(PContact a, PContact b);
|
static gint _compare_occupants(Occupant *a, Occupant *b);
|
||||||
static muc_role_t _role_from_string(const char * const role);
|
static muc_role_t _role_from_string(const char * const role);
|
||||||
static muc_affiliation_t _affiliation_from_string(const char * const affiliation);
|
static muc_affiliation_t _affiliation_from_string(const char * const affiliation);
|
||||||
static char* _role_to_string(muc_role_t role);
|
static char* _role_to_string(muc_role_t role);
|
||||||
static char* _affiliation_to_string(muc_affiliation_t affiliation);
|
static char* _affiliation_to_string(muc_affiliation_t affiliation);
|
||||||
|
static Occupant* _muc_occupant_new(const char *const nick, resource_presence_t presence, const char * const status);
|
||||||
|
static void _occupant_free(Occupant *occupant);
|
||||||
|
|
||||||
void
|
void
|
||||||
muc_init(void)
|
muc_init(void)
|
||||||
@ -102,13 +90,13 @@ muc_close(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
muc_invites_add(char *room)
|
muc_invites_add(const char * const room)
|
||||||
{
|
{
|
||||||
autocomplete_add(invite_ac, room);
|
autocomplete_add(invite_ac, room);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
muc_invites_remove(char *room)
|
muc_invites_remove(const char * const room)
|
||||||
{
|
{
|
||||||
autocomplete_remove(invite_ac, room);
|
autocomplete_remove(invite_ac, room);
|
||||||
}
|
}
|
||||||
@ -179,11 +167,9 @@ muc_join(const char * const room, const char * const nick,
|
|||||||
new_room->subject = NULL;
|
new_room->subject = NULL;
|
||||||
new_room->pending_broadcasts = NULL;
|
new_room->pending_broadcasts = NULL;
|
||||||
new_room->pending_config = FALSE;
|
new_room->pending_config = FALSE;
|
||||||
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)_occupant_free);
|
||||||
(GDestroyNotify)p_contact_free);
|
|
||||||
new_room->nick_ac = autocomplete_new();
|
new_room->nick_ac = autocomplete_new();
|
||||||
new_room->nick_changes = g_hash_table_new_full(g_str_hash, g_str_equal,
|
new_room->nick_changes = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free);
|
||||||
g_free, g_free);
|
|
||||||
new_room->roster_received = FALSE;
|
new_room->roster_received = FALSE;
|
||||||
new_room->pending_nick_change = FALSE;
|
new_room->pending_nick_change = FALSE;
|
||||||
new_room->autojoin = autojoin;
|
new_room->autojoin = autojoin;
|
||||||
@ -385,8 +371,8 @@ muc_roster_contains_nick(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);
|
Occupant *occupant = g_hash_table_lookup(chat_room->roster, nick);
|
||||||
return (contact != NULL);
|
return (occupant != NULL);
|
||||||
} else {
|
} else {
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
@ -401,23 +387,22 @@ muc_roster_add(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);
|
||||||
gboolean updated = FALSE;
|
gboolean updated = FALSE;
|
||||||
|
resource_presence_t new_presence = resource_presence_from_string(show);
|
||||||
|
|
||||||
if (chat_room) {
|
if (chat_room) {
|
||||||
PContact old = g_hash_table_lookup(chat_room->roster, nick);
|
Occupant *old = g_hash_table_lookup(chat_room->roster, nick);
|
||||||
|
|
||||||
if (!old) {
|
if (!old) {
|
||||||
updated = TRUE;
|
updated = TRUE;
|
||||||
autocomplete_add(chat_room->nick_ac, nick);
|
autocomplete_add(chat_room->nick_ac, nick);
|
||||||
} else if ((g_strcmp0(p_contact_presence(old), show) != 0) ||
|
} else if (old->presence != new_presence ||
|
||||||
(g_strcmp0(p_contact_status(old), status) != 0)) {
|
(g_strcmp0(old->status, status) != 0)) {
|
||||||
updated = TRUE;
|
updated = TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
PContact contact = p_contact_new(nick, NULL, NULL, NULL, NULL, FALSE);
|
resource_presence_t presence = resource_presence_from_string(show);
|
||||||
resource_presence_t resource_presence = resource_presence_from_string(show);
|
Occupant *occupant = _muc_occupant_new(nick, presence, status);
|
||||||
Resource *resource = resource_new(nick, resource_presence, status, 0);
|
g_hash_table_replace(chat_room->roster, strdup(nick), occupant);
|
||||||
p_contact_set_presence(contact, resource);
|
|
||||||
g_hash_table_replace(chat_room->roster, strdup(nick), contact);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return updated;
|
return updated;
|
||||||
@ -436,13 +421,13 @@ muc_roster_remove(const char * const room, const char * const nick)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
PContact
|
Occupant *
|
||||||
muc_roster_item(const char * const room, const char * const nick)
|
muc_roster_item(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);
|
Occupant *occupant = g_hash_table_lookup(chat_room->roster, nick);
|
||||||
return participant;
|
return occupant;
|
||||||
} else {
|
} else {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@ -464,7 +449,7 @@ muc_roster(const char * const room)
|
|||||||
|
|
||||||
g_hash_table_iter_init(&iter, chat_room->roster);
|
g_hash_table_iter_init(&iter, chat_room->roster);
|
||||||
while (g_hash_table_iter_next(&iter, &key, &value)) {
|
while (g_hash_table_iter_next(&iter, &key, &value)) {
|
||||||
result = g_list_insert_sorted(result, value, (GCompareFunc)_compare_participants);
|
result = g_list_insert_sorted(result, value, (GCompareFunc)_compare_occupants);
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
@ -513,6 +498,12 @@ muc_roster_complete(const char * const room)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
gboolean
|
||||||
|
muc_occupant_available(Occupant *occupant)
|
||||||
|
{
|
||||||
|
return (occupant->presence == RESOURCE_ONLINE || occupant->presence == RESOURCE_CHAT);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Remove the old_nick from the roster, and flag that a pending nickname change
|
* Remove the old_nick from the roster, and flag that a pending nickname change
|
||||||
* is in progress
|
* is in progress
|
||||||
@ -669,10 +660,10 @@ _free_room(ChatRoom *room)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static
|
static
|
||||||
gint _compare_participants(PContact a, PContact b)
|
gint _compare_occupants(Occupant *a, Occupant *b)
|
||||||
{
|
{
|
||||||
const char * utf8_str_a = p_contact_barejid(a);
|
const char * utf8_str_a = a->nick;
|
||||||
const char * utf8_str_b = p_contact_barejid(b);
|
const char * utf8_str_b = b->nick;
|
||||||
|
|
||||||
gchar *key_a = g_utf8_collate_key(utf8_str_a, -1);
|
gchar *key_a = g_utf8_collate_key(utf8_str_a, -1);
|
||||||
gchar *key_b = g_utf8_collate_key(utf8_str_b, -1);
|
gchar *key_b = g_utf8_collate_key(utf8_str_b, -1);
|
||||||
@ -777,3 +768,39 @@ _affiliation_to_string(muc_affiliation_t affiliation)
|
|||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static Occupant*
|
||||||
|
_muc_occupant_new(const char *const nick, resource_presence_t presence, const char * const status)
|
||||||
|
{
|
||||||
|
Occupant *occupant = malloc(sizeof(Occupant));
|
||||||
|
|
||||||
|
if (nick) {
|
||||||
|
occupant->nick = strdup(nick);
|
||||||
|
} else {
|
||||||
|
occupant->nick = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
occupant->presence = presence;
|
||||||
|
|
||||||
|
if (status) {
|
||||||
|
occupant->status = strdup(status);
|
||||||
|
} else {
|
||||||
|
occupant->status = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
occupant->role = MUC_ROLE_NONE;
|
||||||
|
occupant->affiliation = MUC_AFFILIATION_NONE;
|
||||||
|
|
||||||
|
return occupant;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
_occupant_free(Occupant *occupant)
|
||||||
|
{
|
||||||
|
if (occupant) {
|
||||||
|
free(occupant->nick);
|
||||||
|
free(occupant->status);
|
||||||
|
free(occupant);
|
||||||
|
occupant = NULL;
|
||||||
|
}
|
||||||
|
}
|
29
src/muc.h
29
src/muc.h
@ -41,6 +41,29 @@
|
|||||||
#include "jid.h"
|
#include "jid.h"
|
||||||
#include "tools/autocomplete.h"
|
#include "tools/autocomplete.h"
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
MUC_ROLE_NONE,
|
||||||
|
MUC_ROLE_VISITOR,
|
||||||
|
MUC_ROLE_PARTICIPANT,
|
||||||
|
MUC_ROLE_MODERATOR
|
||||||
|
} muc_role_t;
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
MUC_AFFILIATION_NONE,
|
||||||
|
MUC_AFFILIATION_OUTCAST,
|
||||||
|
MUC_AFFILIATION_MEMBER,
|
||||||
|
MUC_AFFILIATION_ADMIN,
|
||||||
|
MUC_AFFILIATION_OWNER
|
||||||
|
} muc_affiliation_t;
|
||||||
|
|
||||||
|
typedef struct _muc_occupant_t {
|
||||||
|
char *nick;
|
||||||
|
muc_role_t role;
|
||||||
|
muc_affiliation_t affiliation;
|
||||||
|
resource_presence_t presence;
|
||||||
|
char *status;
|
||||||
|
} Occupant;
|
||||||
|
|
||||||
void muc_init(void);
|
void muc_init(void);
|
||||||
void muc_close(void);
|
void muc_close(void);
|
||||||
|
|
||||||
@ -68,12 +91,14 @@ void muc_roster_remove(const char * const room, const char * const nick);
|
|||||||
void muc_roster_set_complete(const char * const room);
|
void muc_roster_set_complete(const char * const room);
|
||||||
GList * muc_roster(const char * const room);
|
GList * muc_roster(const char * const room);
|
||||||
Autocomplete muc_roster_ac(const char * const room);
|
Autocomplete muc_roster_ac(const char * const room);
|
||||||
PContact muc_roster_item(const char * const room, const char * const nick);
|
Occupant* muc_roster_item(const char * const room, const char * const nick);
|
||||||
|
|
||||||
|
gboolean muc_occupant_available(Occupant *occupant);
|
||||||
|
|
||||||
void muc_roster_nick_change_start(const char * const room, const char * const new_nick, const char * const old_nick);
|
void muc_roster_nick_change_start(const char * const room, const char * const new_nick, const char * const old_nick);
|
||||||
char* muc_roster_nick_change_complete(const char * const room, const char * const nick);
|
char* muc_roster_nick_change_complete(const char * const room, const char * const nick);
|
||||||
|
|
||||||
void muc_invites_add(const char *room);
|
void muc_invites_add(const char * const room);
|
||||||
void muc_invites_remove(const char * const room);
|
void muc_invites_remove(const char * const room);
|
||||||
gint muc_invites_count(void);
|
gint muc_invites_count(void);
|
||||||
GSList* muc_invites(void);
|
GSList* muc_invites(void);
|
||||||
|
@ -32,6 +32,7 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
@ -282,14 +283,14 @@ _cons_show_info(PContact pcontact)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
_cons_show_caps(const char * const fulljid, Resource *resource)
|
_cons_show_caps(const char * const fulljid, resource_presence_t presence)
|
||||||
{
|
{
|
||||||
ProfWin *console = wins_get_console();
|
ProfWin *console = wins_get_console();
|
||||||
cons_show("");
|
cons_show("");
|
||||||
|
|
||||||
Capabilities *caps = caps_lookup(fulljid);
|
Capabilities *caps = caps_lookup(fulljid);
|
||||||
if (caps) {
|
if (caps) {
|
||||||
const char *resource_presence = string_from_resource_presence(resource->presence);
|
const char *resource_presence = string_from_resource_presence(presence);
|
||||||
|
|
||||||
int presence_colour = win_presence_colour(resource_presence);
|
int presence_colour = win_presence_colour(resource_presence);
|
||||||
win_save_vprint(console, '-', NULL, NO_EOL, presence_colour, "", "%s", fulljid);
|
win_save_vprint(console, '-', NULL, NO_EOL, presence_colour, "", "%s", fulljid);
|
||||||
|
@ -1393,13 +1393,13 @@ _ui_room_roster(const char * const room, GList *roster, const char * const prese
|
|||||||
if (presence == NULL) {
|
if (presence == NULL) {
|
||||||
win_save_print(window, '!', NULL, 0, COLOUR_ROOMINFO, "", "Room is empty.");
|
win_save_print(window, '!', NULL, 0, COLOUR_ROOMINFO, "", "Room is empty.");
|
||||||
} else {
|
} else {
|
||||||
win_save_vprint(window, '!', NULL, 0, COLOUR_ROOMINFO, "", "No participants %s.", presence);
|
win_save_vprint(window, '!', NULL, 0, COLOUR_ROOMINFO, "", "No occupants %s.", presence);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
int length = g_list_length(roster);
|
int length = g_list_length(roster);
|
||||||
if (presence == NULL) {
|
if (presence == NULL) {
|
||||||
length++;
|
length++;
|
||||||
win_save_vprint(window, '!', NULL, NO_EOL, COLOUR_ROOMINFO, "", "%d participants: ", length);
|
win_save_vprint(window, '!', NULL, NO_EOL, COLOUR_ROOMINFO, "", "%d occupants: ", length);
|
||||||
win_save_vprint(window, '!', NULL, NO_DATE | NO_EOL, COLOUR_ONLINE, "", "%s", muc_nick(room));
|
win_save_vprint(window, '!', NULL, NO_DATE | NO_EOL, COLOUR_ONLINE, "", "%s", muc_nick(room));
|
||||||
win_save_print(window, '!', NULL, NO_DATE | NO_EOL, 0, "", ", ");
|
win_save_print(window, '!', NULL, NO_DATE | NO_EOL, 0, "", ", ");
|
||||||
} else {
|
} else {
|
||||||
@ -1407,12 +1407,11 @@ _ui_room_roster(const char * const room, GList *roster, const char * const prese
|
|||||||
}
|
}
|
||||||
|
|
||||||
while (roster != NULL) {
|
while (roster != NULL) {
|
||||||
PContact member = roster->data;
|
Occupant *occupant = roster->data;
|
||||||
const char *nick = p_contact_barejid(member);
|
const char *presence_str = string_from_resource_presence(occupant->presence);
|
||||||
const char *show = p_contact_presence(member);
|
|
||||||
|
|
||||||
int presence_colour = win_presence_colour(show);
|
int presence_colour = win_presence_colour(presence_str);
|
||||||
win_save_vprint(window, '!', NULL, NO_DATE | NO_EOL, presence_colour, "", "%s", nick);
|
win_save_vprint(window, '!', NULL, NO_DATE | NO_EOL, presence_colour, "", "%s", occupant->nick);
|
||||||
|
|
||||||
if (roster->next != NULL) {
|
if (roster->next != NULL) {
|
||||||
win_save_print(window, '!', NULL, NO_DATE | NO_EOL, 0, "", ", ");
|
win_save_print(window, '!', NULL, NO_DATE | NO_EOL, 0, "", ", ");
|
||||||
@ -1731,11 +1730,11 @@ static void
|
|||||||
_ui_status_private(void)
|
_ui_status_private(void)
|
||||||
{
|
{
|
||||||
Jid *jid = jid_create(ui_current_recipient());
|
Jid *jid = jid_create(ui_current_recipient());
|
||||||
PContact pcontact = muc_roster_item(jid->barejid, jid->resourcepart);
|
Occupant *occupant = muc_roster_item(jid->barejid, jid->resourcepart);
|
||||||
ProfWin *window = wins_get_current();
|
ProfWin *window = wins_get_current();
|
||||||
|
|
||||||
if (pcontact != NULL) {
|
if (occupant) {
|
||||||
win_show_contact(window, pcontact);
|
win_show_occupant(window, occupant);
|
||||||
} else {
|
} else {
|
||||||
win_save_println(window, "Error getting contact info.");
|
win_save_println(window, "Error getting contact info.");
|
||||||
}
|
}
|
||||||
@ -1747,11 +1746,11 @@ static void
|
|||||||
_ui_info_private(void)
|
_ui_info_private(void)
|
||||||
{
|
{
|
||||||
Jid *jid = jid_create(ui_current_recipient());
|
Jid *jid = jid_create(ui_current_recipient());
|
||||||
PContact pcontact = muc_roster_item(jid->barejid, jid->resourcepart);
|
Occupant *occupant = muc_roster_item(jid->barejid, jid->resourcepart);
|
||||||
ProfWin *window = wins_get_current();
|
ProfWin *window = wins_get_current();
|
||||||
|
|
||||||
if (pcontact != NULL) {
|
if (occupant) {
|
||||||
win_show_info(window, pcontact);
|
win_show_occupant_info(window, jid->barejid, occupant);
|
||||||
} else {
|
} else {
|
||||||
win_save_println(window, "Error getting contact info.");
|
win_save_println(window, "Error getting contact info.");
|
||||||
}
|
}
|
||||||
@ -1762,27 +1761,21 @@ _ui_info_private(void)
|
|||||||
static void
|
static void
|
||||||
_ui_status_room(const char * const contact)
|
_ui_status_room(const char * const contact)
|
||||||
{
|
{
|
||||||
PContact pcontact = muc_roster_item(ui_current_recipient(), contact);
|
Occupant *occupant = muc_roster_item(ui_current_recipient(), contact);
|
||||||
ProfWin *current = wins_get_current();
|
ProfWin *current = wins_get_current();
|
||||||
|
|
||||||
if (pcontact != NULL) {
|
if (occupant) {
|
||||||
win_show_contact(current, pcontact);
|
win_show_occupant(current, occupant);
|
||||||
} else {
|
} else {
|
||||||
win_save_vprint(current, '-', NULL, 0, 0, "", "No such participant \"%s\" in room.", contact);
|
win_save_vprint(current, '-', NULL, 0, 0, "", "No such participant \"%s\" in room.", contact);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
_ui_info_room(const char * const contact)
|
_ui_info_room(const char * const room, Occupant *occupant)
|
||||||
{
|
{
|
||||||
PContact pcontact = muc_roster_item(ui_current_recipient(), contact);
|
|
||||||
ProfWin *current = wins_get_current();
|
ProfWin *current = wins_get_current();
|
||||||
|
win_show_occupant_info(current, room, occupant);
|
||||||
if (pcontact != NULL) {
|
|
||||||
win_show_info(current, pcontact);
|
|
||||||
} else {
|
|
||||||
win_save_vprint(current, '-', NULL, 0, 0, "", "No such participant \"%s\" in room.", contact);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static gint
|
static gint
|
||||||
|
@ -172,7 +172,7 @@ void (*ui_show_lines)(ProfWin *window, const gchar** lines);
|
|||||||
|
|
||||||
// contact status functions
|
// contact status functions
|
||||||
void (*ui_status_room)(const char * const contact);
|
void (*ui_status_room)(const char * const contact);
|
||||||
void (*ui_info_room)(const char * const contact);
|
void (*ui_info_room)(const char * const room, Occupant *occupant);
|
||||||
void (*ui_status)(void);
|
void (*ui_status)(void);
|
||||||
void (*ui_info)(void);
|
void (*ui_info)(void);
|
||||||
void (*ui_status_private)(void);
|
void (*ui_status_private)(void);
|
||||||
@ -234,7 +234,7 @@ void (*cons_show_roster_group)(const char * const group, GSList * list);
|
|||||||
void (*cons_show_wins)(void);
|
void (*cons_show_wins)(void);
|
||||||
void (*cons_show_status)(const char * const barejid);
|
void (*cons_show_status)(const char * const barejid);
|
||||||
void (*cons_show_info)(PContact pcontact);
|
void (*cons_show_info)(PContact pcontact);
|
||||||
void (*cons_show_caps)(const char * const fulljid, Resource *resource);
|
void (*cons_show_caps)(const char * const fulljid, resource_presence_t presence);
|
||||||
void (*cons_show_themes)(GSList *themes);
|
void (*cons_show_themes)(GSList *themes);
|
||||||
void (*cons_show_aliases)(GList *aliases);
|
void (*cons_show_aliases)(GList *aliases);
|
||||||
void (*cons_show_login_success)(ProfAccount *account);
|
void (*cons_show_login_success)(ProfAccount *account);
|
||||||
|
@ -125,6 +125,23 @@ win_presence_colour(const char * const presence)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
win_show_occupant(ProfWin *window, Occupant *occupant)
|
||||||
|
{
|
||||||
|
const char *presence_str = string_from_resource_presence(occupant->presence);
|
||||||
|
|
||||||
|
int presence_colour = win_presence_colour(presence_str);
|
||||||
|
|
||||||
|
win_save_print(window, '-', NULL, NO_EOL, presence_colour, "", occupant->nick);
|
||||||
|
win_save_vprint(window, '-', NULL, NO_DATE | NO_EOL, presence_colour, "", " is %s", presence_str);
|
||||||
|
|
||||||
|
if (occupant->status) {
|
||||||
|
win_save_vprint(window, '-', NULL, NO_DATE | NO_EOL, presence_colour, "", ", \"%s\"", occupant->status);
|
||||||
|
}
|
||||||
|
|
||||||
|
win_save_print(window, '-', NULL, NO_DATE, presence_colour, "", "");
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
win_show_contact(ProfWin *window, PContact contact)
|
win_show_contact(ProfWin *window, PContact contact)
|
||||||
{
|
{
|
||||||
@ -169,6 +186,68 @@ win_show_contact(ProfWin *window, PContact contact)
|
|||||||
win_save_print(window, '-', NULL, NO_DATE, presence_colour, "", "");
|
win_save_print(window, '-', NULL, NO_DATE, presence_colour, "", "");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
win_show_occupant_info(ProfWin *window, const char * const room, Occupant *occupant)
|
||||||
|
{
|
||||||
|
const char *presence_str = string_from_resource_presence(occupant->presence);
|
||||||
|
|
||||||
|
int presence_colour = win_presence_colour(presence_str);
|
||||||
|
|
||||||
|
win_save_print(window, '-', NULL, NO_EOL, presence_colour, "", occupant->nick);
|
||||||
|
win_save_vprint(window, '-', NULL, NO_DATE | NO_EOL, presence_colour, "", " is %s", presence_str);
|
||||||
|
|
||||||
|
if (occupant->status) {
|
||||||
|
win_save_vprint(window, '-', NULL, NO_DATE | NO_EOL, presence_colour, "", ", \"%s\"", occupant->status);
|
||||||
|
}
|
||||||
|
|
||||||
|
win_save_newline(window);
|
||||||
|
|
||||||
|
Jid *jidp = jid_create_from_bare_and_resource(room, occupant->nick);
|
||||||
|
Capabilities *caps = caps_lookup(jidp->fulljid);
|
||||||
|
|
||||||
|
if (caps) {
|
||||||
|
// show identity
|
||||||
|
if ((caps->category != NULL) || (caps->type != NULL) || (caps->name != NULL)) {
|
||||||
|
win_save_print(window, '-', NULL, NO_EOL, 0, "", " Identity: ");
|
||||||
|
if (caps->name != NULL) {
|
||||||
|
win_save_print(window, '-', NULL, NO_DATE | NO_EOL, 0, "", caps->name);
|
||||||
|
if ((caps->category != NULL) || (caps->type != NULL)) {
|
||||||
|
win_save_print(window, '-', NULL, NO_DATE | NO_EOL, 0, "", " ");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (caps->type != NULL) {
|
||||||
|
win_save_print(window, '-', NULL, NO_DATE | NO_EOL, 0, "", caps->type);
|
||||||
|
if (caps->category != NULL) {
|
||||||
|
win_save_print(window, '-', NULL, NO_DATE | NO_EOL, 0, "", " ");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (caps->category != NULL) {
|
||||||
|
win_save_print(window, '-', NULL, NO_DATE | NO_EOL, 0, "", caps->category);
|
||||||
|
}
|
||||||
|
win_save_newline(window);
|
||||||
|
}
|
||||||
|
if (caps->software != NULL) {
|
||||||
|
win_save_vprint(window, '-', NULL, NO_EOL, 0, "", " Software: %s", caps->software);
|
||||||
|
}
|
||||||
|
if (caps->software_version != NULL) {
|
||||||
|
win_save_vprint(window, '-', NULL, NO_DATE | NO_EOL, 0, "", ", %s", caps->software_version);
|
||||||
|
}
|
||||||
|
if ((caps->software != NULL) || (caps->software_version != NULL)) {
|
||||||
|
win_save_newline(window);
|
||||||
|
}
|
||||||
|
if (caps->os != NULL) {
|
||||||
|
win_save_vprint(window, '-', NULL, NO_EOL, 0, "", " OS: %s", caps->os);
|
||||||
|
}
|
||||||
|
if (caps->os_version != NULL) {
|
||||||
|
win_save_vprint(window, '-', NULL, NO_DATE | NO_EOL, 0, "", ", %s", caps->os_version);
|
||||||
|
}
|
||||||
|
if ((caps->os != NULL) || (caps->os_version != NULL)) {
|
||||||
|
win_save_newline(window);
|
||||||
|
}
|
||||||
|
caps_destroy(caps);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
win_show_info(ProfWin *window, PContact contact)
|
win_show_info(ProfWin *window, PContact contact)
|
||||||
{
|
{
|
||||||
|
@ -44,6 +44,7 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "contact.h"
|
#include "contact.h"
|
||||||
|
#include "muc.h"
|
||||||
#include "ui/buffer.h"
|
#include "ui/buffer.h"
|
||||||
#include "xmpp/xmpp.h"
|
#include "xmpp/xmpp.h"
|
||||||
|
|
||||||
@ -85,6 +86,7 @@ void win_update_virtual(ProfWin *window);
|
|||||||
void win_move_to_end(ProfWin *window);
|
void win_move_to_end(ProfWin *window);
|
||||||
int win_presence_colour(const char * const presence);
|
int win_presence_colour(const char * const presence);
|
||||||
void win_show_contact(ProfWin *window, PContact contact);
|
void win_show_contact(ProfWin *window, PContact contact);
|
||||||
|
void win_show_occupant(ProfWin *window, Occupant *occupant);
|
||||||
void win_show_status_string(ProfWin *window, const char * const from,
|
void win_show_status_string(ProfWin *window, const char * const from,
|
||||||
const char * const show, const char * const status,
|
const char * const show, const char * const status,
|
||||||
GDateTime *last_activity, const char * const pre,
|
GDateTime *last_activity, const char * const pre,
|
||||||
@ -92,6 +94,7 @@ void win_show_status_string(ProfWin *window, const char * const from,
|
|||||||
void win_print_incoming_message(ProfWin *window, GTimeVal *tv_stamp,
|
void win_print_incoming_message(ProfWin *window, GTimeVal *tv_stamp,
|
||||||
const char * const from, const char * const message);
|
const char * const from, const char * const message);
|
||||||
void win_show_info(ProfWin *window, PContact contact);
|
void win_show_info(ProfWin *window, PContact contact);
|
||||||
|
void win_show_occupant_info(ProfWin *window, const char * const room, Occupant *occupant);
|
||||||
void win_save_vprint(ProfWin *window, const char show_char, GTimeVal *tstamp, int flags, int attrs, const char * const from, const char * const message, ...);
|
void win_save_vprint(ProfWin *window, const char show_char, GTimeVal *tstamp, int flags, int attrs, const char * const from, const char * const message, ...);
|
||||||
void win_save_print(ProfWin *window, const char show_char, GTimeVal *tstamp, int flags, int attrs, const char * const from, const char * const message);
|
void win_save_print(ProfWin *window, const char show_char, GTimeVal *tstamp, int flags, int attrs, const char * const from, const char * const message);
|
||||||
void win_save_println(ProfWin *window, const char * const message);
|
void win_save_println(ProfWin *window, const char * const message);
|
||||||
|
@ -493,16 +493,17 @@ _version_result_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
|
|||||||
os_str = xmpp_stanza_get_text(os);
|
os_str = xmpp_stanza_get_text(os);
|
||||||
}
|
}
|
||||||
|
|
||||||
PContact contact;
|
|
||||||
Jid *jidp = jid_create(jid);
|
Jid *jidp = jid_create(jid);
|
||||||
|
const char *presence = NULL;
|
||||||
if (muc_active(jidp->barejid)) {
|
if (muc_active(jidp->barejid)) {
|
||||||
contact = muc_roster_item(jidp->barejid, jidp->resourcepart);
|
Occupant *occupant = muc_roster_item(jidp->barejid, jidp->resourcepart);
|
||||||
|
presence = string_from_resource_presence(occupant->presence);
|
||||||
} else {
|
} else {
|
||||||
contact = roster_get_contact(jidp->barejid);
|
PContact contact = roster_get_contact(jidp->barejid);
|
||||||
|
Resource *resource = p_contact_get_resource(contact, jidp->resourcepart);
|
||||||
|
presence = string_from_resource_presence(resource->presence);
|
||||||
}
|
}
|
||||||
|
|
||||||
Resource *resource = p_contact_get_resource(contact, jidp->resourcepart);
|
|
||||||
const char *presence = string_from_resource_presence(resource->presence);
|
|
||||||
handle_software_version_result(jid, presence, name_str, version_str, os_str);
|
handle_software_version_result(jid, presence, name_str, version_str, os_str);
|
||||||
|
|
||||||
jid_destroy(jidp);
|
jid_destroy(jidp);
|
||||||
|
Loading…
Reference in New Issue
Block a user