mirror of
https://git.jabber.space/devs/cproof.git
synced 2026-07-31 23:06:21 +00:00
wip - Store roles and affiliations with occupants
This commit is contained in:
18
src/muc.c
18
src/muc.c
@@ -71,7 +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 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 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 void _occupant_free(Occupant *occupant);
|
static void _occupant_free(Occupant *occupant);
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -382,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
|
* Add a new chat room member to the room's roster
|
||||||
*/
|
*/
|
||||||
gboolean
|
gboolean
|
||||||
muc_roster_add(const char * const room, const char * const nick,
|
muc_roster_add(const char * const room, const char * const nick, const char * const role,
|
||||||
const char * const show, const char * const status)
|
const char * const affiliation, const char * const show, const char * const status)
|
||||||
{
|
{
|
||||||
ChatRoom *chat_room = g_hash_table_lookup(rooms, room);
|
ChatRoom *chat_room = g_hash_table_lookup(rooms, room);
|
||||||
gboolean updated = FALSE;
|
gboolean updated = FALSE;
|
||||||
@@ -401,7 +402,9 @@ muc_roster_add(const char * const room, const char * const nick,
|
|||||||
}
|
}
|
||||||
|
|
||||||
resource_presence_t presence = resource_presence_from_string(show);
|
resource_presence_t presence = resource_presence_from_string(show);
|
||||||
Occupant *occupant = _muc_occupant_new(nick, presence, status);
|
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);
|
||||||
g_hash_table_replace(chat_room->roster, strdup(nick), occupant);
|
g_hash_table_replace(chat_room->roster, strdup(nick), occupant);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -770,7 +773,8 @@ _affiliation_to_string(muc_affiliation_t affiliation)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static Occupant*
|
static Occupant*
|
||||||
_muc_occupant_new(const char *const nick, resource_presence_t presence, const char * const status)
|
_muc_occupant_new(const char *const nick, muc_role_t role, muc_affiliation_t affiliation, resource_presence_t presence,
|
||||||
|
const char * const status)
|
||||||
{
|
{
|
||||||
Occupant *occupant = malloc(sizeof(Occupant));
|
Occupant *occupant = malloc(sizeof(Occupant));
|
||||||
|
|
||||||
@@ -788,8 +792,8 @@ _muc_occupant_new(const char *const nick, resource_presence_t presence, const ch
|
|||||||
occupant->status = NULL;
|
occupant->status = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
occupant->role = MUC_ROLE_NONE;
|
occupant->role = role;
|
||||||
occupant->affiliation = MUC_AFFILIATION_NONE;
|
occupant->affiliation = affiliation;
|
||||||
|
|
||||||
return occupant;
|
return occupant;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -85,7 +85,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_contains_nick(const char * const room, const char * const nick);
|
||||||
gboolean muc_roster_complete(const char * const room);
|
gboolean muc_roster_complete(const char * const room);
|
||||||
gboolean muc_roster_add(const char * const room, const char * const nick, const char * const show,
|
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);
|
const char * const status);
|
||||||
void muc_roster_remove(const char * const room, const char * const nick);
|
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);
|
||||||
|
|||||||
@@ -527,11 +527,10 @@ handle_room_roster_complete(const char * const room)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
handle_room_member_presence(const char * const room,
|
handle_room_member_presence(const char * const room, const char * const nick, const char * const role,
|
||||||
const char * const nick, const char * const show,
|
const char * const affiliation, const char * const show, const char * const status)
|
||||||
const char * const status)
|
|
||||||
{
|
{
|
||||||
gboolean updated = muc_roster_add(room, nick, show, status);
|
gboolean updated = muc_roster_add(room, nick, role, affiliation, show, status);
|
||||||
|
|
||||||
if (updated) {
|
if (updated) {
|
||||||
char *muc_status_pref = prefs_get_string(PREF_STATUSES_MUC);
|
char *muc_status_pref = prefs_get_string(PREF_STATUSES_MUC);
|
||||||
@@ -543,10 +542,10 @@ handle_room_member_presence(const char * const room,
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
handle_room_member_online(const char * const room, const char * const nick,
|
handle_room_member_online(const char * const room, const char * const nick, const char * const role,
|
||||||
const char * const show, const char * const status)
|
const char * const affiliation, const char * const show, const char * const status)
|
||||||
{
|
{
|
||||||
muc_roster_add(room, nick, show, status);
|
muc_roster_add(room, nick, role, affiliation, show, status);
|
||||||
|
|
||||||
char *muc_status_pref = prefs_get_string(PREF_STATUSES_MUC);
|
char *muc_status_pref = prefs_get_string(PREF_STATUSES_MUC);
|
||||||
if (g_strcmp0(muc_status_pref, "none") != 0) {
|
if (g_strcmp0(muc_status_pref, "none") != 0) {
|
||||||
|
|||||||
@@ -73,11 +73,10 @@ void handle_room_nick_change(const char * const room,
|
|||||||
void handle_room_requires_config(const char * const room);
|
void handle_room_requires_config(const char * const room);
|
||||||
void handle_room_destroy(const char * const room);
|
void handle_room_destroy(const char * const room);
|
||||||
void handle_room_roster_complete(const char * const room);
|
void handle_room_roster_complete(const char * const room);
|
||||||
void handle_room_member_presence(const char * const room,
|
void handle_room_member_presence(const char * const room, const char * const nick, const char * const role,
|
||||||
const char * const nick, const char * const show,
|
const char * const affiliation, const char * const show, const char * const status);
|
||||||
const char * const status);
|
void handle_room_member_online(const char * const room, const char * const nick, const char * const role,
|
||||||
void handle_room_member_online(const char * const room, const char * const nick,
|
const char * const affiliation, const char * const show, const char * const status);
|
||||||
const char * const show, const char * const status);
|
|
||||||
void handle_room_member_offline(const char * const room, const char * const nick,
|
void handle_room_member_offline(const char * const room, const char * const nick,
|
||||||
const char * const show, const char * const status);
|
const char * const show, const char * const status);
|
||||||
void handle_room_member_nick_change(const char * const room,
|
void handle_room_member_nick_change(const char * const room,
|
||||||
|
|||||||
@@ -202,6 +202,8 @@ win_show_occupant_info(ProfWin *window, const char * const room, Occupant *occup
|
|||||||
|
|
||||||
win_save_newline(window);
|
win_save_newline(window);
|
||||||
|
|
||||||
|
win_save_vprint(window, '-', NULL, NO_DATE, 0, "", "Role: %s, Affiliation: %s", occupant->role, occupant->affiliation);
|
||||||
|
|
||||||
Jid *jidp = jid_create_from_bare_and_resource(room, occupant->nick);
|
Jid *jidp = jid_create_from_bare_and_resource(room, occupant->nick);
|
||||||
Capabilities *caps = caps_lookup(jidp->fulljid);
|
Capabilities *caps = caps_lookup(jidp->fulljid);
|
||||||
|
|
||||||
|
|||||||
@@ -766,20 +766,32 @@ _muc_user_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
|
|||||||
}
|
}
|
||||||
|
|
||||||
char *show_str = stanza_get_show(stanza, "online");
|
char *show_str = stanza_get_show(stanza, "online");
|
||||||
|
char *role = NULL;
|
||||||
|
char *affiliation = NULL;
|
||||||
|
|
||||||
|
xmpp_stanza_t *x = xmpp_stanza_get_child_by_ns(stanza, STANZA_NS_MUC_USER);
|
||||||
|
if (x) {
|
||||||
|
xmpp_stanza_t *item = xmpp_stanza_get_child_by_name(x, STANZA_NAME_ITEM);
|
||||||
|
if (item) {
|
||||||
|
role = xmpp_stanza_get_attribute(item, "role");
|
||||||
|
affiliation = xmpp_stanza_get_attribute(item, "affiliation");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!muc_roster_complete(from_room)) {
|
if (!muc_roster_complete(from_room)) {
|
||||||
muc_roster_add(from_room, from_nick, show_str, status_str);
|
muc_roster_add(from_room, from_nick, role, affiliation, show_str, status_str);
|
||||||
} else {
|
} else {
|
||||||
char *old_nick = muc_roster_nick_change_complete(from_room, from_nick);
|
char *old_nick = muc_roster_nick_change_complete(from_room, from_nick);
|
||||||
|
|
||||||
if (old_nick != NULL) {
|
if (old_nick != NULL) {
|
||||||
muc_roster_add(from_room, from_nick, show_str, status_str);
|
muc_roster_add(from_room, from_nick, role, affiliation, show_str, status_str);
|
||||||
handle_room_member_nick_change(from_room, old_nick, from_nick);
|
handle_room_member_nick_change(from_room, old_nick, from_nick);
|
||||||
free(old_nick);
|
free(old_nick);
|
||||||
} else {
|
} else {
|
||||||
if (!muc_roster_contains_nick(from_room, from_nick)) {
|
if (!muc_roster_contains_nick(from_room, from_nick)) {
|
||||||
handle_room_member_online(from_room, from_nick, show_str, status_str);
|
handle_room_member_online(from_room, from_nick, role, affiliation, show_str, status_str);
|
||||||
} else {
|
} else {
|
||||||
handle_room_member_presence(from_room, from_nick, show_str, status_str);
|
handle_room_member_presence(from_room, from_nick, role, affiliation, show_str, status_str);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user