From 8456e00bd8473719d5bbbbe12796413222e70152 Mon Sep 17 00:00:00 2001 From: Jaidyn Ann Date: Sat, 4 Sep 2021 21:17:25 -0500 Subject: [PATCH] (matrix) Fetch own displayname, use correct user ID --- protocols/matrix/MatrixApp.cpp | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/protocols/matrix/MatrixApp.cpp b/protocols/matrix/MatrixApp.cpp index 17210cf..4cb62f4 100644 --- a/protocols/matrix/MatrixApp.cpp +++ b/protocols/matrix/MatrixApp.cpp @@ -129,16 +129,25 @@ MatrixApp::Connect() void MatrixApp::StartLoop() { - BMessage ready(IM_MESSAGE); - ready.AddInt32("im_what", IM_PROTOCOL_READY); - SendMessage(ready); + client->get_profile(client->user_id().to_string(), + [this](const mtx::responses::Profile &res, mtx::http::RequestErr err) + { + if (err) { + print_error(err, "Failed getting own info after login…"); + StartLoop(); + snooze(1000000); + return; + } + BMessage ready(IM_MESSAGE); + ready.AddInt32("im_what", IM_PROTOCOL_READY); + SendMessage(ready); - BString mxId("@"); - mxId << fUser << ":" << fServer; - BMessage init(IM_MESSAGE); - init.AddInt32("im_what", IM_OWN_CONTACT_INFO); - init.AddString("user_id", mxId); - SendMessage(init); + BMessage init(IM_MESSAGE); + init.AddInt32("im_what", IM_OWN_CONTACT_INFO); + init.AddString("user_id", client->user_id().to_string().c_str()); + init.AddString("user_name", res.display_name.c_str()); + SendMessage(init); + }); BMessage status(IM_MESSAGE); status.AddInt32("im_what", IM_OWN_STATUS_SET);