Properly handle mutes (closes #6)
This commit is contained in:
parent
57a2f8720b
commit
0cd33fa0a2
|
@ -101,6 +101,21 @@ namespace tgcli {
|
||||||
|
|
||||||
return history;
|
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) {
|
public static List<Chat> GetUnreadChats(bool all = false) {
|
||||||
var output = new List<Chat>();
|
var output = new List<Chat>();
|
||||||
|
@ -109,7 +124,7 @@ namespace tgcli {
|
||||||
output.AddRange(all
|
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).ToList()
|
||||||
: response.ChatIds.Select(GetChat)
|
: 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());
|
.ToList());
|
||||||
|
|
||||||
return output;
|
return output;
|
||||||
|
|
|
@ -553,7 +553,7 @@ namespace tgcli {
|
||||||
|
|
||||||
public static void AddMessageToQueue(Message msg) {
|
public static void AddMessageToQueue(Message msg) {
|
||||||
//handle muted
|
//handle muted
|
||||||
if (GetChat(msg.ChatId).NotificationSettings.MuteFor > 0 && currentChatId != msg.ChatId)
|
if (IsMuted(GetChat(msg.ChatId)) && currentChatId != msg.ChatId)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
//we aren't interested in backlog
|
//we aren't interested in backlog
|
||||||
|
@ -576,7 +576,7 @@ namespace tgcli {
|
||||||
|
|
||||||
public static void AddMessageToQueue(Update.UpdateMessageContent msg) {
|
public static void AddMessageToQueue(Update.UpdateMessageContent msg) {
|
||||||
//handle muted
|
//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;
|
return;
|
||||||
|
|
||||||
var formattedMessage = FormatMessage(msg);
|
var formattedMessage = FormatMessage(msg);
|
||||||
|
@ -592,7 +592,7 @@ namespace tgcli {
|
||||||
|
|
||||||
public static void AddMessageToQueue(Update.UpdateMessageUnreadReactions msg) {
|
public static void AddMessageToQueue(Update.UpdateMessageUnreadReactions msg) {
|
||||||
//handle muted
|
//handle muted
|
||||||
if (GetChat(msg.ChatId).NotificationSettings.MuteFor > 0 && currentChatId != msg.ChatId)
|
if (IsMuted(GetChat(msg.ChatId)) && currentChatId != msg.ChatId)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (!msg.UnreadReactions.Any(p => p.Type is ReactionType.ReactionTypeEmoji))
|
if (!msg.UnreadReactions.Any(p => p.Type is ReactionType.ReactionTypeEmoji))
|
||||||
|
|
Loading…
Reference in a new issue