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

Store real jid with occupants

This commit is contained in:
James Booth 2014-10-01 13:27:01 +01:00
parent b189f8f52e
commit 60e0d5ef7b
8 changed files with 47 additions and 24 deletions

View File

@ -4,3 +4,4 @@ Changing subject
Moderator use cases
Admin use cases
Owner use cases
Check commands from private conversations

View File

@ -71,8 +71,8 @@ static muc_role_t _role_from_string(const char * const role);
static muc_affiliation_t _affiliation_from_string(const char * const affiliation);
static char* _role_to_string(muc_role_t role);
static char* _affiliation_to_string(muc_affiliation_t affiliation);
static Occupant* _muc_occupant_new(const char *const nick, muc_role_t role, muc_affiliation_t affiliation,
resource_presence_t presence, const char * const status);
static Occupant* _muc_occupant_new(const char *const nick, const char * const jid,
muc_role_t role, muc_affiliation_t affiliation, resource_presence_t presence, const char * const status);
static void _occupant_free(Occupant *occupant);
void
@ -383,8 +383,8 @@ muc_roster_contains_nick(const char * const room, const char * const nick)
* Add a new chat room member to the room's roster
*/
gboolean
muc_roster_add(const char * const room, const char * const nick, const char * const role,
const char * const affiliation, const char * const show, const char * const status)
muc_roster_add(const char * const room, const char * const nick, const char * const jid,
const char * const role, const char * const affiliation, const char * const show, const char * const status)
{
ChatRoom *chat_room = g_hash_table_lookup(rooms, room);
gboolean updated = FALSE;
@ -404,7 +404,7 @@ muc_roster_add(const char * const room, const char * const nick, const char * co
resource_presence_t presence = resource_presence_from_string(show);
muc_role_t role_t = _role_from_string(role);
muc_affiliation_t affiliation_t = _affiliation_from_string(affiliation);
Occupant *occupant = _muc_occupant_new(nick, role_t, affiliation_t, presence, status);
Occupant *occupant = _muc_occupant_new(nick, jid, role_t, affiliation_t, presence, status);
g_hash_table_replace(chat_room->roster, strdup(nick), occupant);
}
@ -831,7 +831,7 @@ _affiliation_to_string(muc_affiliation_t affiliation)
}
static Occupant*
_muc_occupant_new(const char *const nick, muc_role_t role, muc_affiliation_t affiliation, resource_presence_t presence,
_muc_occupant_new(const char *const nick, const char * const jid, muc_role_t role, muc_affiliation_t affiliation, resource_presence_t presence,
const char * const status)
{
Occupant *occupant = malloc(sizeof(Occupant));
@ -842,6 +842,12 @@ _muc_occupant_new(const char *const nick, muc_role_t role, muc_affiliation_t aff
occupant->nick = NULL;
}
if (jid) {
occupant->jid = strdup(jid);
} else {
occupant->jid = NULL;
}
occupant->presence = presence;
if (status) {
@ -861,6 +867,7 @@ _occupant_free(Occupant *occupant)
{
if (occupant) {
free(occupant->nick);
free(occupant->jid);
free(occupant->status);
free(occupant);
occupant = NULL;

View File

@ -58,6 +58,7 @@ typedef enum {
typedef struct _muc_occupant_t {
char *nick;
char *jid;
muc_role_t role;
muc_affiliation_t affiliation;
resource_presence_t presence;
@ -85,8 +86,8 @@ char* muc_old_nick(const char * const room, const char * const new_nick);
gboolean muc_roster_contains_nick(const char * const room, const char * const nick);
gboolean muc_roster_complete(const char * const room);
gboolean muc_roster_add(const char * const room, const char * const nick, const char * const role,
const char * const affiliation, const char * const show,
gboolean muc_roster_add(const char * const room, const char * const nick, const char * const jid,
const char * const role, const char * const affiliation, const char * const show,
const char * const status);
void muc_roster_remove(const char * const room, const char * const nick);
void muc_roster_set_complete(const char * const room);

View File

@ -527,10 +527,10 @@ handle_room_roster_complete(const char * const room)
}
void
handle_room_member_presence(const char * const room, const char * const nick, const char * const role,
const char * const affiliation, const char * const show, const char * const status)
handle_room_member_presence(const char * const room, const char * const nick, const char * const jid,
const char * const role, const char * const affiliation, const char * const show, const char * const status)
{
gboolean updated = muc_roster_add(room, nick, role, affiliation, show, status);
gboolean updated = muc_roster_add(room, nick, jid, role, affiliation, show, status);
if (updated) {
char *muc_status_pref = prefs_get_string(PREF_STATUSES_MUC);
@ -542,10 +542,10 @@ handle_room_member_presence(const char * const room, const char * const nick, co
}
void
handle_room_member_online(const char * const room, const char * const nick, const char * const role,
const char * const affiliation, const char * const show, const char * const status)
handle_room_member_online(const char * const room, const char * const nick, const char * const jid,
const char * const role, const char * const affiliation, const char * const show, const char * const status)
{
muc_roster_add(room, nick, role, affiliation, show, status);
muc_roster_add(room, nick, jid, role, affiliation, show, status);
char *muc_status_pref = prefs_get_string(PREF_STATUSES_MUC);
if (g_strcmp0(muc_status_pref, "none") != 0) {

View File

@ -73,10 +73,10 @@ void handle_room_nick_change(const char * const room,
void handle_room_requires_config(const char * const room);
void handle_room_destroy(const char * const room);
void handle_room_roster_complete(const char * const room);
void handle_room_member_presence(const char * const room, const char * const nick, const char * const role,
const char * const affiliation, const char * const show, const char * const status);
void handle_room_member_online(const char * const room, const char * const nick, const char * const role,
const char * const affiliation, const char * const show, const char * const status);
void handle_room_member_presence(const char * const room, const char * const nick, const char * const jid,
const char * const role, const char * const affiliation, const char * const show, const char * const status);
void handle_room_member_online(const char * const room, const char * const nick, const char * const jid,
const char * const role, const char * const affiliation, const char * const show, const char * const status);
void handle_room_member_offline(const char * const room, const char * const nick,
const char * const show, const char * const status);
void handle_room_member_nick_change(const char * const room,

View File

@ -1937,7 +1937,11 @@ _ui_show_room_role_list(ProfWin *window, const char * const room, muc_role_t rol
while(curr_occupant) {
Occupant *occupant = curr_occupant->data;
if (occupant->role == role) {
win_save_vprint(window, '!', NULL, 0, 0, "", " %s", occupant->nick);
if (occupant->jid) {
win_save_vprint(window, '!', NULL, 0, 0, "", " %s (%s)", occupant->nick, occupant->jid);
} else {
win_save_vprint(window, '!', NULL, 0, 0, "", " %s", occupant->nick);
}
}
curr_occupant = g_slist_next(curr_occupant);
@ -1992,7 +1996,11 @@ _ui_show_room_affiliation_list(ProfWin *window, const char * const room, muc_aff
while(curr_occupant) {
Occupant *occupant = curr_occupant->data;
if (occupant->affiliation == affiliation) {
win_save_vprint(window, '!', NULL, 0, 0, "", " %s", occupant->nick);
if (occupant->jid) {
win_save_vprint(window, '!', NULL, 0, 0, "", " %s (%s)", occupant->nick, occupant->jid);
} else {
win_save_vprint(window, '!', NULL, 0, 0, "", " %s", occupant->nick);
}
}
curr_occupant = g_slist_next(curr_occupant);

View File

@ -204,6 +204,10 @@ win_show_occupant_info(ProfWin *window, const char * const room, Occupant *occup
win_save_newline(window);
if (occupant->jid) {
win_save_vprint(window, '!', NULL, 0, 0, "", " Jid: %s", occupant->jid);
}
win_save_vprint(window, '!', NULL, 0, 0, "", " Affiliation: %s", occupant_affiliation);
win_save_vprint(window, '!', NULL, 0, 0, "", " Role: %s", occupant_role);

View File

@ -766,6 +766,7 @@ _muc_user_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
}
char *show_str = stanza_get_show(stanza, "online");
char *jid = NULL;
char *role = NULL;
char *affiliation = NULL;
@ -773,25 +774,26 @@ _muc_user_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
if (x) {
xmpp_stanza_t *item = xmpp_stanza_get_child_by_name(x, STANZA_NAME_ITEM);
if (item) {
jid = xmpp_stanza_get_attribute(item, "jid");
role = xmpp_stanza_get_attribute(item, "role");
affiliation = xmpp_stanza_get_attribute(item, "affiliation");
}
}
if (!muc_roster_complete(from_room)) {
muc_roster_add(from_room, from_nick, role, affiliation, show_str, status_str);
muc_roster_add(from_room, from_nick, jid, role, affiliation, show_str, status_str);
} else {
char *old_nick = muc_roster_nick_change_complete(from_room, from_nick);
if (old_nick != NULL) {
muc_roster_add(from_room, from_nick, role, affiliation, show_str, status_str);
muc_roster_add(from_room, from_nick, jid, role, affiliation, show_str, status_str);
handle_room_member_nick_change(from_room, old_nick, from_nick);
free(old_nick);
} else {
if (!muc_roster_contains_nick(from_room, from_nick)) {
handle_room_member_online(from_room, from_nick, role, affiliation, show_str, status_str);
handle_room_member_online(from_room, from_nick, jid, role, affiliation, show_str, status_str);
} else {
handle_room_member_presence(from_room, from_nick, role, affiliation, show_str, status_str);
handle_room_member_presence(from_room, from_nick, jid, role, affiliation, show_str, status_str);
}
}
}