mirror of
https://github.com/uowuo/abaddon.git
synced 2024-09-20 06:51:51 +00:00
ignore unread state from undisplayed channel types
This commit is contained in:
parent
01865075a4
commit
25ecbce043
|
@ -351,7 +351,9 @@ void DiscordClient::GetArchivedPrivateThreads(Snowflake channel_id, const sigc::
|
|||
}
|
||||
|
||||
std::vector<Snowflake> DiscordClient::GetChildChannelIDs(Snowflake parent_id) const {
|
||||
return m_store.GetChannelIDsWithParentID(parent_id);
|
||||
std::vector<Snowflake> ids;
|
||||
for (auto [id, type] : m_store.GetChannelIDsWithParentID(parent_id)) ids.push_back(id);
|
||||
return ids;
|
||||
}
|
||||
|
||||
std::optional<WebhookMessageData> DiscordClient::GetWebhookMessageData(Snowflake message_id) const {
|
||||
|
@ -1371,7 +1373,8 @@ int DiscordClient::GetUnreadStateForChannel(Snowflake id) const noexcept {
|
|||
|
||||
int DiscordClient::GetUnreadChannelsCountForCategory(Snowflake id) const noexcept {
|
||||
int result = 0;
|
||||
for (Snowflake channel_id : m_store.GetChannelIDsWithParentID(id)) {
|
||||
for (auto [channel_id, channel_type] : m_store.GetChannelIDsWithParentID(id)) {
|
||||
if (!ShouldChannelTypeCountInUnread(channel_type)) continue;
|
||||
if (IsChannelMuted(channel_id)) continue;
|
||||
const auto iter = m_unread.find(channel_id);
|
||||
if (iter == m_unread.end()) continue;
|
||||
|
@ -1393,6 +1396,9 @@ bool DiscordClient::GetUnreadStateForGuild(Snowflake id, int &total_mentions) co
|
|||
if (const auto iter = m_channel_muted_parent.find(channel_id); iter != m_channel_muted_parent.end())
|
||||
continue;
|
||||
|
||||
const auto channel = GetChannel(channel_id);
|
||||
if (channel.has_value() && !ShouldChannelTypeCountInUnread(channel->Type)) continue;
|
||||
|
||||
if (!has_any_unread && channel_unread > -1 && !IsChannelMuted(channel_id))
|
||||
has_any_unread = true;
|
||||
}
|
||||
|
@ -2753,6 +2759,14 @@ bool DiscordClient::CheckCode(const http::response_type &r, int expected) {
|
|||
return true;
|
||||
}
|
||||
|
||||
bool DiscordClient::ShouldChannelTypeCountInUnread(ChannelType type) {
|
||||
return type != ChannelType::GUILD_VOICE &&
|
||||
type != ChannelType::GUILD_FORUM &&
|
||||
type != ChannelType::GUILD_MEDIA &&
|
||||
type != ChannelType::GUILD_STORE &&
|
||||
type != ChannelType::GUILD_DIRECTORY;
|
||||
}
|
||||
|
||||
void DiscordClient::StoreMessageData(Message &msg) {
|
||||
const auto chan = m_store.GetChannel(msg.ChannelID);
|
||||
if (chan.has_value() && chan->GuildID.has_value())
|
||||
|
|
|
@ -321,6 +321,8 @@ private:
|
|||
|
||||
void StoreMessageData(Message &msg);
|
||||
|
||||
static bool ShouldChannelTypeCountInUnread(ChannelType type);
|
||||
|
||||
void HandleReadyReadState(const ReadyEventData &data);
|
||||
void HandleReadyGuildSettings(const ReadyEventData &data);
|
||||
|
||||
|
|
|
@ -638,16 +638,16 @@ std::vector<ChannelData> Store::GetActiveThreads(Snowflake channel_id) const {
|
|||
return ret;
|
||||
}
|
||||
|
||||
std::vector<Snowflake> Store::GetChannelIDsWithParentID(Snowflake channel_id) const {
|
||||
std::vector<std::pair<Snowflake, ChannelType>> Store::GetChannelIDsWithParentID(Snowflake channel_id) const {
|
||||
auto &s = m_stmt_get_chan_ids_parent;
|
||||
|
||||
s->Bind(1, channel_id);
|
||||
|
||||
std::vector<Snowflake> ret;
|
||||
std::vector<std::pair<Snowflake, ChannelType>> ret;
|
||||
while (s->FetchOne()) {
|
||||
Snowflake x;
|
||||
s->Get(0, x);
|
||||
ret.push_back(x);
|
||||
auto &p = ret.emplace_back();
|
||||
s->Get(0, p.first);
|
||||
s->Get(1, p.second);
|
||||
}
|
||||
|
||||
s->Reset();
|
||||
|
@ -2315,7 +2315,7 @@ bool Store::CreateStatements() {
|
|||
}
|
||||
|
||||
m_stmt_get_chan_ids_parent = std::make_unique<Statement>(m_db, R"(
|
||||
SELECT id FROM channels WHERE parent_id = ?
|
||||
SELECT id, type FROM channels WHERE parent_id = ?
|
||||
)");
|
||||
if (!m_stmt_get_chan_ids_parent->OK()) {
|
||||
fprintf(stderr, "failed to prepare get channel ids for parent statement: %s\n", m_db.ErrStr());
|
||||
|
|
|
@ -50,7 +50,7 @@ public:
|
|||
std::vector<Message> GetMessagesBefore(Snowflake channel_id, Snowflake message_id, size_t limit) const;
|
||||
std::vector<Message> GetPinnedMessages(Snowflake channel_id) const;
|
||||
std::vector<ChannelData> GetActiveThreads(Snowflake channel_id) const; // public
|
||||
std::vector<Snowflake> GetChannelIDsWithParentID(Snowflake channel_id) const;
|
||||
std::vector<std::pair<Snowflake, ChannelType>> GetChannelIDsWithParentID(Snowflake channel_id) const;
|
||||
std::unordered_set<Snowflake> GetMembersInGuild(Snowflake guild_id) const;
|
||||
// ^ not the same as GetUsersInGuild since users in a guild may include users who do not have retrieved member data
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user