diff options
-rw-r--r-- | common/subscriptions.c | 7 | ||||
-rw-r--r-- | common/subscriptions.h | 5 | ||||
-rw-r--r-- | restapi/subscriptions.c | 5 |
3 files changed, 10 insertions, 7 deletions
diff --git a/common/subscriptions.c b/common/subscriptions.c index d6d15aa..0874cb0 100644 --- a/common/subscriptions.c +++ b/common/subscriptions.c @@ -1,12 +1,12 @@ #include "subscriptions.h" -void common_subscription_add(struct subscription** subscriptions, const char* id, const char* name, enum subscription_type type) +void common_subscription_add(struct subscription** subscriptions, const char* id, const char* name, enum subscription_type type, size_t unread) { - struct subscription * subscription = common_subscription_new(id, name, type); + struct subscription * subscription = common_subscription_new(id, name, type, unread); HASH_ADD_KEYPTR(hh, *subscriptions, subscription->id, strlen(id), subscription); } -struct subscription* common_subscription_new(const char* id, const char* name, enum subscription_type type) +struct subscription* common_subscription_new(const char* id, const char* name, enum subscription_type type, size_t unread) { struct subscription* subscription = malloc(sizeof(struct subscription)); subscription->id = malloc(strlen(id) + 1); @@ -14,6 +14,7 @@ struct subscription* common_subscription_new(const char* id, const char* name, e subscription->name = malloc(strlen(name) + 1); strcpy(subscription->name, name); subscription->type = type; + subscription->unread = unread; return subscription; } diff --git a/common/subscriptions.h b/common/subscriptions.h index 6c10a24..a152345 100644 --- a/common/subscriptions.h +++ b/common/subscriptions.h @@ -17,11 +17,12 @@ struct subscription { char* id; char* name; enum subscription_type type; + size_t unread; UT_hash_handle hh; }; -void common_subscription_add(struct subscription** subscriptions, const char* id, const char* name, enum subscription_type type); -struct subscription* common_subscription_new(const char* id, const char* name, enum subscription_type type); +void common_subscription_add(struct subscription** subscriptions, const char* id, const char* name, enum subscription_type type, size_t unread); +struct subscription* common_subscription_new(const char* id, const char* name, enum subscription_type type, size_t unread); void common_subscriptions_free(struct subscription* subscriptions); void common_subscriptions_const_walk(const struct subscription* subscriptions, void (*func)(const struct subscription*)); diff --git a/restapi/subscriptions.c b/restapi/subscriptions.c index b52ea9a..e41cf95 100644 --- a/restapi/subscriptions.c +++ b/restapi/subscriptions.c @@ -41,8 +41,9 @@ restapi_subscriptions_get(void) const cJSON* name = cJSON_GetObjectItemCaseSensitive(update, "name"); const cJSON* type = cJSON_GetObjectItemCaseSensitive(update, "t"); const cJSON* open = cJSON_GetObjectItemCaseSensitive(update, "open"); + const cJSON* unread = cJSON_GetObjectItemCaseSensitive(update, "unread"); enum subscription_type etype; - if (!cJSON_IsString(id) || id->valuestring == NULL || !cJSON_IsString(name) || name->valuestring == NULL || !cJSON_IsString(type) || type->valuestring == NULL || !cJSON_IsTrue(open)) + if (!cJSON_IsString(id) || id->valuestring == NULL || !cJSON_IsString(name) || name->valuestring == NULL || !cJSON_IsString(type) || type->valuestring == NULL || !cJSON_IsTrue(open) || !cJSON_IsNumber(unread)) continue; if (strcmp(type->valuestring, "c") == 0) etype = SUBSCRIPTION_CHANNEL; @@ -54,7 +55,7 @@ restapi_subscriptions_get(void) fprintf(stderr, "Bug found : Unknown subscription type %s\n%s\n", type->valuestring, buffer); exit(999); } - common_subscription_add(&subscriptions, id->valuestring, name->valuestring, etype); + common_subscription_add(&subscriptions, id->valuestring, name->valuestring, etype, unread->valueint); } } get_json_cleanup: |