[ADD/MOD] XMPP->Matrix media bridge, small cleanup

This commit is contained in:
LDA 2024-06-23 15:34:51 +02:00
commit 42d69226f0
14 changed files with 327 additions and 54 deletions

View file

@ -1,5 +1,10 @@
#include <Matrix.h>
#include <Cytoplasm/Memory.h>
#include <Cytoplasm/Str.h>
#include <string.h>
HashMap *
MatrixCreateNotice(char *body)
{
@ -61,3 +66,51 @@ MatrixCreateNickChange(char *nick)
return map;
}
HashMap *
MatrixCreateMedia(char *mxc, char *body, char *mime)
{
HashMap *map;
char *mime_type = NULL, *matrix_type = NULL;
if (!mxc || !body)
{
return NULL;
}
matrix_type = "m.file";
if (mime)
{
size_t i;
mime_type = StrDuplicate(mime);
for (i = 0; i < strlen(mime); i++)
{
if (mime_type[i] == '/')
{
mime_type[i] = '\0';
break;
}
}
if (StrEquals(mime_type, "image"))
{
matrix_type = "m.image";
}
else if (StrEquals(mime_type, "video"))
{
matrix_type = "m.video";
}
else if (StrEquals(mime_type, "audio"))
{
matrix_type = "m.audio";
}
Free(mime_type);
}
map = HashMapCreate();
HashMapSet(map, "msgtype", JsonValueString(matrix_type));
HashMapSet(map, "mimetype", JsonValueString(mime));
HashMapSet(map, "body", JsonValueString(body));
HashMapSet(map, "url", JsonValueString(mxc));
return map;
}