Skip to content

Commit

Permalink
* Some more message list fixes.
Browse files Browse the repository at this point in the history
* Fix missing status being parsed as offline status for profile updates.
  • Loading branch information
iProgramMC committed May 28, 2024
1 parent 82d6d37 commit a03ccc6
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 22 deletions.
3 changes: 2 additions & 1 deletion deps/md5/MD5.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ documentation and/or software.

#include <cstring>
#include <iostream>
#include <string>


// a small class for calculating MD5 hashes of strings or byte arrays
Expand All @@ -53,7 +54,7 @@ class MD5
typedef unsigned int size_type; // must be 32bit

MD5();
MD5(const std::string& text);
explicit MD5(const std::string& text);
void update(const unsigned char* buf, size_type length);
void update(const char* buf, size_type length);
MD5& finalize();
Expand Down
33 changes: 21 additions & 12 deletions src/discord/DiscordInstance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1644,11 +1644,13 @@ void DiscordInstance::HandleREADY_SUPPLEMENTAL(Json& j)

for (auto& memPres : guildPres) {
Snowflake userID = GetSnowflake(memPres, "user_id");
std::string status = GetFieldSafe(memPres, "status");
if (status.empty()) status = "offline";

Profile* pf = GetProfileCache()->LookupProfile(userID, "", "", "", false);
pf->m_activeStatus = GetStatusFromString(status);

if (memPres.contains("status")) {
std::string status = GetFieldSafe(memPres, "status");
if (status.empty()) status = "offline";
pf->m_activeStatus = GetStatusFromString(status);
}

// Look for any activities -- TODO: Server specific activities
if (guildPres.contains("game") && !guildPres["game"].is_null())
Expand All @@ -1663,11 +1665,13 @@ void DiscordInstance::HandleREADY_SUPPLEMENTAL(Json& j)
for (auto& friendPres : merPreFriends)
{
Snowflake userID = GetSnowflake(friendPres, "user_id");
std::string status = GetFieldSafe(friendPres, "status");
if (status.empty()) status = "offline";

Profile* pf = GetProfileCache()->LookupProfile(userID, "", "", "", false);
pf->m_activeStatus = GetStatusFromString(status);
if (friendPres.contains("status")) {
std::string status = GetFieldSafe(friendPres, "status");
if (status.empty()) status = "offline";
pf->m_activeStatus = GetStatusFromString(status);
}

// Look for any activities
if (friendPres.contains("game") && !friendPres["game"].is_null())
Expand Down Expand Up @@ -1733,9 +1737,6 @@ void DiscordInstance::HandleREADY(Json& j)
DbgPrintF("No session found with id %s!", m_sessionId.c_str());
assert(!sesh.empty());

//eActiveStatus status = GetStatusFromString(sesh["status"]);
//SetActivityStatus(status, false);

// ==== load users
if (data.contains("users") && data["users"].is_array())
{
Expand Down Expand Up @@ -2117,7 +2118,11 @@ Snowflake DiscordInstance::ParseGuildMember(Snowflake guild, nlohmann::json& mem

// TODO: Not sure if this is the guild specific or global status. Probably guild specific
if (!pres.is_null()) {
pf->m_activeStatus = GetStatusFromString(GetFieldSafe(pres, "status"));
if (pres.contains("status")) {
auto status = GetFieldSafe(pres, "status");
if (status.empty()) status = "offline";
pf->m_activeStatus = GetStatusFromString(status);
}
if (pres.contains("game") && !pres["game"].is_null()) {
pf->m_status = GetStatusStringFromGameJsonObject(pres["game"]);
}
Expand Down Expand Up @@ -2149,7 +2154,11 @@ void DiscordInstance::HandlePRESENCE_UPDATE(nlohmann::json& j)
Profile* pf = GetProfileCache()->LookupProfile(userID, "", "", "", false);

// Note: Updating these first because maybe LoadProfile triggers a refresh
pf->m_activeStatus = GetStatusFromString(GetFieldSafe(data, "status"));
if (data.contains("status")) {
std::string stat = GetFieldSafe(data, "status");
if (stat.empty()) stat = "offline";
pf->m_activeStatus = GetStatusFromString(stat);
}

// Look for any activities -- TODO: Server specific activities
if (data.contains("game") && !data["game"].is_null())
Expand Down
10 changes: 5 additions & 5 deletions src/discord/FormattedText.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,7 @@ void FormattedText::Layout(DrawingContext* context, const Rect& rect, int offset
}
}

Rect FormattedText::GetExtent()
Rect FormattedText::GetExtent(int offsetY)
{
assert(m_bFormatted && "Have to call Layout(rc) first!");

Expand All @@ -565,12 +565,12 @@ Rect FormattedText::GetExtent()

if (ext.left > w.m_rect.left)
ext.left = w.m_rect.left;
if (ext.top > w.m_rect.top)
ext.top = w.m_rect.top;
if (ext.top > w.m_rect.top + offsetY)
ext.top = w.m_rect.top + offsetY;
if (ext.right < w.m_rect.right)
ext.right = w.m_rect.right;
if (ext.bottom < w.m_rect.bottom)
ext.bottom = w.m_rect.bottom;
if (ext.bottom < w.m_rect.bottom + offsetY)
ext.bottom = w.m_rect.bottom + offsetY;
}

return ext;
Expand Down
2 changes: 1 addition & 1 deletion src/discord/FormattedText.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ class FormattedText
void Layout(DrawingContext* context, const Rect& rect, int offsetX = 0);
void Draw(DrawingContext* context, int offsetY = 0);
void RunForEachCustomEmote(FunctionEachEmote func, void* context);
Rect GetExtent();
Rect GetExtent(int offsetY = 0);

std::vector<Word>& GetWords() {
return m_words;
Expand Down
17 changes: 14 additions & 3 deletions src/windows/MessageList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2370,11 +2370,16 @@ void MessageList::DrawMessage(HDC hdc, MessageItem& item, RECT& msgRect, RECT& c
rcMsg.bottom -= item.m_attachHeight + item.m_embedHeight;
if (item.m_attachHeight)
rcMsg.bottom -= ATTACHMENT_GAP;
if (item.m_embedHeight)
rcMsg.bottom -= ScaleByDPI(5);

item.m_message.Layout(&mddc, Rect(W32RECT(rcMsg)), bIsCompact ? (item.m_authWidth + item.m_dateWidth + ScaleByDPI(10)) : 0);

Rect ext = item.m_message.GetExtent();
int height = std::max(item.m_authHeight, ext.Height());
int offsetY = ((rcMsg.bottom - rcMsg.top) - ext.Height()) / 2;

item.m_messageRect = rcMsg;

// Once laid out, also update the rectangles for the interactable items.
const auto& words = item.m_message.GetWords();
Expand Down Expand Up @@ -2447,8 +2452,6 @@ void MessageList::DrawMessage(HDC hdc, MessageItem& item, RECT& msgRect, RECT& c
}
}

item.m_messageRect = RectToNative(ext);

if (bIsCompact)
item.m_messageRect.bottom = std::max(item.m_messageRect.bottom, item.m_messageRect.top + item.m_authHeight);

Expand Down Expand Up @@ -2482,7 +2485,7 @@ void MessageList::DrawMessage(HDC hdc, MessageItem& item, RECT& msgRect, RECT& c
}
else
{
item.m_avatarRect = { -10000, -10000, -9999, -9999 };
item.m_avatarRect = { 0, 0, 0, 0 };
}
}

Expand Down Expand Up @@ -4222,6 +4225,14 @@ void MessageList::AddMessageInternal(const Message& msg, bool toStart, bool upda

UpdateScrollBar(mi.m_height - oldHeight, mi.m_height - oldHeight, toStart, true, offsetY, true);

bool needUpdateAboveMessage = GetLocalSettings()->GetMessageStyle() == MS_3DFACE;
if (needUpdateAboveMessage && mi.m_placeInChain != 0) {
RECT rcUpdate = rcClient;
rcUpdate.bottom -= offsetY;
rcUpdate.top = rcUpdate.bottom - 2;
InvalidateRect(m_hwnd, &rcUpdate, FALSE);
}

if (bDeletedNonce)
{
// in case the message shrunk in size
Expand Down

0 comments on commit a03ccc6

Please sign in to comment.