Properly handle mutes (closes #6)
This commit is contained in:
parent
57a2f8720b
commit
0cd33fa0a2
|
@ -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;
|
||||
|
|
|
@ -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))
|
||||
|
|
Loading…
Reference in a new issue