From a286baee2e7d0bb53aa8e743d837595e2071eb05 Mon Sep 17 00:00:00 2001 From: xengineering Date: Wed, 5 Oct 2022 10:45:25 +0200 Subject: Fix known-roster-item bug If you got a second roster description (e.g. after a reconnect) the roster items were just appended. There was no distinction if a roster item already existed or not. This lead to doubled entries. This commit ignores already known roster items. Mind that it is still not able to update an existing item. This is mentioned by a FIXME comment. --- data.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/data.c b/data.c index f8be1ff..f19075c 100644 --- a/data.c +++ b/data.c @@ -3,6 +3,7 @@ #include #include #include +#include #include "gui.h" #include "data.h" @@ -11,10 +12,29 @@ static roster_item_t* roster = NULL; +/* check if JID is already in roster data structure */ +bool is_jid_known(const char* jid) { + + roster_item_t* i; + + // iterate over all roster items + for (i = roster; i != NULL; i=i->next) { + if (strcmp(i->jid, jid) == 0) { + return true; + } + } + + return false; + +} + void data_add_roster_item(const char* jid, const char* subscription, const char* name) { - // FIXME check if roster item already exists and handle updates + // FIXME handle roster updates + if (is_jid_known(jid)) { + return; + } // allocate datastructures roster_item_t* item = malloc(sizeof(roster_item_t)); -- cgit v1.2.3-70-g09d2