Skip to content

Commit

Permalink
fix(messages): emit correct items-changed signas
Browse files Browse the repository at this point in the history
  • Loading branch information
andyholmes committed Oct 22, 2024
1 parent 8f9f3a4 commit 1a31e78
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions src/libvalent/messages/valent-message-thread.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,23 @@ typedef enum {

static GParamSpec *properties[PROP_PARTICIPANTS + 1] = { NULL, };

static void
valent_message_thread_items_changed (ValentMessageThread *self,
unsigned int position,
unsigned int removed,
unsigned int added)
{
/* check if the iter cache may have been invalidated */
if (position <= self->last_position)
{
self->last_iter = NULL;
self->last_position = 0;
self->last_position_valid = FALSE;
}

g_list_model_items_changed (G_LIST_MODEL (self), position, removed, added);
}

static inline int
valent_message_thread_sort_func (gconstpointer a,
gconstpointer b,
Expand Down Expand Up @@ -114,7 +131,7 @@ valent_message_thread_load_message_cb (GObject *object,
valent_message_thread_sort_func, NULL);

position = g_sequence_iter_get_position (it);
g_list_model_items_changed (G_LIST_MODEL (self), position, 0, 1);
valent_message_thread_items_changed (self, position, 0, 1);
}

static inline int
Expand Down Expand Up @@ -145,7 +162,7 @@ valent_message_thread_remove_message (ValentMessageThread *self,
{
position = g_sequence_iter_get_position (it);
g_sequence_remove (it);
g_list_model_items_changed (G_LIST_MODEL (self), position, 1, 0);
valent_message_thread_items_changed (self, position, 1, 0);
}
}

Expand Down Expand Up @@ -334,7 +351,7 @@ valent_message_thread_load_cb (GObject *object,
for (unsigned int i = 0; i < messages->len; i++)
g_sequence_append (self->items, g_object_ref (g_ptr_array_index (messages, i)));

g_list_model_items_changed (G_LIST_MODEL (self), position, 0, messages->len);
valent_message_thread_items_changed (self, position, 0, messages->len);
}

static void
Expand Down

0 comments on commit 1a31e78

Please sign in to comment.