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

Merge pull request #1400 from profanity-im/feature/1399-console-hilight

Dont hilight console once all messages have been read
This commit is contained in:
Michael Vetter 2020-07-09 17:07:25 +02:00 committed by GitHub
commit d075c62fed
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 148 additions and 75 deletions

View File

@ -4588,7 +4588,7 @@ cmd_bookmark(ProfWin* window, const char* const command, gchar** args)
if (conn_status != JABBER_CONNECTED) {
cons_show("You are not currently connected.");
cons_alert();
cons_alert(NULL);
return TRUE;
}
@ -4627,7 +4627,7 @@ cmd_bookmark(ProfWin* window, const char* const command, gchar** args)
if (cmd == NULL) {
cons_bad_cmd_usage(command);
cons_alert();
cons_alert(NULL);
return TRUE;
}
@ -4642,7 +4642,7 @@ cmd_bookmark(ProfWin* window, const char* const command, gchar** args)
cons_bad_cmd_usage(command);
cons_show("");
}
cons_alert();
cons_alert(NULL);
return TRUE;
}
@ -4657,13 +4657,13 @@ cmd_bookmark(ProfWin* window, const char* const command, gchar** args)
if (jid == NULL) {
cons_bad_cmd_usage(command);
cons_show("");
cons_alert();
cons_alert(NULL);
return TRUE;
}
if (strchr(jid, '@') == NULL) {
cons_show("Invalid room, must be of the form room@domain.tld");
cons_show("");
cons_alert();
cons_alert(NULL);
return TRUE;
}
@ -4674,7 +4674,7 @@ cmd_bookmark(ProfWin* window, const char* const command, gchar** args)
} else {
cons_show("No bookmark exists for %s.", jid);
}
cons_alert();
cons_alert(NULL);
return TRUE;
}
@ -4683,7 +4683,7 @@ cmd_bookmark(ProfWin* window, const char* const command, gchar** args)
if (!joined) {
cons_show("No bookmark exists for %s.", jid);
}
cons_alert();
cons_alert(NULL);
return TRUE;
}
@ -4694,7 +4694,7 @@ cmd_bookmark(ProfWin* window, const char* const command, gchar** args)
if (!parsed) {
cons_bad_cmd_usage(command);
cons_show("");
cons_alert();
cons_alert(NULL);
return TRUE;
}
@ -4704,7 +4704,7 @@ cmd_bookmark(ProfWin* window, const char* const command, gchar** args)
cons_bad_cmd_usage(command);
cons_show("");
options_destroy(options);
cons_alert();
cons_alert(NULL);
return TRUE;
}
@ -4720,7 +4720,7 @@ cmd_bookmark(ProfWin* window, const char* const command, gchar** args)
cons_show("Bookmark already exists, use /bookmark update to edit.");
}
options_destroy(options);
cons_alert();
cons_alert(NULL);
return TRUE;
}
@ -4732,13 +4732,13 @@ cmd_bookmark(ProfWin* window, const char* const command, gchar** args)
cons_show("No bookmark exists for %s.", jid);
}
options_destroy(options);
cons_alert();
cons_alert(NULL);
return TRUE;
}
cons_bad_cmd_usage(command);
options_destroy(options);
cons_alert();
cons_alert(NULL);
return TRUE;
}
@ -4750,7 +4750,7 @@ cmd_bookmark_ignore(ProfWin* window, const char* const command, gchar** args)
if (conn_status != JABBER_CONNECTED) {
cons_show("You are not currently connected.");
cons_alert();
cons_alert(NULL);
return TRUE;
}
@ -8219,13 +8219,14 @@ _cmd_execute_default(ProfWin* window, const char* inp)
// handle unknown commands
} else if ((inp[0] == '/') && (!g_str_has_prefix(inp, "/me "))) {
cons_show("Unknown command: %s", inp);
cons_alert();
cons_alert(NULL);
return TRUE;
}
// handle non commands in non chat or plugin windows
if (window->type != WIN_CHAT && window->type != WIN_MUC && window->type != WIN_PRIVATE && window->type != WIN_PLUGIN && window->type != WIN_XML) {
cons_show("Unknown command: %s", inp);
cons_alert(NULL);
return TRUE;
}

View File

@ -357,7 +357,7 @@ sv_ev_room_message(ProfMessage* message)
flash();
}
cons_show_incoming_room_message(message->from_jid->resourcepart, mucwin->roomjid, num, mention, triggers, mucwin->unread);
cons_show_incoming_room_message(message->from_jid->resourcepart, mucwin->roomjid, num, mention, triggers, mucwin->unread, window);
mucwin->unread++;

View File

@ -57,7 +57,7 @@
void
api_cons_alert(void)
{
cons_alert();
cons_alert(NULL);
}
int

View File

@ -132,7 +132,7 @@ chatwin_otr_secured(ProfChatWin* chatwin, gboolean trusted)
ui_index = 0;
}
cons_show("%s started an OTR session (%d).", chatwin->barejid, ui_index);
cons_alert();
cons_alert(window);
}
}
@ -282,7 +282,7 @@ chatwin_incoming_msg(ProfChatWin* chatwin, ProfMessage* message, gboolean win_cr
// not currently viewing chat window with sender
} else {
status_bar_new(num, WIN_CHAT, chatwin->barejid);
cons_show_incoming_message(display_name, num, chatwin->unread);
cons_show_incoming_message(display_name, num, chatwin->unread, window);
if (prefs_get_boolean(PREF_FLASH)) {
flash();

View File

@ -63,6 +63,7 @@
static void _cons_splash_logo(void);
static void _show_roster_contacts(GSList* list, gboolean show_groups);
static GList* alert_list;
void
cons_debug(const char* const msg, ...)
@ -172,7 +173,7 @@ cons_show_error(const char* const msg, ...)
g_string_free(fmt_msg, TRUE);
va_end(arg);
cons_alert();
cons_alert(NULL);
}
void
@ -284,7 +285,7 @@ cons_show_typing(const char* const barejid)
}
win_println(console, THEME_TYPING, "-", "!! %s is typing a message...", display_usr);
cons_alert();
cons_alert(NULL);
}
char*
@ -307,7 +308,7 @@ _room_triggers_to_string(GList* triggers)
void
cons_show_incoming_room_message(const char* const nick, const char* const room, const int win_index, gboolean mention,
GList* triggers, int unread)
GList* triggers, int unread, ProfWin* const window)
{
ProfWin* const console = wins_get_console();
@ -328,27 +329,27 @@ cons_show_incoming_room_message(const char* const nick, const char* const room,
} else {
win_println(console, THEME_INCOMING, "-", "<< room message: %s in %s (win %d)", nick, room, ui_index);
}
cons_alert();
cons_alert(window);
} else if (g_strcmp0(muc_show, "first") == 0) {
if (mention) {
win_println(console, THEME_MENTION, "-", "<< room mention: %s in %s (win %d)", nick, room, ui_index);
cons_alert();
cons_alert(window);
} else if (triggers) {
char* triggers_str = _room_triggers_to_string(triggers);
win_println(console, THEME_TRIGGER, "-", "<< room trigger %s: %s in %s (win %d)", triggers_str, nick, room, ui_index);
free(triggers_str);
cons_alert();
cons_alert(window);
} else if (unread == 0) {
win_println(console, THEME_INCOMING, "-", "<< room message: %s (win %d)", room, ui_index);
cons_alert();
cons_alert(window);
}
}
g_free(muc_show);
}
void
cons_show_incoming_message(const char* const short_from, const int win_index, int unread)
cons_show_incoming_message(const char* const short_from, const int win_index, int unread, ProfWin* const window)
{
ProfWin* console = wins_get_console();
@ -360,17 +361,17 @@ cons_show_incoming_message(const char* const short_from, const int win_index, in
char* chat_show = prefs_get_string(PREF_CONSOLE_CHAT);
if (g_strcmp0(chat_show, "all") == 0) {
win_println(console, THEME_INCOMING, "-", "<< chat message: %s (win %d)", short_from, ui_index);
cons_alert();
cons_alert(window);
} else if ((g_strcmp0(chat_show, "first") == 0) && unread == 0) {
win_println(console, THEME_INCOMING, "-", "<< chat message: %s (win %d)", short_from, ui_index);
cons_alert();
cons_alert(window);
}
g_free(chat_show);
}
void
cons_show_incoming_private_message(const char* const nick, const char* const room, const int win_index, int unread)
cons_show_incoming_private_message(const char* const nick, const char* const room, const int win_index, int unread, ProfWin* const window)
{
ProfWin* console = wins_get_console();
@ -382,10 +383,10 @@ cons_show_incoming_private_message(const char* const nick, const char* const roo
char* priv_show = prefs_get_string(PREF_CONSOLE_PRIVATE);
if (g_strcmp0(priv_show, "all") == 0) {
win_println(console, THEME_INCOMING, "-", "<< private message: %s in %s (win %d)", nick, room, ui_index);
cons_alert();
cons_alert(window);
} else if ((g_strcmp0(priv_show, "first") == 0) && unread == 0) {
win_println(console, THEME_INCOMING, "-", "<< private message: %s in %s (win %d)", nick, room, ui_index);
cons_alert();
cons_alert(window);
}
g_free(priv_show);
@ -429,7 +430,7 @@ cons_about(void)
pnoutrefresh(console->layout->win, 0, 0, 1, 0, rows - 3, cols - 1);
cons_alert();
cons_alert(NULL);
}
void
@ -453,7 +454,7 @@ cons_check_version(gboolean not_available_msg)
}
}
cons_alert();
cons_alert(NULL);
}
free(latest_release);
}
@ -477,7 +478,7 @@ cons_show_login_success(ProfAccount* account, gboolean secured)
if (!secured) {
cons_show_error("TLS connection not established");
}
cons_alert();
cons_alert(NULL);
}
void
@ -507,7 +508,7 @@ cons_show_wins(gboolean unread)
}
g_slist_free_full(window_strings, free);
cons_alert();
cons_alert(NULL);
}
void
@ -524,7 +525,7 @@ cons_show_room_invites(GList* invites)
}
}
cons_alert();
cons_alert(NULL);
}
void
@ -533,7 +534,7 @@ cons_show_info(PContact pcontact)
ProfWin* console = wins_get_console();
win_show_info(console, pcontact);
cons_alert();
cons_alert(NULL);
}
void
@ -608,7 +609,7 @@ cons_show_caps(const char* const fulljid, resource_presence_t presence)
cons_show("No capabilities found for %s", fulljid);
}
cons_alert();
cons_alert(NULL);
}
void
@ -627,7 +628,7 @@ cons_show_received_subs(void)
g_list_free_full(received, g_free);
}
cons_alert();
cons_alert(NULL);
}
void
@ -649,7 +650,7 @@ cons_show_sent_subs(void)
} else {
cons_show("No pending requests sent.");
}
cons_alert();
cons_alert(NULL);
}
void
@ -671,7 +672,7 @@ cons_show_room_list(GSList* rooms, const char* const conference_node)
cons_show("No chat rooms at %s", conference_node);
}
cons_alert();
cons_alert(NULL);
}
void
@ -725,7 +726,7 @@ cons_show_bookmarks(const GList* list)
cons_show("Automatic invite bookmarking (/bookmark invites): OFF");
}
cons_alert();
cons_alert(NULL);
}
void
@ -765,7 +766,7 @@ cons_show_disco_info(const char* jid, GSList* identities, GSList* features)
features = g_slist_next(features);
}
cons_alert();
cons_alert(NULL);
}
}
@ -790,7 +791,7 @@ cons_show_disco_items(GSList* items, const char* const jid)
cons_show("No service discovery items for %s", jid);
}
cons_alert();
cons_alert(NULL);
}
void
@ -805,7 +806,7 @@ cons_show_status(const char* const barejid)
cons_show("No such contact \"%s\" in roster.", barejid);
}
cons_alert();
cons_alert(NULL);
}
void
@ -841,7 +842,7 @@ cons_show_room_invite(const char* const invitor, const char* const room, const c
free(display_from);
cons_alert();
cons_alert(NULL);
}
void
@ -867,7 +868,7 @@ cons_show_account_list(gchar** accounts)
cons_show("");
}
cons_alert();
cons_alert(NULL);
}
void
@ -1058,7 +1059,7 @@ cons_show_account(ProfAccount* account)
g_list_free(ordered_resources);
}
cons_alert();
cons_alert(NULL);
}
void
@ -1592,7 +1593,7 @@ cons_show_ui_prefs(void)
cons_titlebar_setting();
cons_statusbar_setting();
cons_alert();
cons_alert(NULL);
}
void
@ -1691,7 +1692,7 @@ cons_show_desktop_prefs(void)
cons_notify_setting();
cons_tray_setting();
cons_alert();
cons_alert(NULL);
}
void
@ -1779,7 +1780,7 @@ cons_show_chat_prefs(void)
cons_carbons_setting();
cons_receipts_setting();
cons_alert();
cons_alert(NULL);
}
void
@ -1889,7 +1890,7 @@ cons_show_log_prefs(void)
cons_log_setting();
cons_logging_setting();
cons_alert();
cons_alert(NULL);
}
void
@ -1955,7 +1956,7 @@ cons_show_presence_prefs(void)
cons_show("Send last activity (/lastactivity) : OFF");
}
cons_alert();
cons_alert(NULL);
}
void
@ -2096,7 +2097,7 @@ cons_show_connection_prefs(void)
cons_autoconnect_setting();
cons_rooms_cache_setting();
cons_alert();
cons_alert(NULL);
}
void
@ -2129,7 +2130,7 @@ cons_show_otr_prefs(void)
cons_show("Allow sending unencrypted files in an OTR session via /sendfile (/otr sendfile): OFF");
}
cons_alert();
cons_alert(NULL);
}
void
@ -2158,7 +2159,7 @@ cons_show_pgp_prefs(void)
cons_show("Allow sending unencrypted files via /sendfile while otherwise using PGP (/pgp sendfile): OFF");
}
cons_alert();
cons_alert(NULL);
}
void
@ -2191,7 +2192,7 @@ cons_show_omemo_prefs(void)
cons_show("Allow sending unencrypted files in an OMEMO session via /sendfile (/omemo sendfile): OFF");
}
cons_alert();
cons_alert(NULL);
}
void
@ -2209,7 +2210,7 @@ cons_show_themes(GSList* themes)
}
}
cons_alert();
cons_alert(NULL);
}
void
@ -2227,7 +2228,7 @@ cons_show_scripts(GSList* scripts)
}
}
cons_alert();
cons_alert(NULL);
}
void
@ -2245,7 +2246,7 @@ cons_show_script(const char* const script, GSList* commands)
}
}
cons_alert();
cons_alert(NULL);
}
void
@ -2271,7 +2272,7 @@ cons_prefs(void)
cons_show_omemo_prefs();
cons_show("");
cons_alert();
cons_alert(NULL);
}
void
@ -2295,7 +2296,7 @@ cons_help(void)
cons_show_padded(pad, "/help navigation : How to navigate around Profanity.");
cons_show("");
cons_alert();
cons_alert(NULL);
}
void
@ -2314,7 +2315,7 @@ cons_navigation_help(void)
cons_show("");
cons_show("See '/help win' for more information.");
cons_alert();
cons_alert(NULL);
}
void
@ -2330,7 +2331,7 @@ cons_show_roster_group(const char* const group, GSList* list)
_show_roster_contacts(list, FALSE);
cons_alert();
cons_alert(NULL);
}
void
@ -2341,7 +2342,7 @@ cons_show_roster(GSList* list)
_show_roster_contacts(list, TRUE);
cons_alert();
cons_alert(NULL);
}
void
@ -2381,15 +2382,27 @@ cons_show_contacts(GSList* list)
}
curr = g_slist_next(curr);
}
cons_alert();
cons_alert(NULL);
}
void
cons_alert(void)
cons_alert(ProfWin* alert_origin_window)
{
ProfWin* current = wins_get_current();
if (current->type != WIN_CONSOLE) {
status_bar_new(1, WIN_CONSOLE, "console");
char* win_name;
if (alert_origin_window) {
win_name = win_to_string(alert_origin_window);
} else {
win_name = strdup("console");
}
GList* item = g_list_find_custom(alert_list, win_name, (GCompareFunc)g_strcmp0);
if (!item) {
alert_list = g_list_append(alert_list, win_name);
}
}
}
@ -2707,3 +2720,29 @@ cons_show_bookmarks_ignore(gchar** list, gsize len)
win_newline(console);
}
}
gboolean
cons_has_alerts(void)
{
if (g_list_length(alert_list) > 0) {
return TRUE;
}
return FALSE;
}
void
cons_clear_alerts(void)
{
g_list_free_full(alert_list, g_free);
alert_list = NULL;
}
void
cons_remove_alert(ProfWin* window)
{
char* win_name = win_to_string(window);
GList* item = g_list_find_custom(alert_list, win_name, (GCompareFunc)g_strcmp0);
alert_list = g_list_remove_link(alert_list, item);
g_list_free_full(item, g_free);
free(win_name);
}

View File

@ -182,6 +182,7 @@ void
ui_close(void)
{
notifier_uninit();
cons_clear_alerts();
wins_destroy();
inp_close();
status_bar_close();

View File

@ -68,7 +68,7 @@ privwin_incoming_msg(ProfPrivateWin* privatewin, ProfMessage* message)
// not currently viewing chat window with sender
} else {
status_bar_new(num, WIN_PRIVATE, privatewin->fulljid);
cons_show_incoming_private_message(jidp->resourcepart, jidp->barejid, num, privatewin->unread);
cons_show_incoming_private_message(jidp->resourcepart, jidp->barejid, num, privatewin->unread, window);
win_insert_last_read_position_marker((ProfWin*)privatewin, privatewin->fulljid);
win_print_incoming(window, jidp->resourcepart, message);

View File

@ -275,13 +275,12 @@ void cons_show_room_invite(const char* const invitor, const char* const room, co
void cons_check_version(gboolean not_available_msg);
void cons_show_typing(const char* const barejid);
void cons_show_incoming_room_message(const char* const nick, const char* const room, const int win_index,
gboolean mention, GList* triggers, int unread);
void cons_show_incoming_message(const char* const short_from, const int win_index, int unread);
void cons_show_incoming_private_message(const char* const nick, const char* const room, const int win_index, int unread);
gboolean mention, GList* triggers, int unread, ProfWin* const window);
void cons_show_incoming_message(const char* const short_from, const int win_index, int unread, ProfWin* const window);
void cons_show_incoming_private_message(const char* const nick, const char* const room, const int win_index, int unread, ProfWin* const window);
void cons_show_room_invites(GList* invites);
void cons_show_received_subs(void);
void cons_show_sent_subs(void);
void cons_alert(void);
void cons_theme_setting(void);
void cons_resource_setting(void);
void cons_privileges_setting(void);
@ -329,6 +328,11 @@ void cons_theme_colours(void);
void cons_show_tlscert(TLSCertificate* cert);
void cons_show_tlscert_summary(TLSCertificate* cert);
void cons_alert(ProfWin* alert_origin_window);
void cons_remove_alert(ProfWin* window);
void cons_clear_alerts(void);
gboolean cons_has_alerts(void);
// title bar
void title_bar_set_presence(contact_presence_t presence);

View File

@ -357,6 +357,21 @@ wins_set_current_by_num(int i)
ProfPrivateWin* privatewin = (ProfPrivateWin*)window;
privatewin->unread = 0;
}
// if we switched to console
if (current == 0) {
// remove all alerts
cons_clear_alerts();
} else {
// remove alert from window where we switch to
cons_remove_alert(window);
// if there a no more alerts left
if (!cons_has_alerts()) {
// dont highlight console (no news there)
ProfWin* conswin = wins_get_console();
status_bar_active(1, conswin->type, "console");
}
}
}
}

View File

@ -905,11 +905,11 @@ cons_show_typing(const char* const barejid)
{
}
void
cons_show_incoming_room_message(const char* const nick, const char* const room, const int win_index, gboolean mention, GList* triggers, int unread)
cons_show_incoming_room_message(const char* const nick, const char* const room, const int win_index, gboolean mention, GList* triggers, int unread, ProfWin* const window)
{
}
void
cons_show_incoming_message(const char* const short_from, const int win_index, int unread)
cons_show_incoming_message(const char* const short_from, const int win_index, int unread, ProfWin* const window)
{
}
void
@ -925,7 +925,7 @@ cons_show_sent_subs(void)
{
}
void
cons_alert(void)
cons_alert(ProfWin* alert_origin_window)
{
}
void
@ -1332,3 +1332,16 @@ notify(const char* const message, int timeout,
const char* const category)
{
}
void
cons_remove_alert(ProfWin* window)
{
}
void
cons_clear_alerts(void)
{
}
gboolean
cons_has_alerts(void)
{
return FALSE;
}