Fix channel default mute behavior (#6)

This commit is contained in:
Laura Hausmann 2023-01-18 04:02:17 +01:00
parent 0cd33fa0a2
commit bd4fd3ec36
Signed by: zotan
GPG key ID: D044E84C5BE01605

View file

@ -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;
}