summaryrefslogtreecommitdiff
path: root/data.c
diff options
context:
space:
mode:
authorxengineering <me@xengineering.eu>2022-10-05 10:45:25 +0200
committerxengineering <me@xengineering.eu>2022-10-05 10:45:25 +0200
commita286baee2e7d0bb53aa8e743d837595e2071eb05 (patch)
tree416d0b03c4693e34f2ea2d245d0d2259779d2bb5 /data.c
parentfa67074bcc47ae09591819c720aea9edbeaef216 (diff)
downloadlimox-a286baee2e7d0bb53aa8e743d837595e2071eb05.tar
limox-a286baee2e7d0bb53aa8e743d837595e2071eb05.tar.zst
limox-a286baee2e7d0bb53aa8e743d837595e2071eb05.zip
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.
Diffstat (limited to 'data.c')
-rw-r--r--data.c22
1 files changed, 21 insertions, 1 deletions
diff --git a/data.c b/data.c
index f8be1ff..f19075c 100644
--- a/data.c
+++ b/data.c
@@ -3,6 +3,7 @@
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
+#include <stdbool.h>
#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));