This is an automated email from the git hooks/post-receive script.

git pushed a commit to branch main
in repository elaro.

View the commit online.

commit e6a85206ff10ef9905263129932c9c4a73d5e103
Author: Alastair Poole <[email protected]>
AuthorDate: Tue Nov 24 14:02:31 2026 +0000

    ui: make auto-complete more intelligent.
---
 src/core/nick-rec.h            |  2 ++
 src/engine/elaro_engine.c      | 21 +++++++++++++++++++--
 src/engine/elaro_engine.h      |  1 +
 src/fe-efl/ui/elaro_ui_users.c | 27 ++++++++++++++++++---------
 tests/fe-efl/test-ui-state.c   | 17 +++++++++++++++++
 5 files changed, 57 insertions(+), 11 deletions(-)

diff --git a/src/core/nick-rec.h b/src/core/nick-rec.h
index 53bc709..54cb250 100644
--- a/src/core/nick-rec.h
+++ b/src/core/nick-rec.h
@@ -3,6 +3,8 @@
 int type; /* module_get_uniq_id("NICK", 0) */
 int chat_type; /* chat_protocol_lookup(xx) */
 
+guint64 last_spoke; /* order of the last incoming channel message */
+
 time_t last_check; /* last time gone was checked */
 
 char *nick;
diff --git a/src/engine/elaro_engine.c b/src/engine/elaro_engine.c
index 0a0e0f3..6f41311 100644
--- a/src/engine/elaro_engine.c
+++ b/src/engine/elaro_engine.c
@@ -43,6 +43,7 @@ struct _Elaro_Engine
    GSList *connections;
    bool reconnect_available;
    GMainLoop *loop;
+   guint64 speech_sequence;
    char *binary, *selected_server, *selected_target, *last_nicks;
    GHashTable *whois_presence;
 };
@@ -514,6 +515,18 @@ _dialog(const char *type, const char *text)
    _emit_event(ELARO_ENGINE_LINE, NULL, "", text);
 }
 
+static void
+_channel_speaker_record(IRC_SERVER_REC *s, const char *target, const char *nick)
+{
+   CHANNEL_REC *channel;
+   NICK_REC *user;
+
+   if (!nick || !s->nick_comp_func(nick, s->nick)) return;
+   channel = channel_find(SERVER(s), target);
+   user = channel ? nicklist_find(channel, nick) : NULL;
+   if (user) user->last_spoke = ++active->speech_sequence;
+}
+
 /* CTCP has already removed the protocol frame before emitting this signal. */
 static void
 _action(IRC_SERVER_REC *s, const char *body, const char *nick, const char *address,
@@ -523,6 +536,7 @@ _action(IRC_SERVER_REC *s, const char *body, const char *nick, const char *addre
    char *text;
 
    if (channel && !channel_find(SERVER(s), target)) return;
+   if (channel) _channel_speaker_record(s, target, nick);
    text = g_strdup_printf("* %s %s", nick ? nick : s->tag, body);
    _emit_event_full(ELARO_ENGINE_LINE, s->tag, channel ? target : nick, text,
                     !channel && nick && address && *address && !s->nick_comp_func(target, s->nick)
@@ -649,6 +663,8 @@ _server_event(IRC_SERVER_REC *s, const char *line, const char *nick, const char
                   return;
                }
              channel_message = target && server_ischannel(SERVER(s), target);
+             if (channel_message && !g_ascii_strcasecmp(copy, "PRIVMSG"))
+                _channel_speaker_record(s, target, nick);
              mention = !g_ascii_strcasecmp(copy, "PRIVMSG") && target && nick
                        && server_ischannel(SERVER(s), target)
                        && s->nick_comp_func(nick, s->nick) && _nick_mentioned(s, body);
@@ -1344,9 +1360,10 @@ _snapshot(gpointer data)
              Whois_Presence *pending = _whois_presence_find(s, n->nick);
              gboolean away = pending ? pending->previous : n->gone;
              /* Borrow nicknames while comparing; copy only for a new event. */
-             Elaro_Engine_User user = { n->nick, n->op ? '@' : n->voice ? '+' : 0, away };
+             Elaro_Engine_User user = { n->nick, n->op ? '@' : n->voice ? '+' : 0, away, n->last_spoke };
              g_array_append_val(users, user);
-             g_string_append_printf(state, "%c%s\n", away ? 'G' : 'H', n->nick);
+             g_string_append_printf(state, "%c%" G_GUINT64_FORMAT " %s\n",
+                                    away ? 'G' : 'H', n->last_spoke, n->nick);
              g_string_append_printf(names, "%s%s\n", n->op ? "@" : n->voice ? "+" : "", n->nick);
           }
         g_slist_free(nicks);
diff --git a/src/engine/elaro_engine.h b/src/engine/elaro_engine.h
index 1794e61..aff3bbc 100644
--- a/src/engine/elaro_engine.h
+++ b/src/engine/elaro_engine.h
@@ -78,6 +78,7 @@ typedef struct
    char *nick;
    char prefix;
    bool away;
+   uint64_t last_spoke;
 } Elaro_Engine_User;
 
 typedef struct
diff --git a/src/fe-efl/ui/elaro_ui_users.c b/src/fe-efl/ui/elaro_ui_users.c
index d274dcb..f8069ee 100644
--- a/src/fe-efl/ui/elaro_ui_users.c
+++ b/src/fe-efl/ui/elaro_ui_users.c
@@ -8,6 +8,7 @@ typedef struct
    Evas_Object *preview;
    Eina_Bool lookup_requested;
    Ecore_Timer *lookup_timer;
+   uint64_t last_spoke;
    char status;
    Eina_Bool seen, away;
    Elm_Object_Item *item;
@@ -174,10 +175,14 @@ _completion_reset(Elaro_Ui *ui)
 static int
 _completion_compare(const void *a, const void *b)
 {
+   const User *first = a, *second = b;
    int order;
 
-   order = strcasecmp(a, b);
-   return order ? order : strcmp(a, b);
+   if (first->last_spoke != second->last_spoke)
+      return first->last_spoke > second->last_spoke ? -1 : 1;
+
+   order = strcasecmp(first->nick, second->nick);
+   return order ? order : strcmp(first->nick, second->nick);
 }
 
 Eina_Bool
@@ -186,6 +191,7 @@ elaro_ui_users_complete(void *data, Evas_Object *obj, Evas_Event_Key_Down *ev)
    Elaro_Ui *ui;
    Eina_Iterator *iter;
    User *u;
+   Eina_List *matches = NULL;
    char *text, *end, *start, *prefix, *markup, *result;
    const char *nick, *separator;
    int cursor, offset, i;
@@ -228,13 +234,14 @@ elaro_ui_users_complete(void *data, Evas_Object *obj, Evas_Event_Key_Down *ev)
         iter = eina_hash_iterator_data_new(ui->users);
         EINA_ITERATOR_FOREACH (iter, u)
            if (!strncasecmp(u->nick, prefix, strlen(prefix)))
-             {
-                char *match = strdup(u->nick);
-                if (match)
-                   ui->completion.matches = eina_list_sorted_insert(
-                       ui->completion.matches, _completion_compare, match);
-             }
+              matches = eina_list_append(matches, u);
         eina_iterator_free(iter);
+        matches = eina_list_sort(matches, 0, _completion_compare);
+        EINA_LIST_FREE (matches, u)
+          {
+             char *match = strdup(u->nick);
+             if (match) ui->completion.matches = eina_list_append(ui->completion.matches, match);
+          }
         free(prefix);
         ui->completion.next = ui->completion.matches;
      }
@@ -434,7 +441,6 @@ elaro_ui_users_update(Elaro_Ui *ui, const Elaro_Engine_User *users, unsigned int
    const char *nick;
    char status;
 
-   _completion_reset(ui);
    iter = eina_hash_iterator_data_new(ui->users);
    EINA_ITERATOR_FOREACH (iter, u)
       u->seen = EINA_FALSE;
@@ -459,6 +465,7 @@ elaro_ui_users_update(Elaro_Ui *ui, const Elaro_Engine_User *users, unsigned int
 
         if (!u)
           {
+             _completion_reset(ui);
              u = calloc(1, sizeof(User));
              if (!u) return;
              u->nick = strdup(nick);
@@ -477,6 +484,7 @@ elaro_ui_users_update(Elaro_Ui *ui, const Elaro_Engine_User *users, unsigned int
              u->away = users[i].away;
              elm_genlist_item_update(u->item);
           }
+        u->last_spoke = users[i].last_spoke;
         u->seen = EINA_TRUE;
      }
 
@@ -485,6 +493,7 @@ elaro_ui_users_update(Elaro_Ui *ui, const Elaro_Engine_User *users, unsigned int
    EINA_ITERATOR_FOREACH (iter, u)
       if (!u->seen) removed = eina_list_append(removed, u);
    eina_iterator_free(iter);
+   if (removed) _completion_reset(ui);
    EINA_LIST_FREE (removed, u)
      {
         eina_hash_del_by_key(ui->users, u->nick);
diff --git a/tests/fe-efl/test-ui-state.c b/tests/fe-efl/test-ui-state.c
index 73a4c90..1a5e13e 100644
--- a/tests/fe-efl/test-ui-state.c
+++ b/tests/fe-efl/test-ui-state.c
@@ -365,6 +365,23 @@ int main(int argc, char **argv)
     input_set(&ui, "al");
     complete(&ui, "Alfred: ");
     complete(&ui, "Alice: ");
+    {
+        Elaro_Engine_User speakers[] = {
+            { .nick = "One" },
+            { .nick = "Other", .last_spoke = 1 },
+            { .nick = "OnlyHuman", .last_spoke = 2 },
+        };
+
+        elaro_ui_users_update(&ui, speakers, EINA_C_ARRAY_LENGTH(speakers));
+        input_set(&ui, "O");
+        complete(&ui, "OnlyHuman: ");
+        speakers[0].last_spoke = 3;
+        elaro_ui_users_update(&ui, speakers, EINA_C_ARRAY_LENGTH(speakers));
+        complete(&ui, "Other: ");
+        complete(&ui, "One: ");
+        input_set(&ui, "o");
+        complete(&ui, "One: ");
+    }
     update_users(&ui, "Alice\n");
     input_set(&ui, "al");
     complete(&ui, "Alice: ");

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.

Reply via email to