From d5bcd885dd0ed490117095465d038a3da8d02c28 Mon Sep 17 00:00:00 2001 From: Laura Hausmann Date: Fri, 13 Dec 2019 17:16:55 +0100 Subject: [PATCH] fix channels/supergroups --- telegram/Command.cs | 14 +++++++------- telegram/Util.cs | 32 +++++++++++++++++++------------- telegram/tgcli.cs | 11 +++++++++-- 3 files changed, 35 insertions(+), 22 deletions(-) diff --git a/telegram/Command.cs b/telegram/Command.cs index 4a564a8..594fb73 100644 --- a/telegram/Command.cs +++ b/telegram/Command.cs @@ -112,6 +112,7 @@ namespace telegram else if (chat.UnreadCount > 0) { var unreads = GetHistory(chatId, chat.UnreadCount); + Console.WriteLine(unreads.Count); var rest = GetHistory(chatId, 5 - unreads.Count, unreads.First().Id); rest.ForEach(AddMessageToQueue); messageQueue.Add($"{Ansi.Yellow}[tgcli] ---UNREAD---"); @@ -273,7 +274,7 @@ namespace telegram { if (currentChatId == 0) return; //TODO: do something MarkUnread(currentChatId); - CommandManager.HandleCommand("close"); + CommandManager.HandleCommand("c"); } } @@ -444,17 +445,16 @@ namespace telegram { try { - - var message = inputParams.Aggregate((current, param) => current + " " + param).Trim(); - - if (currentChatId == 0) return; //TODO do something - - if (message.Length == 0) + if (inputParams.Count == 0) { currentInputLine = "/e " + ((TdApi.MessageContent.MessageText) lastMessage?.Content)?.Text?.Text; return; } + var message = inputParams.Aggregate((current, param) => current + " " + param).Trim(); + + if (currentChatId == 0) return; //TODO do something + if (lastMessage == null) { //try to find last message diff --git a/telegram/Util.cs b/telegram/Util.cs index 7bef3d1..5fd5efc 100644 --- a/telegram/Util.cs +++ b/telegram/Util.cs @@ -77,7 +77,6 @@ namespace telegram { var response = client.ExecuteAsync(new SearchChatMessages { - ChatId = chatId, Query = "+", Limit = 1 @@ -90,17 +89,23 @@ namespace telegram } } - public static List GetHistory(long chatId, int limit = 5, long fromMessageId = 0, int offset = 0, bool isSecret = false) + public static List GetHistory(long chatId, int limit = 5, long fromMessageId = 0, int offset = 0, + bool isSecret = false, bool skipTotal = false) { var history = new List(); var total = GetTotalMessages(chatId); - if (limit > total) limit = total; + var chat = GetChat(chatId); + if (chat.Type is ChatType.ChatTypeSupergroup || isSecret) + skipTotal = true; + if (limit > total && !skipTotal) limit = total; for (var i = 5; i > 0; i--) { if (limit <= 0) { - lock (@lock) messageQueue.Add($"{Ansi.Red}[tgcli] " + $"Limit cannot be less than one. Usage: /history "); + lock (@lock) + messageQueue.Add($"{Ansi.Red}[tgcli] " + + $"Limit cannot be less than one. Usage: /history "); return history; } @@ -124,6 +129,7 @@ namespace telegram history.Reverse(); return history; } + return history; } @@ -136,11 +142,11 @@ namespace telegram }).Result; return all ? response.ChatIds.Select(GetChat).Where(c => c.UnreadCount > 0 || c.IsMarkedAsUnread).ToList() - : response.ChatIds.Select(GetChat).Where(c => (c.UnreadCount > 0 || c.IsMarkedAsUnread) + : response.ChatIds.Select(GetChat).Where(c => (c.UnreadCount > 0 || c.IsMarkedAsUnread) && c.NotificationSettings.MuteFor == 0) .ToList(); } - + public static List GetSecretChats() { var response = client.ExecuteAsync(new GetChats @@ -150,7 +156,7 @@ namespace telegram }).Result; return response.ChatIds.Select(GetChat).Where(c => c.Type is ChatType.ChatTypeSecret).ToList(); } - + public static void CloseSecretChat(int secretChatId) { client.ExecuteAsync(new CloseSecretChat() @@ -158,7 +164,7 @@ namespace telegram SecretChatId = secretChatId }).Wait(); } - + public static Chat CreateSecretChat(int userId) { return client.ExecuteAsync(new CreateNewSecretChat @@ -166,7 +172,7 @@ namespace telegram UserId = userId }).Result; } - + public static void DeleteChatHistory(long chatId) { client.ExecuteAsync(new DeleteChatHistory @@ -176,7 +182,7 @@ namespace telegram Revoke = true }).Wait(); } - + public static SecretChat GetSecretChat(int secretChatId) { var response = client.ExecuteAsync(new GetSecretChat @@ -260,7 +266,7 @@ namespace telegram } } }).Result; - + return msg; } @@ -305,7 +311,7 @@ namespace telegram return 0; } } - + public static int SearchContacts(string query) { try @@ -371,7 +377,7 @@ namespace telegram output += (isRead ? Ansi.Green : Ansi.Red) + "r"; return output + $"{Ansi.ResetAll}]"; } - + public static readonly List SpecialKeys = new List { ConsoleKey.Backspace, diff --git a/telegram/tgcli.cs b/telegram/tgcli.cs index 1043e84..38009a3 100644 --- a/telegram/tgcli.cs +++ b/telegram/tgcli.cs @@ -28,11 +28,10 @@ namespace telegram * make Util.getActualStringWidth better * refactor everything * add option to disable terminal bell - * command /s /search -> list matching chats, option 1-n, archived, muted indicator + * command /s /search -> list matching chats, archived, muted indicator * mute,unmute chats * split with newline if received message enters next line * fix issues when current_input message is longer than term width (only show as much as fits?) - * photo/document/etc captions * photo download & show externally * publish AUR package * maybe cursor input nav (cmd+del, left/right, up for last inputs, etc) @@ -379,6 +378,14 @@ namespace telegram string text; if (msg.Content is Td.TdApi.MessageContent.MessageText messageText) text = messageText.Text.Text; + else if (msg.Content is Td.TdApi.MessageContent.MessagePhoto photo) + text = !string.IsNullOrWhiteSpace(photo.Caption.Text) + ? $"[unsupported {msg.Content.DataType}] {photo.Caption.Text}" + : $"[unsupported {msg.Content.DataType}]"; + else if (msg.Content is Td.TdApi.MessageContent.MessageDocument document) + text = !string.IsNullOrWhiteSpace(document.Caption.Text) + ? $"[unsupported {msg.Content.DataType}] {document.Caption.Text}" + : $"[unsupported {msg.Content.DataType}]"; else text = $"[unsupported {msg.Content.DataType}]"; var sender = GetUser(msg.SenderUserId);