Add type field to ProfMessage

The mucuser boolean is not now needed anymore.
This commit is contained in:
Michael Vetter
2020-04-06 18:37:39 +02:00
parent 5862e5b159
commit 3524a53c7c
4 changed files with 27 additions and 14 deletions

View File

@@ -110,6 +110,7 @@ _message_handler(xmpp_conn_t *const conn, xmpp_stanza_t *const stanza, void *con
_handle_error(stanza);
}
// if muc
if (g_strcmp0(type, STANZA_TYPE_GROUPCHAT) == 0) {
_handle_groupchat(stanza);
}
@@ -195,7 +196,7 @@ message_init(void)
message->enc = PROF_MSG_ENC_NONE;
message->timestamp = NULL;
message->trusted = true;
message->mucuser = false;
message->type = PROF_MSG_TYPE_UNINITIALIZED;
return message;
}
@@ -831,6 +832,7 @@ _handle_groupchat(xmpp_stanza_t *const stanza)
ProfMessage *message = message_init();
message->jid = jid;
message->type = PROF_MSG_TYPE_MUC;
if (id) {
message->id = strdup(id);
@@ -977,7 +979,7 @@ _handle_muc_private_message(xmpp_stanza_t *const stanza)
{
// standard chat message, use jid without resource
ProfMessage *message = message_init();
message->mucuser = TRUE;
message->type = PROF_MSG_TYPE_MUCPM;
const gchar *from = xmpp_stanza_get_from(stanza);
message->jid = jid_create(from);
@@ -1062,11 +1064,12 @@ _handle_carbons(xmpp_stanza_t *const stanza)
}
ProfMessage *message = message_init();
message->type = PROF_MSG_TYPE_CHAT;
// check whether message was a MUC PM
xmpp_stanza_t *mucuser = xmpp_stanza_get_child_by_ns(message_stanza, STANZA_NS_MUC_USER);
if (mucuser) {
message->mucuser = TRUE;
message->type = PROF_MSG_TYPE_MUCPM;
}
// id
@@ -1181,6 +1184,7 @@ _handle_chat(xmpp_stanza_t *const stanza)
// standard chat message, use jid without resource
ProfMessage *message = message_init();
message->jid = jid;
message->type = PROF_MSG_TYPE_CHAT;
// message stanza id
const char *id = xmpp_stanza_get_id(stanza);
@@ -1197,7 +1201,7 @@ _handle_chat(xmpp_stanza_t *const stanza)
}
if (mucuser) {
message->mucuser = TRUE;
message->type = PROF_MSG_TYPE_MUCPM;
}
message->timestamp = stanza_get_delay(stanza);

View File

@@ -126,7 +126,16 @@ typedef enum {
PROF_MSG_ENC_OMEMO
} prof_enc_t;
// TODO: ProfMessage needs a 'type' field like we have in sql db. then we can know whether each message is a chat, muc, mucpm
typedef enum {
PROF_MSG_TYPE_UNINITIALIZED,
// regular 1:1 chat
PROF_MSG_TYPE_CHAT,
// groupchats to whole group
PROF_MSG_TYPE_MUC,
// groupchat private message
PROF_MSG_TYPE_MUCPM
} prof_msg_type_t;
typedef struct prof_message_t {
Jid *jid;
char *id;
@@ -143,7 +152,7 @@ typedef struct prof_message_t {
GDateTime *timestamp;
prof_enc_t enc;
gboolean trusted;
gboolean mucuser;
prof_msg_type_t type;
} ProfMessage;
void session_init(void);