aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulien Dessaux2020-08-14 11:22:10 +0200
committerJulien Dessaux2020-08-14 11:22:10 +0200
commit0327cba62d6e32d47a249ef10dd56baa421b6f8a (patch)
treec014dd2900374eb4ef033f870cdb2f5a53a0fc43
parentRemoved useless type (diff)
downloadrocket-cli-client-0327cba62d6e32d47a249ef10dd56baa421b6f8a.tar.gz
rocket-cli-client-0327cba62d6e32d47a249ef10dd56baa421b6f8a.tar.bz2
rocket-cli-client-0327cba62d6e32d47a249ef10dd56baa421b6f8a.zip
Handle the alert flag in subscriptions
-rw-r--r--common/subscriptions.c7
-rw-r--r--common/subscriptions.h5
-rw-r--r--maar/main.c2
-rw-r--r--restapi/subscriptions.c5
4 files changed, 11 insertions, 8 deletions
diff --git a/common/subscriptions.c b/common/subscriptions.c
index 529c339..60ce002 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* rid, const char* name, enum subscription_type type, size_t unread)
+void common_subscription_add(struct subscription** subscriptions, const char* rid, const char* name, enum subscription_type type, size_t unread, char alert)
{
- struct subscription * subscription = common_subscription_new(rid, name, type, unread);
+ struct subscription * subscription = common_subscription_new(rid, name, type, unread, alert);
HASH_ADD_KEYPTR(hh, *subscriptions, subscription->rid, strlen(rid), subscription);
}
-struct subscription* common_subscription_new(const char* rid, const char* name, enum subscription_type type, size_t unread)
+struct subscription* common_subscription_new(const char* rid, const char* name, enum subscription_type type, size_t unread, char alert)
{
struct subscription* subscription = malloc(sizeof(struct subscription));
subscription->rid = malloc(strlen(rid) + 1);
@@ -15,6 +15,7 @@ struct subscription* common_subscription_new(const char* rid, const char* name,
strcpy(subscription->name, name);
subscription->type = type;
subscription->unread = unread;
+ subscription->alert = alert;
return subscription;
}
diff --git a/common/subscriptions.h b/common/subscriptions.h
index e6f4771..1c42ad0 100644
--- a/common/subscriptions.h
+++ b/common/subscriptions.h
@@ -14,11 +14,12 @@ struct subscription {
char* name;
enum subscription_type type;
size_t unread;
+ char alert;
UT_hash_handle hh;
};
-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* rid, const char* name, enum subscription_type type, size_t unread);
+void common_subscription_add(struct subscription** subscriptions, const char* id, const char* name, enum subscription_type type, size_t unread, char alert);
+struct subscription* common_subscription_new(const char* rid, const char* name, enum subscription_type type, size_t unread, char alert);
void common_subscriptions_free(struct subscription* subscriptions);
void common_subscriptions_const_walk(const struct subscription* subscriptions, void (*func)(const struct subscription*));
size_t common_subscriptions_count(const struct subscription* subscriptions);
diff --git a/maar/main.c b/maar/main.c
index dc93a86..ee13907 100644
--- a/maar/main.c
+++ b/maar/main.c
@@ -11,7 +11,7 @@
void maar_subscription(const struct subscription* subscription)
{
- if (subscription->unread >0) {
+ if (subscription->unread >0 || subscription->alert) {
printf("%s\n", subscription->name);
liveapi_mark_read(subscription->rid);
liveapi_step();
diff --git a/restapi/subscriptions.c b/restapi/subscriptions.c
index 5a1abe6..a296b1c 100644
--- a/restapi/subscriptions.c
+++ b/restapi/subscriptions.c
@@ -42,8 +42,9 @@ restapi_subscriptions_get(void)
const cJSON* type = cJSON_GetObjectItemCaseSensitive(update, "t");
const cJSON* open = cJSON_GetObjectItemCaseSensitive(update, "open");
const cJSON* unread = cJSON_GetObjectItemCaseSensitive(update, "unread");
+ const cJSON* alert = cJSON_GetObjectItemCaseSensitive(update, "alert");
enum subscription_type etype;
- if (!cJSON_IsString(rid) || rid->valuestring == NULL || !cJSON_IsString(name) || name->valuestring == NULL || !cJSON_IsString(type) || type->valuestring == NULL || !cJSON_IsTrue(open) || !cJSON_IsNumber(unread))
+ if (!cJSON_IsString(rid) || rid->valuestring == NULL || !cJSON_IsString(name) || name->valuestring == NULL || !cJSON_IsString(type) || type->valuestring == NULL || !cJSON_IsTrue(open) || !cJSON_IsNumber(unread) || !(cJSON_IsTrue(alert) || cJSON_IsFalse(alert)))
continue;
if (strcmp(type->valuestring, "c") == 0)
etype = SUBSCRIPTION_CHANNEL;
@@ -55,7 +56,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, rid->valuestring, name->valuestring, etype, unread->valueint);
+ common_subscription_add(&subscriptions, rid->valuestring, name->valuestring, etype, unread->valueint, cJSON_IsTrue(alert));
}
}
get_json_cleanup: