Fix crash when the local echo is send to the wrong channel.

This commit is contained in:
miterosan 2018-07-09 21:00:39 +02:00
parent f681ef41ac
commit ec914a5095
2 changed files with 7 additions and 5 deletions

View File

@ -29,7 +29,7 @@ public class Channel
public readonly Bindable<bool> Joined = new Bindable<bool>();
public TargetType Target { get; }
public bool ReadOnly { get; set; }
public bool ReadOnly => false; //todo not yet used.
public override string ToString() => Name;
[JsonProperty(@"name")]

View File

@ -93,9 +93,11 @@ public void PostMessage(string text, bool isAction = false)
if (CurrentChannel.Value == null)
return;
var currentChannel = CurrentChannel.Value;
if (!api.IsLoggedIn)
{
CurrentChannel.Value.AddNewMessages(new ErrorMessage("Please sign in to participate in chat!"));
currentChannel.AddNewMessages(new ErrorMessage("Please sign in to participate in chat!"));
return;
}
@ -109,15 +111,15 @@ public void PostMessage(string text, bool isAction = false)
Content = text
};
CurrentChannel.Value.AddLocalEcho(message);
currentChannel.AddLocalEcho(message);
var req = new PostMessageRequest(message);
req.Failure += exception =>
{
Logger.Error(exception, "Posting message failed.");
CurrentChannel.Value?.ReplaceMessage(message, null);
currentChannel.ReplaceMessage(message, null);
};
req.Success += m => CurrentChannel.Value?.ReplaceMessage(message, m);
req.Success += m => currentChannel.ReplaceMessage(message, m);
api.Queue(req);
}