From eac2f53aad3c942994c3a91b7819e9f45c2d7e59 Mon Sep 17 00:00:00 2001 From: nekobit Date: Wed, 17 Aug 2022 21:38:28 +0000 Subject: [PATCH] perlify_message(s) FossilOrigin-Name: ac178b0d18e84d776b7f6ce8ffad5ad900a3d5af9dbdfca4a137d2e9ae5bf1f0 --- src/conversations.c | 31 +++++++++++++++++++++++++++++++ src/conversations.h | 3 +++ 2 files changed, 34 insertions(+) diff --git a/src/conversations.c b/src/conversations.c index 265a912..4311222 100644 --- a/src/conversations.c +++ b/src/conversations.c @@ -18,6 +18,7 @@ #include #include "account.h" +#include "emoji.h" #include "../config.h" #include "conversations.h" #include "helpers.h" @@ -331,3 +332,33 @@ AV* perlify_chats(const struct mstdnt_chat* chats, size_t len) return av; } +HV* perlify_message(const struct mstdnt_message* message) +{ + if (!message) return NULL; + + HV* message_hv = newHV(); + hvstores_str(message_hv, "account_id", message->account_id); + hvstores_str(message_hv, "chat_id", message->chat_id); + hvstores_str(message_hv, "id", message->id); + hvstores_str(message_hv, "content", message->content); + hvstores_int(message_hv, "created_at", message->created_at); + hvstores_ref(message_hv, "emojis", perlify_emojis(message->emojis, message->emojis_len)); + hvstores_int(message_hv, "unread", message->unread); + + return message_hv; +} + +AV* perlify_messages(const struct mstdnt_message* messages, size_t len) +{ + if (!(messages && len)) return NULL; + AV* av = newAV(); + av_extend(av, len-1); + + for (int i = 0; i < len; ++i) + { + av_store(av, i, newRV_inc((SV*)perlify_message(messages + i))); + } + + return av; +} + diff --git a/src/conversations.h b/src/conversations.h index b1cf1da..fb988ca 100644 --- a/src/conversations.h +++ b/src/conversations.h @@ -52,4 +52,7 @@ void content_chat_view(PATH_ARGS); AV* perlify_chats(const struct mstdnt_chat* chats, size_t chats_len); HV* perlify_chat(const struct mstdnt_chat* chat); +AV* perlify_messages(const struct mstdnt_message* messages, size_t messages_len); +HV* perlify_message(const struct mstdnt_message* message); + #endif // LISTS_H