Skip to content

Commit

Permalink
Stop the speech if message gets deleted
Browse files Browse the repository at this point in the history
  • Loading branch information
Regynate committed Aug 1, 2023
1 parent 12a6f5e commit 670a290
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
5 changes: 5 additions & 0 deletions PickChatter/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ private void Application_Startup(object sender, StartupEventArgs e)
Invoke(() => SpeechManager.Instance.Speak(args.Message));
};

ChatterPicker.Instance.MessageDeleted += (_, args) =>
{
Invoke(() => SpeechManager.Instance.Stop());
};

ChatterPicker.Instance.ChatterChanged += (_, args) =>
{
Invoke(() => WebSocketServer.Instance.SendChatter(args.Chatter));
Expand Down
14 changes: 14 additions & 0 deletions PickChatter/ChatterPicker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,15 @@ private void NotifyChatterChanged()
NotifyMessageChanged();
}

private void NotifyMessageDeleted()
{
NotifyMessageChanged();
MessageDeleted?.Invoke(this, EventArgs.Empty);
}

public event EventHandler<MessageChangedEventArgs>? MessageChanged;
public event EventHandler<ChatterChangedEventArgs>? ChatterChanged;
public event EventHandler<EventArgs>? MessageDeleted;

private int processedMessagesCount = 0;

Expand Down Expand Up @@ -96,6 +103,7 @@ public void ClearChatters()
processedMessagesCount = 0;
currentChatter = null;
NotifyChatterChanged();
NotifyMessageDeleted();
}

private readonly Dictionary<string, Chatter> chatters = new();
Expand Down Expand Up @@ -124,9 +132,14 @@ private void OnMessageDeleted(string messageID)
if (chatter.RemoveMessage(messageID))
{
processedMessagesCount--;
if (chatter == currentChatter)
{
NotifyMessageDeleted();
}
return;
}
}

}

private void OnUserBanned(string username)
Expand All @@ -135,6 +148,7 @@ private void OnUserBanned(string username)
{
currentChatter = null;
NotifyChatterChanged();
NotifyMessageDeleted();
}

if (chatters.TryGetValue(username, out Chatter? chatter))
Expand Down
2 changes: 1 addition & 1 deletion PickChatter/PickChatter.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<ApplicationManifest></ApplicationManifest>
<Version>$(VersionPrefix)</Version>
<Authors>Reguas</Authors>
<AssemblyVersion>1.1.1</AssemblyVersion>
<AssemblyVersion>1.1.2</AssemblyVersion>
<Company>$(AssemblyName)</Company>
</PropertyGroup>

Expand Down

0 comments on commit 670a290

Please sign in to comment.