1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-12-04 14:46:46 -05:00

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

@ -445,7 +445,7 @@ sv_ev_outgoing_carbon(ProfMessage *message)
chat_state_active(chatwin->state); chat_state_active(chatwin->state);
if (message->plain) { if (message->plain) {
if (message->mucuser) { if (message->type == PROF_MSG_TYPE_MUCPM) {
// MUC PM, should have resource (nick) in filename // MUC PM, should have resource (nick) in filename
chat_log_msg_out(message->jid->barejid, message->plain, message->jid->resourcepart); chat_log_msg_out(message->jid->barejid, message->plain, message->jid->resourcepart);
} else { } else {

View File

@ -356,13 +356,13 @@ chat_log_otr_msg_in(ProfMessage *message)
Jid *jidp = jid_create(jid); Jid *jidp = jid_create(jid);
char *pref_otr_log = prefs_get_string(PREF_OTR_LOG); char *pref_otr_log = prefs_get_string(PREF_OTR_LOG);
if (message->enc == PROF_MSG_ENC_NONE || (strcmp(pref_otr_log, "on") == 0)) { if (message->enc == PROF_MSG_ENC_NONE || (strcmp(pref_otr_log, "on") == 0)) {
if (message->mucuser) { if (message->type == PROF_MSG_TYPE_MUCPM) {
_chat_log_chat(jidp->barejid, message->jid->barejid, message->plain, PROF_IN_LOG, message->timestamp, message->jid->resourcepart); _chat_log_chat(jidp->barejid, message->jid->barejid, message->plain, PROF_IN_LOG, message->timestamp, message->jid->resourcepart);
} else { } else {
_chat_log_chat(jidp->barejid, message->jid->barejid, message->plain, PROF_IN_LOG, message->timestamp, NULL); _chat_log_chat(jidp->barejid, message->jid->barejid, message->plain, PROF_IN_LOG, message->timestamp, NULL);
} }
} else if (strcmp(pref_otr_log, "redact") == 0) { } else if (strcmp(pref_otr_log, "redact") == 0) {
if (message->mucuser) { if (message->type == PROF_MSG_TYPE_MUCPM) {
_chat_log_chat(jidp->barejid, message->jid->barejid, "[redacted]", PROF_IN_LOG, message->timestamp, message->jid->resourcepart); _chat_log_chat(jidp->barejid, message->jid->barejid, "[redacted]", PROF_IN_LOG, message->timestamp, message->jid->resourcepart);
} else { } else {
_chat_log_chat(jidp->barejid, message->jid->barejid, "[redacted]", PROF_IN_LOG, message->timestamp, NULL); _chat_log_chat(jidp->barejid, message->jid->barejid, "[redacted]", PROF_IN_LOG, message->timestamp, NULL);
@ -381,13 +381,13 @@ chat_log_pgp_msg_in(ProfMessage *message)
Jid *jidp = jid_create(jid); Jid *jidp = jid_create(jid);
char *pref_pgp_log = prefs_get_string(PREF_PGP_LOG); char *pref_pgp_log = prefs_get_string(PREF_PGP_LOG);
if (strcmp(pref_pgp_log, "on") == 0) { if (strcmp(pref_pgp_log, "on") == 0) {
if (message->mucuser) { if (message->type == PROF_MSG_TYPE_MUCPM) {
_chat_log_chat(jidp->barejid, message->jid->barejid, message->plain, PROF_IN_LOG, message->timestamp, message->jid->resourcepart); _chat_log_chat(jidp->barejid, message->jid->barejid, message->plain, PROF_IN_LOG, message->timestamp, message->jid->resourcepart);
} else { } else {
_chat_log_chat(jidp->barejid, message->jid->barejid, message->plain, PROF_IN_LOG, message->timestamp, NULL); _chat_log_chat(jidp->barejid, message->jid->barejid, message->plain, PROF_IN_LOG, message->timestamp, NULL);
} }
} else if (strcmp(pref_pgp_log, "redact") == 0) { } else if (strcmp(pref_pgp_log, "redact") == 0) {
if (message->mucuser) { if (message->type == PROF_MSG_TYPE_MUCPM) {
_chat_log_chat(jidp->barejid, message->jid->barejid, "[redacted]", PROF_IN_LOG, message->timestamp, message->jid->resourcepart); _chat_log_chat(jidp->barejid, message->jid->barejid, "[redacted]", PROF_IN_LOG, message->timestamp, message->jid->resourcepart);
} else { } else {
_chat_log_chat(jidp->barejid, message->jid->barejid, "[redacted]", PROF_IN_LOG, message->timestamp, NULL); _chat_log_chat(jidp->barejid, message->jid->barejid, "[redacted]", PROF_IN_LOG, message->timestamp, NULL);
@ -406,13 +406,13 @@ chat_log_omemo_msg_in(ProfMessage *message)
Jid *jidp = jid_create(jid); Jid *jidp = jid_create(jid);
char *pref_omemo_log = prefs_get_string(PREF_OMEMO_LOG); char *pref_omemo_log = prefs_get_string(PREF_OMEMO_LOG);
if (strcmp(pref_omemo_log, "on") == 0) { if (strcmp(pref_omemo_log, "on") == 0) {
if (message->mucuser) { if (message->type == PROF_MSG_TYPE_MUCPM) {
_chat_log_chat(jidp->barejid, message->jid->barejid, message->plain, PROF_IN_LOG, message->timestamp, message->jid->resourcepart); _chat_log_chat(jidp->barejid, message->jid->barejid, message->plain, PROF_IN_LOG, message->timestamp, message->jid->resourcepart);
} else { } else {
_chat_log_chat(jidp->barejid, message->jid->barejid, message->plain, PROF_IN_LOG, message->timestamp, NULL); _chat_log_chat(jidp->barejid, message->jid->barejid, message->plain, PROF_IN_LOG, message->timestamp, NULL);
} }
} else if (strcmp(pref_omemo_log, "redact") == 0) { } else if (strcmp(pref_omemo_log, "redact") == 0) {
if (message->mucuser) { if (message->type == PROF_MSG_TYPE_MUCPM) {
_chat_log_chat(jidp->barejid, message->jid->barejid, "[redacted]", PROF_IN_LOG, message->timestamp, message->jid->resourcepart); _chat_log_chat(jidp->barejid, message->jid->barejid, "[redacted]", PROF_IN_LOG, message->timestamp, message->jid->resourcepart);
} else { } else {
_chat_log_chat(jidp->barejid, message->jid->barejid, "[redacted]", PROF_IN_LOG, message->timestamp, message->jid->resourcepart); _chat_log_chat(jidp->barejid, message->jid->barejid, "[redacted]", PROF_IN_LOG, message->timestamp, message->jid->resourcepart);
@ -430,7 +430,7 @@ chat_log_msg_in(ProfMessage *message)
const char *jid = connection_get_fulljid(); const char *jid = connection_get_fulljid();
Jid *jidp = jid_create(jid); Jid *jidp = jid_create(jid);
if (message->mucuser) { if (message->type == PROF_MSG_TYPE_MUCPM) {
_chat_log_chat(jidp->barejid, message->jid->barejid, message->plain, PROF_IN_LOG, message->timestamp, message->jid->resourcepart); _chat_log_chat(jidp->barejid, message->jid->barejid, message->plain, PROF_IN_LOG, message->timestamp, message->jid->resourcepart);
} else { } else {
_chat_log_chat(jidp->barejid, message->jid->barejid, message->plain, PROF_IN_LOG, message->timestamp, NULL); _chat_log_chat(jidp->barejid, message->jid->barejid, message->plain, PROF_IN_LOG, message->timestamp, NULL);

View File

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

View File

@ -126,7 +126,16 @@ typedef enum {
PROF_MSG_ENC_OMEMO PROF_MSG_ENC_OMEMO
} prof_enc_t; } 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 { typedef struct prof_message_t {
Jid *jid; Jid *jid;
char *id; char *id;
@ -143,7 +152,7 @@ typedef struct prof_message_t {
GDateTime *timestamp; GDateTime *timestamp;
prof_enc_t enc; prof_enc_t enc;
gboolean trusted; gboolean trusted;
gboolean mucuser; prof_msg_type_t type;
} ProfMessage; } ProfMessage;
void session_init(void); void session_init(void);