From c03e43f9bc38133f88fb93078e634b105e4a0600 Mon Sep 17 00:00:00 2001 From: Trumeet Date: Sat, 9 Apr 2022 18:03:59 -0700 Subject: Support photo captions --- store.c | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/store.c b/store.c index 17acc74..cda3f7b 100644 --- a/store.c +++ b/store.c @@ -108,9 +108,6 @@ static bool filter(struct TdMessage *msg) { } } - if (msg->content_->ID != CODE_MessageText) { - return false; - } return true; } @@ -121,8 +118,24 @@ void store(struct TdMessage *msg, void (*cb)(bool)) { cb(false); return; } - struct TdMessageText *text = (struct TdMessageText *) msg->content_; - const char *t = text->text_->text_; + char *t; + switch (msg->content_->ID) { + case CODE_MessageText: { + struct TdMessageText *text = (struct TdMessageText *) msg->content_; + t = text->text_->text_; + break; + } + case CODE_MessagePhoto: { + struct TdMessagePhoto *photo = (struct TdMessagePhoto *) msg->content_; + if (!photo->caption_ || !photo->caption_->text_) goto f; + t = photo->caption_->text_; + break; + } + default: { + goto f; + } + } + assert(t); struct say *s; if (!(s = malloc(sizeof(struct say)))) { LOGEV("Cannot allocate memory: %s.", strerror(errno)); -- cgit v1.2.3