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