remove online+typing indicators

This commit is contained in:
Laura Hausmann 2019-12-12 18:09:01 +01:00
parent 7761bbae24
commit e987f91678
Signed by: zotan
GPG key ID: 5EC1D38FFC321311
4 changed files with 12 additions and 42 deletions

View file

@ -3,6 +3,8 @@
<component name="ChangeListManager">
<list default="true" id="36e5cfaf-0aa9-4137-8110-a5678a9c5443" name="Default Changelist" comment="">
<change beforePath="$PROJECT_DIR$/.idea/.idea.tgcli/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/.idea.tgcli/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/telegram/Command.cs" beforeDir="false" afterPath="$PROJECT_DIR$/telegram/Command.cs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/telegram/Util.cs" beforeDir="false" afterPath="$PROJECT_DIR$/telegram/Util.cs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/telegram/tgcli.cs" beforeDir="false" afterPath="$PROJECT_DIR$/telegram/tgcli.cs" afterDir="false" />
</list>
<option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
@ -56,9 +58,9 @@
<option value="$PROJECT_DIR$/tgcli.core/tgcli.cs" />
<option value="$PROJECT_DIR$/tgcli.core/Util.cs" />
<option value="$PROJECT_DIR$/tgcli.core/Command.cs" />
<option value="$PROJECT_DIR$/telegram/Command.cs" />
<option value="$PROJECT_DIR$/telegram/Util.cs" />
<option value="$PROJECT_DIR$/telegram/tgcli.cs" />
<option value="$PROJECT_DIR$/telegram/Util.cs" />
<option value="$PROJECT_DIR$/telegram/Command.cs" />
</list>
</option>
</component>
@ -121,7 +123,7 @@
<workItem from="1575536474314" duration="39215000" />
<workItem from="1575724030612" duration="6335000" />
<workItem from="1575806456895" duration="35215000" />
<workItem from="1576149306510" duration="1602000" />
<workItem from="1576149306510" duration="2581000" />
</task>
<servers />
</component>

View file

@ -25,10 +25,7 @@ namespace telegram
currentChatId = 0;
currentChatUserId = 0;
currentUserOnline = false;
currentUserTyping = false;
currentUserRead = false;
ctsTyping?.Cancel();
var chat = getChat(chatId);
if (chat.Type is TdApi.ChatType.ChatTypePrivate privChat)
@ -69,7 +66,7 @@ namespace telegram
markRead(chat.Id, getHistory(chat.Id).First().Id);
var history = getHistory(currentChatId, 50);
var last = history.LastOrDefault(p => p.IsOutgoing);
var last = history.FirstOrDefault(p => p.IsOutgoing);
if (last == null)
{
currentUserRead = true;
@ -91,10 +88,7 @@ namespace telegram
if (split.Length != 1 || currentChatId == 0) return;
currentChatId = 0;
currentChatUserId = 0;
currentUserOnline = false;
currentUserTyping = false;
currentUserRead = false;
ctsTyping?.Cancel();
lastMessage = null;
prefix = "[tgcli";

View file

@ -262,12 +262,10 @@ namespace telegram
return input.Length;
}
public static string getFormattedStatus(bool isOnline, bool isRead, bool isTyping)
public static string getFormattedStatus(bool isRead)
{
var output = " ";
output += (isOnline ? Ansi.Green : Ansi.Red) + "o";
output += (isRead ? Ansi.Green : Ansi.Red) + "r";
output += (isTyping ? Ansi.Green : Ansi.Red) + "t";
return output + $"{Ansi.ResetAll}]";
}
}

View file

@ -42,11 +42,7 @@ namespace telegram
public static volatile string connectionState = "Connecting";
public static long currentChatId = 0;
public static volatile int currentChatUserId = 0;
public static volatile bool currentUserOnline;
public static volatile bool currentUserTyping;
public static volatile bool currentUserRead;
public static volatile CancellationTokenSource ctsTyping;
public static volatile Task typingTask;
public static volatile Td.TdApi.Message lastMessage;
public static volatile bool quitting;
public static volatile string currentInputLine = "";
@ -221,10 +217,6 @@ namespace telegram
case Td.TdApi.Update.UpdateMessageSendSucceeded sentMsg:
lastMessage = sentMsg.Message;
break;
case Td.TdApi.Update.UpdateUserStatus uStatus when uStatus.UserId == currentChatUserId:
currentUserOnline = uStatus.Status is Td.TdApi.UserStatus.UserStatusOnline;
ScreenUpdate();
break;
case Td.TdApi.Update.UpdateChatReadOutbox update:
if (lastMessage != null && lastMessage.ChatId == update.ChatId)
{
@ -232,21 +224,6 @@ namespace telegram
ScreenUpdate();
}
break;
case Td.TdApi.Update.UpdateUserChatAction action when action.Action is
Td.TdApi.ChatAction.ChatActionTyping && action.UserId == currentChatUserId
&& action.ChatId == currentChatUserId:
currentUserTyping = true;
ScreenUpdate();
ctsTyping?.Cancel();
ctsTyping = new CancellationTokenSource();
typingTask = new Task(() =>
{
Task.Delay(5000);
if (!ctsTyping.IsCancellationRequested)
currentUserTyping = false;
}, ctsTyping.Token);
typingTask.Start();
break;
case Td.TdApi.Update.UpdateConnectionState state:
switch (state.State)
{
@ -299,7 +276,7 @@ namespace telegram
if (messageQueue.Count > 0)
Console.Write("\a"); //ring terminal bell
messageQueue.Clear();
var status = getFormattedStatus(currentUserOnline, currentUserRead, currentUserTyping);
var status = getFormattedStatus(currentUserRead);
Console.Write(prefix
+ (connectionState == "Ready" ? "" : $" ({connectionState})")
+ (currentChatUserId != 0 ? status : "]") + " > " + currentInputLine);
@ -463,13 +440,12 @@ namespace telegram
var isPrivate = chat.Type is Td.TdApi.ChatType.ChatTypePrivate;
var isReply = msg.ReplyToMessageId != 0;
Td.TdApi.Message replyMessage;
var replyText = "";
var prefix = $"{Ansi.Bold}{Ansi.Green}[{time}] {Ansi.Cyan}{chat.Title} " +
var msgPrefix = $"{Ansi.Bold}{Ansi.Green}[{time}] {Ansi.Cyan}{chat.Title} " +
$"{(isPrivate || isChannel ? "" : $"{Ansi.Yellow}{username} ")}";
var finalOutput = prefix;
var finalOutput = msgPrefix;
var indent = new string(' ', getActualStringWidth(prefix));
var indent = new string(' ', getActualStringWidth(msgPrefix));
var arrows = $"{(msg.IsOutgoing ? $"{Ansi.Blue}»»»" : $"{Ansi.Magenta}«««")} ";
if (isReply)
@ -477,7 +453,7 @@ namespace telegram
try
{
replyMessage = getMessage(chat.Id, msg.ReplyToMessageId);
finalOutput = $"{FormatMessageReply(replyMessage, prefix)}";
finalOutput = $"{FormatMessageReply(replyMessage, msgPrefix)}";
}
catch
{