diff options
author | DebXWoody <stefan@debxwoody.de> | 2021-05-29 09:30:13 +0200 |
---|---|---|
committer | DebXWoody <stefan@debxwoody.de> | 2021-05-29 09:30:13 +0200 |
commit | 6dd11f0fff27d9019c9e362fc2567f2a0c64690b (patch) | |
tree | a2efeb21ca1cffcf853274ae340c0c9221a4157b /src/ui | |
parent | 35206453667d46e4e14903c435958a94d8ad00e5 (diff) | |
download | profani-tty-6dd11f0fff27d9019c9e362fc2567f2a0c64690b.tar.gz |
Attention flagĀ for groupchats
Attention flag for groupchat and display the windows via "/wins attention"
Diffstat (limited to 'src/ui')
-rw-r--r-- | src/ui/console.c | 20 | ||||
-rw-r--r-- | src/ui/inputwin.c | 12 | ||||
-rw-r--r-- | src/ui/ui.h | 1 | ||||
-rw-r--r-- | src/ui/win_types.h | 1 | ||||
-rw-r--r-- | src/ui/window.c | 1 | ||||
-rw-r--r-- | src/ui/window_list.c | 45 | ||||
-rw-r--r-- | src/ui/window_list.h | 1 |
7 files changed, 79 insertions, 2 deletions
diff --git a/src/ui/console.c b/src/ui/console.c index 3eff47d5..74a7740f 100644 --- a/src/ui/console.c +++ b/src/ui/console.c @@ -507,6 +507,26 @@ cons_show_wins(gboolean unread) } void +cons_show_wins_attention() { + ProfWin* console = wins_get_console(); + cons_show(""); + GSList* window_strings = wins_create_summary_attention(); + + GSList* curr = window_strings; + while (curr) { + if (g_strstr_len(curr->data, strlen(curr->data), " unread") > 0) { + win_println(console, THEME_CMD_WINS_UNREAD, "-", "%s", curr->data); + } else { + win_println(console, THEME_DEFAULT, "-", "%s", curr->data); + } + curr = g_slist_next(curr); + } + g_slist_free_full(window_strings, free); + + cons_alert(NULL); +} + +void cons_show_room_invites(GList* invites) { cons_show(""); diff --git a/src/ui/inputwin.c b/src/ui/inputwin.c index e23fad68..8de12115 100644 --- a/src/ui/inputwin.c +++ b/src/ui/inputwin.c @@ -36,6 +36,7 @@ #define _XOPEN_SOURCE_EXTENDED #include "config.h" +#include <assert.h> #include <stdio.h> #include <sys/select.h> #include <stdlib.h> @@ -814,8 +815,15 @@ static int _inp_rl_win_attention_handler(int count, int key) { ProfWin* current = wins_get_current(); if ( current ) { - ProfChatWin* chatwin = (ProfChatWin*)current; - chatwin->has_attention = !chatwin->has_attention; + if (current->type == WIN_CHAT) { + ProfChatWin* chatwin = (ProfChatWin*)current; + assert(chatwin->memcheck == PROFCHATWIN_MEMCHECK); + chatwin->has_attention = !chatwin->has_attention; + } else if (current->type == WIN_MUC) { + ProfMucWin* mucwin = (ProfMucWin*)current; + assert(mucwin->memcheck == PROFMUCWIN_MEMCHECK); + mucwin->has_attention = !mucwin->has_attention; + } win_redraw(current); } return 0; diff --git a/src/ui/ui.h b/src/ui/ui.h index 391b906c..3404992d 100644 --- a/src/ui/ui.h +++ b/src/ui/ui.h @@ -256,6 +256,7 @@ void cons_show_contacts(GSList* list); void cons_show_roster(GSList* list); void cons_show_roster_group(const char* const group, GSList* list); void cons_show_wins(gboolean unread); +void cons_show_wins_attention(); char* cons_get_string(ProfConsoleWin* conswin); void cons_show_status(const char* const barejid); void cons_show_info(PContact pcontact); diff --git a/src/ui/win_types.h b/src/ui/win_types.h index d40a5396..f2237a79 100644 --- a/src/ui/win_types.h +++ b/src/ui/win_types.h @@ -197,6 +197,7 @@ typedef struct prof_muc_win_t // For LMC char* last_message; char* last_msg_id; + gboolean has_attention; } ProfMucWin; typedef struct prof_conf_win_t ProfConfWin; diff --git a/src/ui/window.c b/src/ui/window.c index f4439c74..36825eab 100644 --- a/src/ui/window.c +++ b/src/ui/window.c @@ -213,6 +213,7 @@ win_create_muc(const char* const roomjid) new_win->is_omemo = FALSE; new_win->last_message = NULL; new_win->last_msg_id = NULL; + new_win->has_attention = FALSE; new_win->memcheck = PROFMUCWIN_MEMCHECK; diff --git a/src/ui/window_list.c b/src/ui/window_list.c index a90c7141..2c45ea97 100644 --- a/src/ui/window_list.c +++ b/src/ui/window_list.c @@ -1102,6 +1102,51 @@ wins_create_summary(gboolean unread) return result; } +GSList* +wins_create_summary_attention() +{ + GSList* result = NULL; + + GList* keys = g_hash_table_get_keys(windows); + keys = g_list_sort(keys, _wins_cmp_num); + GList* curr = keys; + + while (curr) { + ProfWin* window = g_hash_table_lookup(windows, curr->data); + gboolean has_attention = FALSE; + if (window->type == WIN_CHAT) { + ProfChatWin* chatwin = (ProfChatWin*)window; + assert(chatwin->memcheck == PROFCHATWIN_MEMCHECK); + has_attention = chatwin->has_attention; + } else if (window->type == WIN_MUC) { + ProfMucWin* mucwin = (ProfMucWin*)window; + assert(mucwin->memcheck == PROFMUCWIN_MEMCHECK); + has_attention = mucwin->has_attention; + } + if ( has_attention) { + GString* line = g_string_new(""); + + int ui_index = GPOINTER_TO_INT(curr->data); + char* winstring = win_to_string(window); + if (!winstring) { + g_string_free(line, TRUE); + continue; + } + + g_string_append_printf(line, "%d: %s", ui_index, winstring); + free(winstring); + + result = g_slist_append(result, strdup(line->str)); + g_string_free(line, TRUE); + } + curr = g_list_next(curr); + } + + g_list_free(keys); + + return result; +} + char* win_autocomplete(const char* const search_str, gboolean previous, void* context) { diff --git a/src/ui/window_list.h b/src/ui/window_list.h index e02358f9..b2c752e0 100644 --- a/src/ui/window_list.h +++ b/src/ui/window_list.h @@ -87,6 +87,7 @@ void wins_lost_connection(void); void wins_reestablished_connection(void); gboolean wins_tidy(void); GSList* wins_create_summary(gboolean unread); +GSList* wins_create_summary_attention(); void wins_destroy(void); GList* wins_get_nums(void); void wins_swap(int source_win, int target_win); |