fix channels/supergroups
This commit is contained in:
parent
d4aee295a6
commit
d5bcd885dd
|
@ -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
|
||||
|
|
|
@ -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<Message> GetHistory(long chatId, int limit = 5, long fromMessageId = 0, int offset = 0, bool isSecret = false)
|
||||
public static List<Message> GetHistory(long chatId, int limit = 5, long fromMessageId = 0, int offset = 0,
|
||||
bool isSecret = false, bool skipTotal = false)
|
||||
{
|
||||
var history = new List<Message>();
|
||||
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 <count>");
|
||||
lock (@lock)
|
||||
messageQueue.Add($"{Ansi.Red}[tgcli] " +
|
||||
$"Limit cannot be less than one. Usage: /history <count>");
|
||||
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<Chat> 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<ConsoleKey> SpecialKeys = new List<ConsoleKey>
|
||||
{
|
||||
ConsoleKey.Backspace,
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue