1
0
Fork 0

Parse mentions and triggers in muc history if display is 'regular'

Fix https://github.com/profanity-im/profanity/issues/1261
This commit is contained in:
Michael Vetter 2020-02-20 10:17:17 +01:00
parent 1ddac7b9c6
commit 8ee2cdadc8
6 changed files with 33 additions and 25 deletions

View File

@ -366,34 +366,41 @@ mucwin_history(ProfMucWin *mucwin, const ProfMessage *const message)
assert(mucwin != NULL);
ProfWin *window = (ProfWin*)mucwin;
GString *line = g_string_new("");
char *nick = message->jid->resourcepart;
if (strncmp(message->plain, "/me ", 4) == 0) {
g_string_append(line, "*");
g_string_append(line, nick);
g_string_append(line, " ");
g_string_append(line, message->plain + 4);
} else {
g_string_append(line, nick);
g_string_append(line, ": ");
g_string_append(line, message->plain);
}
// 'unanimous' all in one color (like always was)
// 'regular' colored like new messages too
char *muc_history_color = prefs_get_string(PREF_HISTORY_COLOR_MUC);
if (g_strcmp0(muc_history_color, "unanimous") == 0) {
GString *line = g_string_new("");
if (strncmp(message->plain, "/me ", 4) == 0) {
g_string_append(line, "*");
g_string_append(line, nick);
g_string_append(line, " ");
g_string_append(line, message->plain + 4);
} else {
g_string_append(line, nick);
g_string_append(line, ": ");
g_string_append(line, message->plain);
}
win_print_history(window, message->timestamp, line->str);
g_string_free(line, TRUE);
} else {
// TODO: actually should call mucwin_incoming_msg() so that mentions and triggers are highlighted too.
// so should put code from sv_ev_room_message() in own function. so that we get the triggers etc.
win_println_incoming_muc_msg(window, '-', 0, message->jid->resourcepart, message->id, message->replace_id, message->plain);
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);
GList *triggers = prefs_message_get_triggers(message->plain);
mucwin_incoming_msg(mucwin, message, mentions, triggers);
g_slist_free(mentions);
g_list_free_full(triggers, free);
}
g_free(muc_history_color);
g_string_free(line, TRUE);
plugins_on_room_history_message(mucwin->roomjid, nick, message->plain, message->timestamp);
}
@ -542,7 +549,7 @@ mucwin_outgoing_msg(ProfMucWin *mucwin, const char *const message, const char *c
}
void
mucwin_incoming_msg(ProfMucWin *mucwin, ProfMessage *message, GSList *mentions, GList *triggers)
mucwin_incoming_msg(ProfMucWin *mucwin, const ProfMessage *const message, GSList *mentions, GList *triggers)
{
assert(mucwin != NULL);
int flags = 0;

View File

@ -3,6 +3,7 @@
* vim: expandtab:ts=4:sts=4:sw=4
*
* Copyright (C) 2012 - 2019 James Booth <boothj5@gmail.com>
* Copyright (C) 2019 - 2020 Michael Vetter <jubalh@iodoru.org>
*
* This file is part of Profanity.
*
@ -158,7 +159,7 @@ void mucwin_occupant_role_and_affiliation_change(ProfMucWin *mucwin, const char
void mucwin_roster(ProfMucWin *mucwin, GList *occupants, const char *const presence);
void mucwin_history(ProfMucWin *mucwin, const ProfMessage *const message);
void mucwin_outgoing_msg(ProfMucWin *mucwin, const char *const message, const char *const id, prof_enc_t enc_mode, const char *const replace_id);
void mucwin_incoming_msg(ProfMucWin *mucwin, ProfMessage *message, GSList *mentions, GList *triggers);
void mucwin_incoming_msg(ProfMucWin *mucwin, const ProfMessage *const message, GSList *mentions, GList *triggers);
void mucwin_subject(ProfMucWin *mucwin, const char *const nick, const char *const subject);
void mucwin_requires_config(ProfMucWin *mucwin);
void mucwin_info(ProfMucWin *mucwin);

View File

@ -1256,7 +1256,7 @@ _send_message_stanza(xmpp_stanza_t *const stanza)
* checkOID = false: check regular id
*/
bool
message_is_sent_by_us(ProfMessage *message, bool checkOID) {
message_is_sent_by_us(const ProfMessage *const message, bool checkOID) {
bool ret = FALSE;
// we check the </origin-id> for this we calculate a hash into it so we can detect

View File

@ -184,7 +184,7 @@ void message_send_paused(const char *const jid);
void message_send_gone(const char *const jid);
void message_send_invite(const char *const room, const char *const contact, const char *const reason);
bool message_is_sent_by_us(ProfMessage *message, bool checkOID);
bool message_is_sent_by_us(const ProfMessage *const message, bool checkOID);
void presence_subscription(const char *const jid, const jabber_subscr_t action);
GList* presence_get_subscription_requests(void);

View File

@ -188,8 +188,8 @@ void mucwin_occupant_affiliation_change(ProfMucWin *mucwin, const char * const n
void mucwin_occupant_role_and_affiliation_change(ProfMucWin *mucwin, const char * const nick, const char * const role,
const char * const affiliation, const char * const actor, const char * const reason) {}
void mucwin_roster(ProfMucWin *mucwin, GList *occupants, const char * const presence) {}
void mucwin_history(ProfMucWin *mucwin, const char * const nick, GDateTime *timestamp, const char * const message) {}
void mucwin_incoming_msg(ProfMucWin *mucwin, ProfMessage *message, GSList *mentions, GList *triggers) {}
void mucwin_history(ProfMucWin *mucwin, const ProfMessage *const message) {}
void mucwin_incoming_msg(ProfMucWin *mucwin, const ProfMessage *const message, GSList *mentions, GList *triggers) {}
void mucwin_outgoing_msg(ProfMucWin *mucwin, const char *const message, const char *const id, prof_enc_t enc_mode, const char *const replace_id) {}
void mucwin_subject(ProfMucWin *mucwin, const char * const nick, const char * const subject) {}
void mucwin_requires_config(ProfMucWin *mucwin) {}

View File

@ -131,7 +131,7 @@ void message_send_gone(const char * const barejid) {}
void message_send_invite(const char * const room, const char * const contact,
const char * const reason) {}
bool message_is_sent_by_us(ProfMessage *message, bool checkOID) {
bool message_is_sent_by_us(const ProfMessage *const message, bool checkOID) {
return TRUE;
}