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

Retrieve message type from database

So we don't have to check for MUC another way.
This commit is contained in:
Michael Vetter 2020-04-08 12:50:23 +02:00
parent 444ce95aae
commit f42f856d37
5 changed files with 21 additions and 7 deletions

View File

@ -50,6 +50,7 @@ static sqlite3 *g_chatlog_database;
static void _add_to_db(ProfMessage *message, char *type, const Jid * const from_jid, const Jid * const to_jid);
static char* _get_db_filename(ProfAccount *account);
static prof_msg_type_t _get_message_type_type(const char *const type);
static char*
_get_db_filename(ProfAccount *account)
@ -215,7 +216,7 @@ log_database_get_previous_chat(const gchar *const contact_barejid)
sqlite3_stmt *stmt = NULL;
char *query;
if (asprintf(&query, "SELECT * FROM (SELECT `message`, `timestamp`, `from_jid` from `ChatLogs` WHERE `from_jid` = '%s' OR `to_jid` = '%s' ORDER BY `timestamp` DESC LIMIT 10) ORDER BY `timestamp` ASC;", contact_barejid, contact_barejid) == -1) {
if (asprintf(&query, "SELECT * FROM (SELECT `message`, `timestamp`, `from_jid`, `type` from `ChatLogs` WHERE `from_jid` = '%s' OR `to_jid` = '%s' ORDER BY `timestamp` DESC LIMIT 10) ORDER BY `timestamp` ASC;", contact_barejid, contact_barejid) == -1) {
log_error("log_database_get_previous_chat(): SQL query. could not allocate memory");
return NULL;
}
@ -232,11 +233,13 @@ log_database_get_previous_chat(const gchar *const contact_barejid)
char *message = (char*)sqlite3_column_text(stmt, 0);
char *date = (char*)sqlite3_column_text(stmt, 1);
char *from = (char*)sqlite3_column_text(stmt, 2);
char *type = (char*)sqlite3_column_text(stmt, 3);
ProfMessage *msg = message_init();
msg->jid = jid_create(from);
msg->plain = strdup(message);
msg->timestamp = g_date_time_new_from_iso8601(date, NULL);
msg->type = _get_message_type_type(type);
// TODO: later we can get more fields like 'enc'. then we can display the history like regular chats with all info the user enabled.
history = g_slist_append(history, msg);
@ -261,6 +264,18 @@ static const char* _get_message_type_str(prof_msg_type_t type) {
return NULL;
}
static prof_msg_type_t _get_message_type_type(const char *const type) {
if (g_strcmp0(type, "chat") == 0) {
return PROF_MSG_TYPE_CHAT;
} else if (g_strcmp0(type, "muc") == 0) {
return PROF_MSG_TYPE_MUC;
} else if (g_strcmp0(type, "mucpm") == 0) {
return PROF_MSG_TYPE_MUCPM;
} else {
return PROF_MSG_TYPE_UNINITIALIZED;
}
}
static const char* _get_message_enc_str(prof_enc_t enc) {
switch (enc) {
case PROF_MSG_ENC_PGP:

View File

@ -486,7 +486,7 @@ _chatwin_history(ProfChatWin *chatwin, const char *const contact_barejid)
while (curr) {
ProfMessage *msg = curr->data;
win_print_history((ProfWin*)chatwin, msg, FALSE);
win_print_history((ProfWin*)chatwin, msg);
curr = g_slist_next(curr);
}
chatwin->history_shown = TRUE;

View File

@ -373,7 +373,7 @@ mucwin_history(ProfMucWin *mucwin, const ProfMessage *const message)
char *muc_history_color = prefs_get_string(PREF_HISTORY_COLOR_MUC);
if (g_strcmp0(muc_history_color, "unanimous") == 0) {
win_print_history(window, message, TRUE);
win_print_history(window, message);
} else {
char *mynick = muc_nick(mucwin->roomjid);
GSList *mentions = get_mentions(prefs_get_boolean(PREF_NOTIFY_MENTION_WHOLE_WORD), prefs_get_boolean(PREF_NOTIFY_MENTION_CASE_SENSITIVE), message->plain, mynick);

View File

@ -1218,15 +1218,14 @@ win_print_outgoing(ProfWin *window, const char *show_char, const char *const id,
}
void
win_print_history(ProfWin *window, const ProfMessage *const message, gboolean is_muc)
win_print_history(ProfWin *window, const ProfMessage *const message)
{
g_date_time_ref(message->timestamp);
int flags = 0;
// TODO: ProfMessage needs a 'type' field like we have in sql db. then we can know whether each message is a chat, muc, mucpm
char *display_name;
if (is_muc) {
if (message->type == PROF_MSG_TYPE_MUC) {
display_name = strdup(message->jid->resourcepart);
char *muc_history_color = prefs_get_string(PREF_HISTORY_COLOR_MUC);

View File

@ -68,7 +68,7 @@ void win_print_outgoing(ProfWin *window, const char *show_char, const char *cons
void win_print_outgoing_with_receipt(ProfWin *window, const char *show_char, const char *const from, const char *const message, char *id, const char *const replace_id);
void win_println_incoming_muc_msg(ProfWin *window, char *show_char, int flags, const ProfMessage *const message);
void win_print_outgoing_muc_msg(ProfWin *window, char *show_char, const char *const me, const char *const id, const char *const replace_id, const char *const message);
void win_print_history(ProfWin *window, const ProfMessage *const message, gboolean is_muc);
void win_print_history(ProfWin *window, const ProfMessage *const message);
void win_print_http_upload(ProfWin *window, const char *const message, char *url);