Skip to content

Commit

Permalink
* Fix graphical bug when deleting the first messages in a chain.
Browse files Browse the repository at this point in the history
* Fix #41.
  • Loading branch information
iProgramMC committed May 16, 2024
1 parent 56f8636 commit 0ef29f2
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 30 deletions.
20 changes: 9 additions & 11 deletions src/discord/DiscordInstance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1667,26 +1667,24 @@ void DiscordInstance::HandleMessageInsertOrUpdate(Json& j, bool bIsUpdate)

if (!bIsUpdate)
{
if (msg.CheckWasMentioned(m_mySnowflake, guildId))
if (msg.CheckWasMentioned(m_mySnowflake, guildId) && m_CurrentChannel != channelId)
pChan->m_mentionCount++;
}

if (m_CurrentChannel == channelId)
{
if (pChan->m_lastViewedMsg == oldSentMsg)
pChan->m_lastViewedMsg = pChan->m_lastSentMsg;
else
GetFrontend()->UpdateChannelAcknowledge(channelId);
}
bool updateAck = false;

if (m_CurrentChannel == channelId && pChan->m_lastViewedMsg == oldSentMsg)
pChan->m_lastViewedMsg = pChan->m_lastSentMsg;
else
{
GetFrontend()->UpdateChannelAcknowledge(channelId);
}
updateAck = true;

if (bIsUpdate)
GetFrontend()->OnUpdateMessage(channelId, msg);
else
GetFrontend()->OnAddMessage(channelId, msg);

if (updateAck)
GetFrontend()->UpdateChannelAcknowledge(channelId);
}

void DiscordInstance::HandleMESSAGE_CREATE(Json& j)
Expand Down
22 changes: 19 additions & 3 deletions src/windows/GuildLister.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,11 @@ void GuildLister::AskLeave(Snowflake guild)
}
}

void GuildLister::RedrawIconForGuild(Snowflake guild)
{
InvalidateRect(m_hwnd, &m_iconRects[guild], TRUE);
}

LRESULT CALLBACK GuildLister::ParentWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
GuildLister* pThis = (GuildLister*)GetWindowLongPtr(hWnd, GWLP_USERDATA);
Expand All @@ -266,13 +271,15 @@ LRESULT CALLBACK GuildLister::ParentWndProc(HWND hWnd, UINT uMsg, WPARAM wParam,
return DefWindowProc(hWnd, uMsg, wParam, lParam);
}

void DrawServerIcon(HDC hdc, HBITMAP hicon, int& y, RECT& rect, Snowflake id, const std::string& textOver)
void GuildLister::DrawServerIcon(HDC hdc, HBITMAP hicon, int& y, RECT& rect, Snowflake id, const std::string& textOver)
{
int height = 0;
int pfpSize = GetProfilePictureSize();
int pfpBorderSize = ScaleByDPI(PROFILE_PICTURE_SIZE_DEF + 12);
bool isCurrent = GetDiscordInstance()->GetCurrentGuildID() == id;

SetRectEmpty(&m_iconRects[id]);

if (hdc && hicon)
{
HICON hborder;
Expand All @@ -288,6 +295,8 @@ void DrawServerIcon(HDC hdc, HBITMAP hicon, int& y, RECT& rect, Snowflake id, co
rect.top + y + pfpBorderSize + BORDER_SIZE * 2
};

m_iconRects[id] = rcProfile;

int pfpBorderSize2 = GetProfileBorderRenderSize();

FillRect(hdc, &rcProfile, GetSysColorBrush(GUILD_LISTER_COLOR));
Expand All @@ -299,9 +308,16 @@ void DrawServerIcon(HDC hdc, HBITMAP hicon, int& y, RECT& rect, Snowflake id, co
else if (hicon)
{
height = pfpBorderSize;

RECT rcProfile = {
rect.left + BORDER_SIZE,
rect.top + y,
rect.left + pfpBorderSize + BORDER_SIZE * 2,
rect.top + y + pfpBorderSize + BORDER_SIZE * 2
};
}

if (!textOver.empty())
if (hdc && !textOver.empty())
{
int mod = SetBkMode(hdc, TRANSPARENT);
COLORREF clr = SetTextColor(hdc, RGB(255, 255, 255));
Expand Down Expand Up @@ -600,7 +616,7 @@ LRESULT CALLBACK GuildLister::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARA
}

int oldY = y;
DrawServerIcon(hdc, hbm, y, rect, sf, textOver);
pThis->DrawServerIcon(hdc, hbm, y, rect, sf, textOver);
DrawMentionStatus(hdc, rect.left + BORDER_SIZE + ScaleByDPI(6), rect.top + BORDER_SIZE + ScaleByDPI(4) + oldY, mentionCount);
}

Expand Down
6 changes: 6 additions & 0 deletions src/windows/GuildLister.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ class GuildLister

Snowflake m_rightClickedGuild = 0;

std::map<Snowflake, RECT> m_iconRects;

public:
GuildLister();
~GuildLister();
Expand All @@ -37,6 +39,10 @@ class GuildLister
void OnScroll();
void ShowMenu(Snowflake guild, POINT pt);
void AskLeave(Snowflake guild);
void RedrawIconForGuild(Snowflake guild);

private:
void DrawServerIcon(HDC hdc, HBITMAP hicon, int& y, RECT& rect, Snowflake id, const std::string& textOver);

public:
static WNDCLASS g_GuildListerParentClass;
Expand Down
14 changes: 11 additions & 3 deletions src/windows/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -726,14 +726,22 @@ LRESULT CALLBACK WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
Snowflake sf = *((Snowflake*)lParam);
auto inst = GetDiscordInstance();

Channel* pChan = GetDiscordInstance()->GetChannelGlobally(sf);

// Update the icon for the specific guild
g_pGuildLister->RedrawIconForGuild(pChan->m_parentGuild);

// Get the channel as is in the current guild; if found,
// update the channel view's ack status
Guild* pGuild = inst->GetGuild(inst->m_CurrentGuild);
if (!pGuild) break;

Channel* pChan = pGuild->GetChannel(sf);
if (!pChan) break;
pChan = pGuild->GetChannel(sf);
if (pChan)
break;

g_pChannelView->UpdateAcknowledgement(sf);

break;
}
case WM_UPDATECHANLIST:
Expand Down
29 changes: 16 additions & 13 deletions src/windows/MessageList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -673,6 +673,9 @@ void MessageList::DeleteMessage(Snowflake sf)

bool wasFirstMessage = niter == m_messages.begin();

int afterMessageInitialHeight = 0;
int afterMessageNowHeight = 0;

if (afteriter != m_messages.end())
{
Snowflake sf = Snowflake(-1);
Expand All @@ -687,6 +690,8 @@ void MessageList::DeleteMessage(Snowflake sf)
pl = beforeiter->m_placeInChain;
}

afterMessageInitialHeight = afteriter->m_height;

bool shouldRecalc = false;
if (ShouldStartNewChain(sf, tm, pl, et, *afteriter)) {
afteriter->m_placeInChain = 0; // don't care about the rest to be honest
Expand All @@ -698,28 +703,26 @@ void MessageList::DeleteMessage(Snowflake sf)
}

if (shouldRecalc) {
// recalculate
int oldHeight = afteriter->m_height;
DetermineMessageMeasurements(*afteriter);
int diff = afteriter->m_height - oldHeight;
messageHeight -= diff;
// TODO: invalidatelater crap
}

afterMessageNowHeight = afteriter->m_height;
}

m_messages.erase(niter); // still stupid that I have to do this decrement crap

UpdateScrollBar(-messageHeight, -messageHeight, false, false);
int deltaMessageAfter = afterMessageNowHeight - afterMessageInitialHeight;
int pullDownAmount = messageHeight - deltaMessageAfter;
messageRect.bottom -= deltaMessageAfter;

UpdateScrollBar(-pullDownAmount, -pullDownAmount, false, false);

SendMessage(m_hwnd, WM_MSGLIST_PULLDOWN, 0, (LPARAM)&messageRect);

// HACKHACK: expand the refresh rect a bit if you delete the first message.
// This should really be fixed properly
if (wasFirstMessage) {
messageRect.top -= 50;
messageRect.bottom += 50;
InvalidateRect(m_hwnd, &messageRect, FALSE);
}
RECT invalRect = messageRect;
invalRect.top = invalRect.bottom;
invalRect.bottom += afterMessageNowHeight;
InvalidateRect(m_hwnd, &invalRect, FALSE);
}

void MessageList::Repaint()
Expand Down

0 comments on commit 0ef29f2

Please sign in to comment.