diff options
author | Julien Dessaux | 2019-08-06 19:55:31 +0200 |
---|---|---|
committer | Julien Dessaux | 2019-08-06 19:55:31 +0200 |
commit | a753a35c37ac9b01f7e22912f8cad50603fc5ec0 (patch) | |
tree | 6758289f6456b116a25fa1aa476d9746d5d247b7 | |
parent | Have the login function return the authToken (diff) | |
download | rocket-cli-client-a753a35c37ac9b01f7e22912f8cad50603fc5ec0.tar.gz rocket-cli-client-a753a35c37ac9b01f7e22912f8cad50603fc5ec0.tar.bz2 rocket-cli-client-a753a35c37ac9b01f7e22912f8cad50603fc5ec0.zip |
Have the subscription struct hold the unread counters
Diffstat (limited to '')
-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: |