Properly handle mutes (closes #6)

This commit is contained in:
Laura Hausmann 2023-01-18 03:52:51 +01:00
parent 57a2f8720b
commit 0cd33fa0a2
Signed by: zotan
GPG key ID: D044E84C5BE01605
2 changed files with 19 additions and 4 deletions

View file

@ -101,6 +101,21 @@ 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()
};
return client.GetScopeNotificationSettingsAsync(scope).Result.MuteFor != 0;
}
public static List<Chat> GetUnreadChats(bool all = false) {
var output = new List<Chat>();
@ -109,7 +124,7 @@ namespace tgcli {
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) && c.NotificationSettings.MuteFor == 0)
.Where(c => (c.UnreadCount > 0 || c.IsMarkedAsUnread) && !IsMuted(c))
.ToList());
return output;

View file

@ -553,7 +553,7 @@ namespace tgcli {
public static void AddMessageToQueue(Message msg) {
//handle muted
if (GetChat(msg.ChatId).NotificationSettings.MuteFor > 0 && currentChatId != msg.ChatId)
if (IsMuted(GetChat(msg.ChatId)) && currentChatId != msg.ChatId)
return;
//we aren't interested in backlog
@ -576,7 +576,7 @@ namespace tgcli {
public static void AddMessageToQueue(Update.UpdateMessageContent msg) {
//handle muted
if (GetChat(msg.ChatId).NotificationSettings.MuteFor > 0 && currentChatId != msg.ChatId || GetMessage(msg.ChatId, msg.MessageId).EditDate == 0)
if (IsMuted(GetChat(msg.ChatId)) && currentChatId != msg.ChatId || GetMessage(msg.ChatId, msg.MessageId).EditDate == 0)
return;
var formattedMessage = FormatMessage(msg);
@ -592,7 +592,7 @@ namespace tgcli {
public static void AddMessageToQueue(Update.UpdateMessageUnreadReactions msg) {
//handle muted
if (GetChat(msg.ChatId).NotificationSettings.MuteFor > 0 && currentChatId != msg.ChatId)
if (IsMuted(GetChat(msg.ChatId)) && currentChatId != msg.ChatId)
return;
if (!msg.UnreadReactions.Any(p => p.Type is ReactionType.ReactionTypeEmoji))