MCPcopy Create free account
hub / github.com/DiscordMessenger/dm / SetLastViewedMessage

Method SetLastViewedMessage

src/windows/MessageList.cpp:4824–4878  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4822}
4823
4824void MessageList::SetLastViewedMessage(Snowflake sf, bool refreshItAlso)
4825{
4826 if (m_previousLastReadMessage == sf)
4827 return;
4828
4829 bool notExactMatch = false;
4830 auto itm = m_messages.begin();
4831 for (; itm != m_messages.end(); ++itm) {
4832 if (itm->m_msg->m_snowflake >= sf) {
4833 notExactMatch = itm->m_msg->m_snowflake != sf;
4834 break;
4835 }
4836 }
4837
4838 Snowflake old = m_previousLastReadMessage;
4839 m_previousLastReadMessage = sf;
4840 if (old != 0)
4841 {
4842 // find that message's iter...
4843 auto it = m_messages.rbegin();
4844 auto it2 = m_messages.end();
4845 for (; it != m_messages.rend(); ++it) {
4846 if (it->m_msg->m_snowflake == old) {
4847 it2 = it.base(); // returns the NEXT element.
4848 break;
4849 }
4850 }
4851
4852 if (it2 != m_messages.end()) {
4853 // refresh JUST the top part
4854 RECT rcMsg = it2->m_rect;
4855 rcMsg.bottom = rcMsg.top + ScaleByDPI(15); // about the height of the NEW marker
4856 InvalidateRect(m_hwnd, &rcMsg, FALSE);
4857 }
4858 }
4859
4860 // check if this message is the last one
4861 if (!notExactMatch && itm != m_messages.end()) {
4862 ++itm;
4863 if (itm == m_messages.end())
4864 // yeah, so don't ACTUALLY update - that'll be done on refresh.
4865 return;
4866 }
4867
4868 if (refreshItAlso)
4869 {
4870 // TODO: fix bug where first message isn't actually properly refreshed?
4871 if (itm != m_messages.end()) {
4872 // refresh, again, JUST the top part
4873 RECT rcMsg = itm->m_rect;
4874 rcMsg.bottom = rcMsg.top + ScaleByDPI(15) + (itm->m_bIsDateGap ? DATE_GAP_HEIGHT : 0); // about the height of the NEW marker
4875 InvalidateRect(m_hwnd, &rcMsg, FALSE);
4876 }
4877 }
4878}
4879
4880void MessageList::Scroll(int amount, RECT* rcClip, bool shiftAllRects)
4881{

Callers 1

WindowProcFunction · 0.80

Calls 4

ScaleByDPIFunction · 0.85
beginMethod · 0.45
endMethod · 0.45
baseMethod · 0.45

Tested by

no test coverage detected