mirror of
https://github.com/profanity-im/profanity.git
synced 2025-02-02 15:08:15 -05:00
Added check members only room to send mediated invites
This commit is contained in:
parent
f1f047889e
commit
fac2b2cf66
14
src/muc.c
14
src/muc.c
@ -62,6 +62,7 @@ typedef struct _muc_room_t {
|
|||||||
Autocomplete jid_ac;
|
Autocomplete jid_ac;
|
||||||
GHashTable *nick_changes;
|
GHashTable *nick_changes;
|
||||||
gboolean roster_received;
|
gboolean roster_received;
|
||||||
|
muc_member_type_t member_type;
|
||||||
} ChatRoom;
|
} ChatRoom;
|
||||||
|
|
||||||
GHashTable *rooms = NULL;
|
GHashTable *rooms = NULL;
|
||||||
@ -177,6 +178,7 @@ muc_join(const char * const room, const char * const nick,
|
|||||||
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;
|
||||||
|
new_room->member_type = MUC_MEMBER_TYPE_UNKNOWN;
|
||||||
|
|
||||||
g_hash_table_insert(rooms, strdup(room), new_room);
|
g_hash_table_insert(rooms, strdup(room), new_room);
|
||||||
}
|
}
|
||||||
@ -763,6 +765,18 @@ muc_set_affiliation(const char * const room, const char * const affiliation)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
muc_member_type_t
|
||||||
|
muc_member_type(const char * const room)
|
||||||
|
{
|
||||||
|
ChatRoom *chat_room = g_hash_table_lookup(rooms, room);
|
||||||
|
if (chat_room) {
|
||||||
|
return chat_room->member_type;
|
||||||
|
} else {
|
||||||
|
return MUC_MEMBER_TYPE_UNKNOWN;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
_free_room(ChatRoom *room)
|
_free_room(ChatRoom *room)
|
||||||
{
|
{
|
||||||
|
@ -56,6 +56,12 @@ typedef enum {
|
|||||||
MUC_AFFILIATION_OWNER
|
MUC_AFFILIATION_OWNER
|
||||||
} muc_affiliation_t;
|
} muc_affiliation_t;
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
MUC_MEMBER_TYPE_UNKNOWN,
|
||||||
|
MUC_MEMBER_TYPE_PUBLIC,
|
||||||
|
MUC_MEMBER_TYPE_MEMBERS_ONLY
|
||||||
|
} muc_member_type_t;
|
||||||
|
|
||||||
typedef struct _muc_occupant_t {
|
typedef struct _muc_occupant_t {
|
||||||
char *nick;
|
char *nick;
|
||||||
char *jid;
|
char *jid;
|
||||||
@ -134,4 +140,6 @@ void muc_set_affiliation(const char * const room, const char * const affiliation
|
|||||||
char *muc_role_str(const char * const room);
|
char *muc_role_str(const char * const room);
|
||||||
char *muc_affiliation_str(const char * const room);
|
char *muc_affiliation_str(const char * const room);
|
||||||
|
|
||||||
|
muc_member_type_t muc_member_type(const char * const room);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -697,6 +697,9 @@ handle_muc_self_online(const char * const room, const char * const nick, gboolea
|
|||||||
} else {
|
} else {
|
||||||
ui_room_join(room, TRUE);
|
ui_room_join(room, TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO send disco info request to room
|
||||||
|
|
||||||
muc_invites_remove(room);
|
muc_invites_remove(room);
|
||||||
muc_roster_set_complete(room);
|
muc_roster_set_complete(room);
|
||||||
|
|
||||||
|
@ -204,7 +204,16 @@ message_send_invite(const char * const roomjid, const char * const contact,
|
|||||||
{
|
{
|
||||||
xmpp_conn_t * const conn = connection_get_conn();
|
xmpp_conn_t * const conn = connection_get_conn();
|
||||||
xmpp_ctx_t * const ctx = connection_get_ctx();
|
xmpp_ctx_t * const ctx = connection_get_ctx();
|
||||||
xmpp_stanza_t *stanza = stanza_create_invite(ctx, roomjid, contact, reason);
|
xmpp_stanza_t *stanza;
|
||||||
|
|
||||||
|
muc_member_type_t member_type = muc_member_type(roomjid);
|
||||||
|
if (member_type == MUC_MEMBER_TYPE_PUBLIC) {
|
||||||
|
log_debug("Sending direct invite to %s, for %s", contact, roomjid);
|
||||||
|
stanza = stanza_create_invite(ctx, roomjid, contact, reason);
|
||||||
|
} else {
|
||||||
|
log_debug("Sending mediated invite to %s, for %s", contact, roomjid);
|
||||||
|
stanza = stanza_create_mediated_invite(ctx, roomjid, contact, reason);
|
||||||
|
}
|
||||||
|
|
||||||
xmpp_send(conn, stanza);
|
xmpp_send(conn, stanza);
|
||||||
xmpp_stanza_release(stanza);
|
xmpp_stanza_release(stanza);
|
||||||
|
@ -440,6 +440,46 @@ stanza_create_invite(xmpp_ctx_t *ctx, const char * const room,
|
|||||||
return message;
|
return message;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
xmpp_stanza_t *
|
||||||
|
stanza_create_mediated_invite(xmpp_ctx_t *ctx, const char * const room,
|
||||||
|
const char * const contact, const char * const reason)
|
||||||
|
{
|
||||||
|
xmpp_stanza_t *message, *x, *invite;
|
||||||
|
|
||||||
|
message = xmpp_stanza_new(ctx);
|
||||||
|
xmpp_stanza_set_name(message, STANZA_NAME_MESSAGE);
|
||||||
|
xmpp_stanza_set_attribute(message, STANZA_ATTR_TO, room);
|
||||||
|
char *id = create_unique_id(NULL);
|
||||||
|
xmpp_stanza_set_id(message, id);
|
||||||
|
free(id);
|
||||||
|
|
||||||
|
x = xmpp_stanza_new(ctx);
|
||||||
|
xmpp_stanza_set_name(x, STANZA_NAME_X);
|
||||||
|
xmpp_stanza_set_ns(x, STANZA_NS_MUC_USER);
|
||||||
|
|
||||||
|
invite = xmpp_stanza_new(ctx);
|
||||||
|
xmpp_stanza_set_name(invite, STANZA_NAME_INVITE);
|
||||||
|
xmpp_stanza_set_attribute(invite, STANZA_ATTR_TO, contact);
|
||||||
|
|
||||||
|
if (reason != NULL) {
|
||||||
|
xmpp_stanza_t *reason_st = xmpp_stanza_new(ctx);
|
||||||
|
xmpp_stanza_set_name(reason_st, STANZA_NAME_REASON);
|
||||||
|
xmpp_stanza_t *reason_txt = xmpp_stanza_new(ctx);
|
||||||
|
xmpp_stanza_set_text(reason_txt, reason);
|
||||||
|
xmpp_stanza_add_child(reason_st, reason_txt);
|
||||||
|
xmpp_stanza_release(reason_txt);
|
||||||
|
xmpp_stanza_add_child(invite, reason_st);
|
||||||
|
xmpp_stanza_release(reason_st);
|
||||||
|
}
|
||||||
|
|
||||||
|
xmpp_stanza_add_child(x, invite);
|
||||||
|
xmpp_stanza_release(invite);
|
||||||
|
xmpp_stanza_add_child(message, x);
|
||||||
|
xmpp_stanza_release(x);
|
||||||
|
|
||||||
|
return message;
|
||||||
|
}
|
||||||
|
|
||||||
xmpp_stanza_t *
|
xmpp_stanza_t *
|
||||||
stanza_create_room_join_presence(xmpp_ctx_t * const ctx,
|
stanza_create_room_join_presence(xmpp_ctx_t * const ctx,
|
||||||
const char * const full_room_jid, const char * const passwd)
|
const char * const full_room_jid, const char * const passwd)
|
||||||
|
@ -215,6 +215,8 @@ xmpp_stanza_t* stanza_create_disco_info_iq(xmpp_ctx_t *ctx, const char * const i
|
|||||||
|
|
||||||
xmpp_stanza_t* stanza_create_invite(xmpp_ctx_t *ctx, const char * const room,
|
xmpp_stanza_t* stanza_create_invite(xmpp_ctx_t *ctx, const char * const room,
|
||||||
const char * const contact, const char * const reason);
|
const char * const contact, const char * const reason);
|
||||||
|
xmpp_stanza_t* stanza_create_mediated_invite(xmpp_ctx_t *ctx, const char * const room,
|
||||||
|
const char * const contact, const char * const reason);
|
||||||
|
|
||||||
gboolean stanza_contains_chat_state(xmpp_stanza_t *stanza);
|
gboolean stanza_contains_chat_state(xmpp_stanza_t *stanza);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user