Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(#102) Telegram, Messaging: extract to separate projects #162

Merged
merged 1 commit into from
Jul 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ WORKDIR /app
COPY ./Emulsion/Emulsion.fsproj ./Emulsion/
COPY ./Emulsion.ContentProxy/Emulsion.ContentProxy.fsproj ./Emulsion.ContentProxy/
COPY ./Emulsion.Database/Emulsion.Database.fsproj ./Emulsion.Database/
COPY ./Emulsion.Messaging/Emulsion.Messaging.fsproj ./Emulsion.Messaging/
COPY ./Emulsion.Settings/Emulsion.Settings.fsproj ./Emulsion.Settings/
COPY ./Emulsion.Telegram/Emulsion.Telegram.fsproj ./Emulsion.Telegram/
COPY ./Emulsion.Web/Emulsion.Web.fsproj ./Emulsion.Web/

RUN dotnet restore Emulsion
Expand Down
6 changes: 6 additions & 0 deletions Emulsion.Messaging/AssemblyInfo.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace Emulsion.Messaging

open System.Runtime.CompilerServices

[<assembly: InternalsVisibleTo("Emulsion.Tests")>]
()
16 changes: 16 additions & 0 deletions Emulsion.Messaging/Emulsion.Messaging.fsproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
</PropertyGroup>
<ItemGroup>
<Compile Include="AssemblyInfo.fs" />
<Compile Include="Message.fs" />
<Compile Include="MessageSender.fs" />
<Compile Include="MessageSystem.fs" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="FSharpx.Collections" Version="2.0.0" />
<PackageReference Include="Serilog" Version="2.10.0" />
</ItemGroup>
</Project>
2 changes: 1 addition & 1 deletion Emulsion/Message.fs → Emulsion.Messaging/Message.fs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Emulsion
namespace Emulsion.Messaging

[<Struct>]
type AuthoredMessage = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module Emulsion.MessageSender
module Emulsion.Messaging.MessageSender

open System
open System.Threading
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module Emulsion.MessageSystem
module Emulsion.Messaging.MessageSystem

open System
open System.Threading
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Emulsion
namespace Emulsion.Telegram

open System.Runtime.CompilerServices

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ namespace Emulsion.Telegram
open System.Threading

open Emulsion.Database
open Emulsion.MessageSystem
open Emulsion.Messaging.MessageSystem
open Emulsion.Settings

type Client(ctx: ServiceContext,
Expand Down
23 changes: 23 additions & 0 deletions Emulsion.Telegram/Emulsion.Telegram.fsproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
</PropertyGroup>
<ItemGroup>
<Compile Include="AssemblyInfo.fs" />
<Compile Include="Html.fs" />
<Compile Include="LinkGenerator.fs" />
<Compile Include="Funogram.fs" />
<Compile Include="Client.fs" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Funogram" Version="2.0.4" />
<PackageReference Include="Funogram.Telegram" Version="6.1.0.1" />
<PackageReference Include="Serilog" Version="2.10.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Emulsion.ContentProxy\Emulsion.ContentProxy.fsproj" />
<ProjectReference Include="..\Emulsion.Messaging\Emulsion.Messaging.fsproj" />
<ProjectReference Include="..\Emulsion.Settings\Emulsion.Settings.fsproj" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ open Funogram.Api
open Funogram.Types
open Serilog

open Emulsion
open Emulsion.Messaging
open Emulsion.Database
open Emulsion.Settings
open Emulsion.Telegram.LinkGenerator
Expand Down
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions Emulsion.Tests/Actors/Core.fs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ open Xunit.Abstractions

open Emulsion
open Emulsion.Actors
open Emulsion.Messaging
open Emulsion.Tests.TestUtils

type CoreTests(testOutput: ITestOutputHelper) as this =
Expand Down
3 changes: 2 additions & 1 deletion Emulsion.Tests/Actors/Telegram.fs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ open Xunit.Abstractions

open Emulsion
open Emulsion.Actors
open Emulsion.MessageSystem
open Emulsion.Messaging
open Emulsion.Messaging.MessageSystem
open Emulsion.Tests.TestUtils

type TelegramTest(testOutput: ITestOutputHelper) =
Expand Down
3 changes: 2 additions & 1 deletion Emulsion.Tests/Actors/Xmpp.fs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ open Xunit.Abstractions

open Emulsion
open Emulsion.Actors
open Emulsion.MessageSystem
open Emulsion.Messaging
open Emulsion.Messaging.MessageSystem
open Emulsion.Tests.TestUtils

type XmppTest(testOutput: ITestOutputHelper) =
Expand Down
4 changes: 2 additions & 2 deletions Emulsion.Tests/MessageSenderTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ open Serilog.Sinks.TestCorrelator
open Xunit
open Xunit.Abstractions

open Emulsion
open Emulsion.MessageSender
open Emulsion.Messaging
open Emulsion.Messaging.MessageSender
open Emulsion.Tests.TestUtils
open Emulsion.Tests.TestUtils.Waiter

Expand Down
7 changes: 4 additions & 3 deletions Emulsion.Tests/MessageSystemTests/MessageSystemBaseTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ open Xunit
open Xunit.Abstractions

open Emulsion
open Emulsion.MessageSystem
open Emulsion.Messaging
open Emulsion.Messaging.MessageSystem
open Emulsion.Tests.TestUtils
open Emulsion.Tests.TestUtils.Waiter

Expand Down Expand Up @@ -39,7 +40,7 @@ type MessageSystemBaseTests(testLogger: ITestOutputHelper) =
}
}
// Start the system but don't let it to start the internal loop yet:
MessageSystem.putMessage messageSystem msg
putMessage messageSystem msg

// No messages sent:
waitForItemCount buffer 1 shortTimeout |> Assert.False
Expand Down Expand Up @@ -76,7 +77,7 @@ type MessageSystemBaseTests(testLogger: ITestOutputHelper) =
buffer.Add m
}
}
MessageSystem.putMessage messageSystem msg
putMessage messageSystem msg

let messageReceiver = ignore
let runningSystem = Task.Run(fun () -> (messageSystem :> IMessageSystem).RunSynchronously messageReceiver)
Expand Down
5 changes: 2 additions & 3 deletions Emulsion.Tests/MessageSystemTests/WrapRunTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ open System.Threading
open Serilog.Core
open Xunit

open Emulsion
open Emulsion.MessageSystem
open Emulsion.Messaging.MessageSystem

let private performTest expectedStage runBody =
use cts = new CancellationTokenSource()
Expand All @@ -22,7 +21,7 @@ let private performTest expectedStage runBody =
}

try
Async.RunSynchronously(MessageSystem.wrapRun context run, cancellationToken = cts.Token)
Async.RunSynchronously(wrapRun context run, cancellationToken = cts.Token)
with
| :? OperationCanceledException -> ()

Expand Down
2 changes: 1 addition & 1 deletion Emulsion.Tests/Telegram/FunogramTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ open Funogram.Types
open Serilog.Core
open Xunit

open Emulsion
open Emulsion.Messaging
open Emulsion.Telegram
open Emulsion.Telegram.Funogram

Expand Down
3 changes: 2 additions & 1 deletion Emulsion.Tests/Xmpp/EmulsionXmppTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ open SharpXMPP.XMPP.Client.Elements
open Xunit
open Xunit.Abstractions

open Emulsion.Settings
open Emulsion
open Emulsion.Messaging
open Emulsion.Settings
open Emulsion.Tests.TestUtils
open Emulsion.Tests.Xmpp
open Emulsion.Xmpp
Expand Down
6 changes: 3 additions & 3 deletions Emulsion.Tests/Xmpp/SharpXmppHelperTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ open SharpXMPP.XMPP
open SharpXMPP.XMPP.Client.Elements
open Xunit

open Emulsion
open Emulsion.Xmpp.SharpXmppHelper.Attributes
open Emulsion.Xmpp.SharpXmppHelper.Elements
open Emulsion.Messaging
open Emulsion.Tests.Xmpp
open Emulsion.Xmpp
open Emulsion.Xmpp.SharpXmppHelper.Attributes
open Emulsion.Xmpp.SharpXmppHelper.Elements

[<Fact>]
let ``Message body has a proper namespace``() =
Expand Down
12 changes: 12 additions & 0 deletions Emulsion.sln
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "Emulsion.Web", "Emulsion.We
EndProject
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "Emulsion.Settings", "Emulsion.Settings\Emulsion.Settings.fsproj", "{88331E40-EF70-4AF1-99CA-8A849208CAB7}"
EndProject
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "Emulsion.Telegram", "Emulsion.Telegram\Emulsion.Telegram.fsproj", "{D21E6DD6-35A8-430B-9719-E044197650A2}"
EndProject
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "Emulsion.Messaging", "Emulsion.Messaging\Emulsion.Messaging.fsproj", "{C8DC4049-250B-4E84-BC98-CFC0AF1632AF}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -77,6 +81,14 @@ Global
{88331E40-EF70-4AF1-99CA-8A849208CAB7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{88331E40-EF70-4AF1-99CA-8A849208CAB7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{88331E40-EF70-4AF1-99CA-8A849208CAB7}.Release|Any CPU.Build.0 = Release|Any CPU
{D21E6DD6-35A8-430B-9719-E044197650A2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D21E6DD6-35A8-430B-9719-E044197650A2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D21E6DD6-35A8-430B-9719-E044197650A2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D21E6DD6-35A8-430B-9719-E044197650A2}.Release|Any CPU.Build.0 = Release|Any CPU
{C8DC4049-250B-4E84-BC98-CFC0AF1632AF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C8DC4049-250B-4E84-BC98-CFC0AF1632AF}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C8DC4049-250B-4E84-BC98-CFC0AF1632AF}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C8DC4049-250B-4E84-BC98-CFC0AF1632AF}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{7D1ADF47-BF1C-4007-BB9B-08C283044467} = {973131E1-E645-4A50-A0D2-1886A1A8F0C6}
Expand Down
2 changes: 1 addition & 1 deletion Emulsion/Actors/Core.fs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module Emulsion.Actors.Core
open Akka.Actor
open Serilog

open Emulsion
open Emulsion.Messaging

type CoreActor(logger: ILogger, factories: ActorFactories) as this =
inherit ReceiveActor()
Expand Down
6 changes: 3 additions & 3 deletions Emulsion/Actors/Telegram.fs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
open Akka.Actor
open Serilog

open Emulsion
open Emulsion.MessageSystem
open Emulsion.Messaging
open Emulsion.Messaging.MessageSystem

type TelegramActor(logger: ILogger, telegram: IMessageSystem) as this =
inherit ReceiveActor()
do logger.Information("Telegram actor starting ({Path})…", this.Self.Path)
do this.Receive<OutgoingMessage>(MessageSystem.putMessage telegram)
do this.Receive<OutgoingMessage>(putMessage telegram)

let spawn (logger: ILogger) (telegram: IMessageSystem) (factory: IActorRefFactory) (name: string): IActorRef =
logger.Information("Telegram actor spawning…")
Expand Down
6 changes: 3 additions & 3 deletions Emulsion/Actors/Xmpp.fs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ module Emulsion.Actors.Xmpp
open Akka.Actor
open Serilog

open Emulsion
open Emulsion.MessageSystem
open Emulsion.Messaging
open Emulsion.Messaging.MessageSystem

type XmppActor(logger: ILogger, xmpp: IMessageSystem) as this =
inherit ReceiveActor()
do logger.Information("XMPP actor starting ({Path})…", this.Self.Path)
do this.Receive<OutgoingMessage>(MessageSystem.putMessage xmpp)
do this.Receive<OutgoingMessage>(putMessage xmpp)

let spawn (logger: ILogger)
(xmpp: IMessageSystem)
Expand Down
13 changes: 2 additions & 11 deletions Emulsion/Emulsion.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,9 @@
<Version>2.0.2</Version>
</PropertyGroup>
<ItemGroup>
<Compile Include="AssemblyInfo.fs" />
<Compile Include="Message.fs" />
<Compile Include="MessageSender.fs" />
<Compile Include="MessageSystem.fs" />
<Compile Include="Logging.fs" />
<Compile Include="Lifetimes.fs" />
<Compile Include="ExceptionUtils.fs" />
<Compile Include="Telegram\Html.fs" />
<Compile Include="Telegram\LinkGenerator.fs" />
<Compile Include="Telegram\Funogram.fs" />
<Compile Include="Telegram\Client.fs" />
<Compile Include="Xmpp\Types.fs" />
<Compile Include="Xmpp/SharpXmppHelper.fs" />
<Compile Include="Xmpp\XmppClient.fs" />
Expand All @@ -32,9 +24,6 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Akka" Version="1.3.12" />
<PackageReference Include="FSharpx.Collections" Version="2.0.0" />
<PackageReference Include="Funogram" Version="2.0.4" />
<PackageReference Include="Funogram.Telegram" Version="6.1.0.1" />
<PackageReference Include="JetBrains.Lifetimes" Version="2020.2.2" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="5.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="5.0.0" />
Expand All @@ -45,6 +34,8 @@
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Emulsion.ContentProxy\Emulsion.ContentProxy.fsproj" />
<ProjectReference Include="..\Emulsion.Messaging\Emulsion.Messaging.fsproj" />
<ProjectReference Include="..\Emulsion.Telegram\Emulsion.Telegram.fsproj" />
<ProjectReference Include="..\Emulsion.Web\Emulsion.Web.fsproj" />
</ItemGroup>
</Project>
2 changes: 1 addition & 1 deletion Emulsion/Program.fs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ open Serilog

open Emulsion.Actors
open Emulsion.Database
open Emulsion.MessageSystem
open Emulsion.Messaging.MessageSystem
open Emulsion.Settings
open Emulsion.Web
open Emulsion.Xmpp
Expand Down
5 changes: 3 additions & 2 deletions Emulsion/Xmpp/EmulsionXmpp.fs
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@ open Serilog
open SharpXMPP.XMPP

open Emulsion
open Emulsion.Messaging
open Emulsion.Messaging.MessageSystem
open Emulsion.Settings
open Emulsion.MessageSystem
open Emulsion.Xmpp.XmppClient

let private shouldProcessMessage (settings: XmppSettings) message =
let isGroup = SharpXmppHelper.isGroupChatMessage message
let shouldSkip = lazy (
SharpXmppHelper.isOwnMessage (settings.Nickname) message
SharpXmppHelper.isOwnMessage settings.Nickname message
|| SharpXmppHelper.isHistoricalMessage message
|| SharpXmppHelper.isEmptyMessage message
)
Expand Down
2 changes: 1 addition & 1 deletion Emulsion/Xmpp/SharpXmppHelper.fs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ open SharpXMPP.XMPP
open SharpXMPP.XMPP.Client.Elements
open SharpXMPP.XMPP.Client.MUC.Bookmarks.Elements

open Emulsion
open Emulsion.Messaging
open Emulsion.Xmpp

module Namespaces =
Expand Down
4 changes: 2 additions & 2 deletions Emulsion/Xmpp/XmppMessageSystem.fs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ open System.Threading

open JetBrains.Lifetimes

open Emulsion
open Emulsion.MessageSystem
open Emulsion.Messaging
open Emulsion.Messaging.MessageSystem
open Emulsion.Settings

type XmppMessageSystem(ctx: ServiceContext, cancellationToken: CancellationToken, settings: XmppSettings) =
Expand Down