mirror of
https://forge.fsky.io/lda/Parsee.git
synced 2026-03-13 19:55:10 +00:00
[MOD] Basic work to get XMPP avatars through PEP
Attaboy!
This commit is contained in:
parent
f31a9c37b6
commit
e54332e376
13 changed files with 428 additions and 25 deletions
|
|
@ -136,3 +136,72 @@ ASGetName(const ParseeConfig *c, char *room, char *user)
|
|||
}
|
||||
return ret;
|
||||
}
|
||||
char *
|
||||
ASGetAvatar(const ParseeConfig *c, char *room, char *user)
|
||||
{
|
||||
HttpClientContext *ctx;
|
||||
HashMap *reply;
|
||||
char *path = NULL, *ret = NULL;
|
||||
char *u2 = user;
|
||||
if (!c || !user)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (room)
|
||||
{
|
||||
user = HttpUrlEncode(user);
|
||||
room = HttpUrlEncode(room);
|
||||
path = StrConcat(4,
|
||||
"/_matrix/client/v3/rooms/", room,
|
||||
"/state/m.room.member/", user
|
||||
);
|
||||
ctx = ParseeCreateRequest(c, HTTP_GET, path);
|
||||
Free(user);
|
||||
Free(room);
|
||||
ASAuthenticateRequest(c, ctx);
|
||||
HttpRequestSendHeaders(ctx);
|
||||
HttpRequestSend(ctx);
|
||||
|
||||
reply = JsonDecode(HttpClientStream(ctx));
|
||||
|
||||
ret = StrDuplicate(
|
||||
JsonValueAsString(HashMapGet(reply, "avatar_url"))
|
||||
);
|
||||
HttpClientContextFree(ctx);
|
||||
JsonFree(reply);
|
||||
Free(path);
|
||||
|
||||
user = u2;
|
||||
|
||||
Log(LOG_DEBUG, "ASGetAvatar: trying to grab avatar from room, got %s", ret);
|
||||
}
|
||||
|
||||
if (!ret)
|
||||
{
|
||||
user = HttpUrlEncode(user);
|
||||
path = StrConcat(3,
|
||||
"/_matrix/client/v3/profile/", user, "/avatar_url"
|
||||
);
|
||||
ctx = ParseeCreateRequest(c, HTTP_GET, path);
|
||||
Free(user);
|
||||
user = u2;
|
||||
ASAuthenticateRequest(c, ctx);
|
||||
HttpRequestSendHeaders(ctx);
|
||||
HttpRequestSend(ctx);
|
||||
|
||||
reply = JsonDecode(HttpClientStream(ctx));
|
||||
|
||||
ret = StrDuplicate(
|
||||
JsonValueAsString(HashMapGet(reply, "avatar_url"))
|
||||
);
|
||||
StreamFlush(StreamStderr());
|
||||
HttpClientContextFree(ctx);
|
||||
JsonFree(reply);
|
||||
Free(path);
|
||||
|
||||
Log(LOG_DEBUG, "ASGetAvatar: trying to grab avatar from profile, got %s", ret);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue