Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
eb52b6a
* MessageList no longer uses DiscordInstance::GetCurrentGuild or GetC…
iProgramMC Sep 22, 2025
aed0852
* Remove "ToCurrentChannel" message senders.
iProgramMC Sep 22, 2025
30712f9
* The upload dialog now accepts a channelID parameter instead of usin…
iProgramMC Sep 22, 2025
3a01f84
* Message Editor no longer uses DiscordInstance::GetCurrentChannel
iProgramMC Sep 22, 2025
c769905
* Remove more uses of DiscordInstance::GetCurrentChannel
iProgramMC Sep 22, 2025
65b5c70
* Move the main window's code into a new MainWindow class.
iProgramMC Sep 22, 2025
8dd686d
* Remove some of the last uses of DiscordInstance GetCurrentChannel/G…
iProgramMC Sep 22, 2025
4f1f8f0
* Work on a base ChatWindow class.
iProgramMC Sep 22, 2025
ec966b9
* Completely nuke GetCurrentChannel/GetCurrentGuild from DiscordInsta…
iProgramMC Sep 22, 2025
e2f11e7
* Initialize most controls based on ChatWindow instead of HWND.
iProgramMC Sep 22, 2025
4967db3
* Add float icon to resources.
iProgramMC Sep 22, 2025
65d06ea
* Add GuildSubWindow skeleton.
iProgramMC Sep 22, 2025
1b7688c
* Improve usability of sub-windows.
iProgramMC Sep 22, 2025
2d2c920
* Improve sub windows even more.
iProgramMC Sep 22, 2025
efbfd1e
* Increased polish.
iProgramMC Sep 22, 2025
d7ff489
* Fix bugs when uploading images from sub windows.
iProgramMC Sep 22, 2025
bfd3b61
* Fix bug where window class wasn't cleared to zero
iProgramMC Sep 22, 2025
37c0ae0
* Do not show the channel view if you are splitting off a DM.
iProgramMC Sep 22, 2025
fc6cc18
* Allow subscriptions to multiple guilds at once, finally fix typing …
iProgramMC Sep 22, 2025
6030883
* Stop editing and browsing past when changing channels.
iProgramMC Sep 26, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added res/icons/icon_float.ico
Binary file not shown.
111 changes: 111 additions & 0 deletions src/discord/ChatView.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
#include "ChatView.hpp"
#include "DiscordInstance.hpp"
#include "Frontend.hpp"

Guild* ChatView::GetCurrentGuild()
{
return GetDiscordInstance()->GetGuild(m_guildID);
}

Channel* ChatView::GetCurrentChannel()
{
auto guild = GetCurrentGuild();
if (!guild)
return nullptr;

return guild->GetChannel(m_channelID);
}

void ChatView::OnSelectChannel(Snowflake sf, bool bSendSubscriptionUpdate)
{
if (m_channelID == sf)
return;

// check if there are any channels and select the first (for now)
Guild* pGuild = GetDiscordInstance()->GetGuild(m_guildID);
if (!pGuild) return;

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

if (!pChan)
{
if (sf != 0)
return;
}
else if (pChan->m_channelType == Channel::CATEGORY)
return;

// Check if we have permission to view the channel.
auto& denyList = GetDiscordInstance()->m_channelDenyList;

if (denyList.find(sf) != denyList.end() ||
(pChan && !pChan->HasPermission(PERM_VIEW_CHANNEL)))
{
GetFrontend()->OnCantViewChannel(pChan->m_name);
return;
}

GetDiscordInstance()->m_channelHistory.AddToHistory(m_channelID);

m_channelID = sf;
pGuild->m_currentChannel = sf;

GetFrontend()->UpdateSelectedChannel(m_viewID);

if (!GetCurrentChannel() || !GetCurrentGuild())
return;

// send an update subscriptions message
if (bSendSubscriptionUpdate)
GetDiscordInstance()->UpdateSubscriptions();
}

void ChatView::OnSelectGuild(Snowflake sf, Snowflake chan)
{
if (m_guildID == sf)
{
if (chan)
OnSelectChannel(chan);

return;
}

GetDiscordInstance()->m_channelHistory.AddToHistory(m_channelID);

// select the guild
m_guildID = sf;

// check if there are any channels and select the first (for now)
Guild* pGuild = GetDiscordInstance()->GetGuild(sf);
if (!pGuild)
return;

GetFrontend()->UpdateSelectedGuild(m_viewID);

if (pGuild->m_bChannelsLoaded && pGuild->m_channels.size())
{
// Determine the first channel we should load.
// TODO: Note, unfortunately this isn't really the right order, but it works for now.
if (!chan && pGuild->m_currentChannel == 0)
{
for (auto& ch : pGuild->m_channels)
{
if (ch.HasPermission(PERM_VIEW_CHANNEL) && ch.m_channelType != Channel::CATEGORY) {
pGuild->m_currentChannel = ch.m_snowflake;
break;
}
}
}

if (!chan)
chan = pGuild->m_currentChannel;

OnSelectChannel(chan, false);
}
else
{
OnSelectChannel(0);
}

GetDiscordInstance()->UpdateSubscriptions();
}
34 changes: 34 additions & 0 deletions src/discord/ChatView.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#pragma once

#include <memory>
#include "Snowflake.hpp"

struct Guild;
struct Channel;

class ChatView
{
public:
int GetID() const { return m_viewID; }
void SetID(int i) { m_viewID = i; }

Snowflake GetCurrentGuildID() const { return m_guildID; }
Snowflake GetCurrentChannelID() const { return m_channelID; }

Guild* GetCurrentGuild();
Channel* GetCurrentChannel();

void SetCurrentGuildID(Snowflake sf) { m_guildID = sf; }
void SetCurrentChannelID(Snowflake sf) { m_channelID = sf; }

void OnSelectChannel(Snowflake sf, bool bSendSubscriptionUpdate = true);
void OnSelectGuild(Snowflake sf, Snowflake chan = 0);

private:
Snowflake m_guildID = 0;
Snowflake m_channelID = 0;

int m_viewID = 0;
};

typedef std::shared_ptr<ChatView> ChatViewPtr;
Loading