From bd4fd3ec36177af147757d19715c55275a6af864 Mon Sep 17 00:00:00 2001 From: Laura Hausmann Date: Wed, 18 Jan 2023 04:02:17 +0100 Subject: [PATCH] Fix channel default mute behavior (#6) --- tgcli/Util.cs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/tgcli/Util.cs b/tgcli/Util.cs index 79ab9a7..cd09573 100644 --- a/tgcli/Util.cs +++ b/tgcli/Util.cs @@ -101,17 +101,19 @@ namespace tgcli { return history; } - + public static bool IsMuted(Chat c) { if (c.NotificationSettings.MuteFor == 0 && !c.NotificationSettings.UseDefaultMuteFor) return false; NotificationSettingsScope scope = c.Type switch { ChatType.ChatTypeBasicGroup => new NotificationSettingsScope.NotificationSettingsScopeGroupChats(), - ChatType.ChatTypeSupergroup => new NotificationSettingsScope.NotificationSettingsScopeGroupChats(), - ChatType.ChatTypePrivate => new NotificationSettingsScope.NotificationSettingsScopePrivateChats(), - ChatType.ChatTypeSecret => new NotificationSettingsScope.NotificationSettingsScopePrivateChats(), - _ => throw new ArgumentOutOfRangeException() + ChatType.ChatTypeSupergroup t => t.IsChannel + ? new NotificationSettingsScope.NotificationSettingsScopeChannelChats() + : new NotificationSettingsScope.NotificationSettingsScopeGroupChats(), + ChatType.ChatTypePrivate => new NotificationSettingsScope.NotificationSettingsScopePrivateChats(), + ChatType.ChatTypeSecret => new NotificationSettingsScope.NotificationSettingsScopePrivateChats(), + _ => throw new ArgumentOutOfRangeException() }; return client.GetScopeNotificationSettingsAsync(scope).Result.MuteFor != 0; @@ -123,9 +125,7 @@ namespace tgcli { var response = client.ExecuteAsync(new GetChats { Limit = int.MaxValue }).Result; output.AddRange(all ? response.ChatIds.Select(GetChat).Where(c => c.UnreadCount > 0 || c.IsMarkedAsUnread).ToList() - : response.ChatIds.Select(GetChat) - .Where(c => (c.UnreadCount > 0 || c.IsMarkedAsUnread) && !IsMuted(c)) - .ToList()); + : response.ChatIds.Select(GetChat).Where(c => (c.UnreadCount > 0 || c.IsMarkedAsUnread) && !IsMuted(c)).ToList()); return output; }