feat(omemo): suppress repetitive missing device ID warnings
When sending OMEMO messages, we print a warning message for every participant without a device ID on every single send: ``` Can't find a OMEMO device id for my@jid.org ``` This clutters the UI due to the high volume of repetitive information. This is solved by tracking suppressed warnings within the window structure. A warning for a specific JID and type is only shown once per window context. Suppression state is stored in the base ProfWin structure and managed via helper functions (win_warn_needed, win_warn_sent). The state is lazily initialized to save resources and automatically cleaned up when the window is closed. Warnings are explicitly reset when an OMEMO session is started or ended to ensure users see fresh alerts when toggling encryption.
This commit is contained in:
@@ -557,6 +557,10 @@ win_free(ProfWin* window)
|
||||
}
|
||||
free(window->layout);
|
||||
|
||||
if (window->warned_jids) {
|
||||
g_hash_table_destroy(window->warned_jids);
|
||||
}
|
||||
|
||||
switch (window->type) {
|
||||
case WIN_CHAT:
|
||||
{
|
||||
@@ -609,6 +613,44 @@ win_free(ProfWin* window)
|
||||
free(window);
|
||||
}
|
||||
|
||||
gboolean
|
||||
win_warn_needed(ProfWin* window, const char* const type, const char* const jid)
|
||||
{
|
||||
if (!window || !type || !jid) {
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
if (!window->warned_jids) {
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
auto_gchar gchar* key = g_strdup_printf("%s:%s", type, jid);
|
||||
return !g_hash_table_contains(window->warned_jids, key);
|
||||
}
|
||||
|
||||
void
|
||||
win_warn_sent(ProfWin* window, const char* const type, const char* const jid)
|
||||
{
|
||||
if (!window || !type || !jid) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!window->warned_jids) {
|
||||
window->warned_jids = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL);
|
||||
}
|
||||
|
||||
gchar* key = g_strdup_printf("%s:%s", type, jid);
|
||||
g_hash_table_insert(window->warned_jids, key, GINT_TO_POINTER(1));
|
||||
}
|
||||
|
||||
void
|
||||
win_clear_warned_jids(ProfWin* window)
|
||||
{
|
||||
if (window && window->warned_jids) {
|
||||
g_hash_table_remove_all(window->warned_jids);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
win_page_up(ProfWin* window, int scroll_size)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user