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

Prepare for the next Funogram update #189

Merged
merged 5 commits into from
Feb 5, 2024
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: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
- name: Set up .NET SDK
uses: actions/setup-dotnet@v1
with:
dotnet-version: 7.0.x
dotnet-version: 8.0.x
- name: NuGet cache
uses: actions/cache@v3
with:
Expand Down
10 changes: 9 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic
Versioning v2.0.0](https://semver.org/spec/v2.0.0.html).

## [2.4.3] - 2024-02-06
### Changed
- **(Requirement update!)** Update to .NET 8.

### Fixed
- [#190](https://github.com/codingteam/emulsion/issues/190): a quotation message caused the bot to fail the parsing.

## [2.4.2] - 2023-07-07
### Fixed
- Message archive entries are stored by id in a stable way
Expand Down Expand Up @@ -177,4 +184,5 @@ runtime 2.2.
[2.4.0]: https://github.com/codingteam/emulsion/compare/v2.3.1...v2.4.0
[2.4.1]: https://github.com/codingteam/emulsion/compare/v2.4.0...v2.4.1
[2.4.2]: https://github.com/codingteam/emulsion/compare/v2.4.1...v2.4.2
[Unreleased]: https://github.com/codingteam/emulsion/compare/v2.4.2...HEAD
[2.4.3]: https://github.com/codingteam/emulsion/compare/v2.4.2...v2.4.3
[Unreleased]: https://github.com/codingteam/emulsion/compare/v2.4.3...HEAD
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build-env
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build-env

# Install Node.js 18
RUN curl -fsSL https://deb.nodesource.com/setup_18.x | bash - \
Expand All @@ -22,7 +22,7 @@ COPY . ./
RUN dotnet build Emulsion.MessageArchive.Frontend # required to publish the frontend resources
RUN dotnet publish Emulsion -c Release -o /app/out

FROM mcr.microsoft.com/dotnet/aspnet:7.0
FROM mcr.microsoft.com/dotnet/aspnet:8.0
WORKDIR /app
COPY --from=build-env /app/out .
ENTRYPOINT ["dotnet", "Emulsion.dll"]
2 changes: 1 addition & 1 deletion Emulsion.ContentProxy/Emulsion.ContentProxy.fsproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion Emulsion.Database/Emulsion.Database.fsproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.Build.NoTargets/3.7.0">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
Expand All @@ -19,7 +19,7 @@
<Exec Command="npm install" />
<Touch Files="$(IntermediateOutputPath)\npm-build.timestamp" AlwaysCreate="true" />
</Target>

<Target Name="NpmBuild" BeforeTargets="Build"
Inputs="@(Content)"
Outputs="bin\index.html">
Expand Down
2 changes: 1 addition & 1 deletion Emulsion.Messaging/Emulsion.Messaging.fsproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
</PropertyGroup>
<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion Emulsion.Settings/Emulsion.Settings.fsproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
</PropertyGroup>

Expand Down
6 changes: 3 additions & 3 deletions Emulsion.Telegram/Emulsion.Telegram.fsproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
</PropertyGroup>
<ItemGroup>
Expand All @@ -11,8 +11,8 @@
<Compile Include="Client.fs" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Funogram" Version="2.0.5" />
<PackageReference Include="Funogram.Telegram" Version="6.3.0" />
<PackageReference Include="Funogram" Version="2.0.10" />
<PackageReference Include="Funogram.Telegram" Version="7.0.0.2" />
<PackageReference Include="Serilog" Version="2.10.0" />
</ItemGroup>
<ItemGroup>
Expand Down
9 changes: 5 additions & 4 deletions Emulsion.Telegram/Funogram.fs
Original file line number Diff line number Diff line change
Expand Up @@ -169,10 +169,11 @@ module MessageConverter =
else Some (contentType, message.Caption)

let (|ForwardFrom|_|) (message: FunogramMessage) =
match message with
| { ForwardFrom = Some user } -> Some (getUserDisplayName user)
| { ForwardSenderName = Some sender } -> Some sender
| { ForwardFromChat = Some chat } -> Some (getChatDisplayName chat)
match message.ForwardOrigin with
| Some(User { SenderUser = user }) -> Some (getUserDisplayName user)
| Some(HiddenUser { SenderUserName = name }) -> Some name
| Some(MessageOrigin.Chat { SenderChat = chat }) -> Some (getChatDisplayName chat)
| Some(MessageOrigin.Channel { Chat = chat }) -> Some (getChatDisplayName chat)
| _ -> None

let appendLinkTo text =
Expand Down
22 changes: 11 additions & 11 deletions Emulsion.Telegram/LinkGenerator.fs
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ type private WithId<'T when 'T: (member FileId: string)> = 'T
type private WithFileName<'T when 'T: (member FileName: string option)> = 'T
type private WithMimeType<'T when 'T: (member MimeType: string option)> = 'T

let inline private extractFileInfo<'T
when WithId<'T>
and WithFileName<'T>
let inline private extractFileInfo<'T
when WithId<'T>
and WithFileName<'T>
and WithMimeType<'T>>
: 'T option -> FileInfo option =
Option.map(fun file -> {
Expand All @@ -51,19 +51,19 @@ let inline private extractFileInfo<'T
MimeType = file.MimeType
})

let inline private extractFileInfoWithName<'T
when WithId<'T>
and WithMimeType<'T>>
(fileName: string)
let inline private extractFileInfoWithName<'T
when WithId<'T>
and WithMimeType<'T>>
(fileName: string)
: 'T option -> FileInfo option =
Option.map(fun file -> {
FileId = file.FileId
FileName = Some fileName
MimeType = file.MimeType
})

let inline private extractFileInfoWithNameAndMimeType<'T when WithId<'T>>
(fileName: string)
let inline private extractFileInfoWithNameAndMimeType<'T when WithId<'T>>
(fileName: string)
(mimeType: string)
: 'T option -> FileInfo option =
Option.map(fun file -> {
Expand All @@ -89,14 +89,14 @@ let private extractStickerFileInfo: Sticker option -> FileInfo option =
Option.bind(fun sticker ->
if sticker.IsAnimated then
// We cannot to preview Telegram's .tgs stickers in browser, so return thumbnail
extractFileInfoWithNameAndMimeType "sticker.webp" "image/webp" sticker.Thumb
extractFileInfoWithNameAndMimeType "sticker.webp" "image/webp" sticker.Thumbnail
elif sticker.IsVideo then
extractFileInfoWithNameAndMimeType "sticker.webm" "video/webm" (Some sticker)
else
extractFileInfoWithNameAndMimeType "sticker.webp" "image/webp" (Some sticker)
)

let private getFileInfos(message: FunogramMessage): FileInfo seq =
let private getFileInfos(message: FunogramMessage): FileInfo seq =
Seq.choose id <| seq {
extractFileInfo message.Document
extractFileInfo message.Audio
Expand Down
2 changes: 1 addition & 1 deletion Emulsion.TestFramework/Emulsion.TestFramework.fsproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<OutputType>Library</OutputType>
</PropertyGroup>
Expand Down
2 changes: 1 addition & 1 deletion Emulsion.Tests/Emulsion.Tests.fsproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
Expand Down
44 changes: 30 additions & 14 deletions Emulsion.Tests/Telegram/FunogramTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,11 @@ let private createReplyMessage from text replyTo : Funogram.Telegram.Types.Messa
let private createForwardedMessage from (forwarded: Funogram.Telegram.Types.Message) =
{ defaultMessage with
From = Some from
ForwardFrom = forwarded.From
ForwardOrigin =
forwarded.From
|> Option.map (
fun u -> User(MessageOriginUser.Create(``type`` = "user", date = forwarded.Date, senderUser = u))
)
Text = forwarded.Text }

let private createStickerMessage from (emoji: string option) =
Expand Down Expand Up @@ -83,17 +87,13 @@ let private createPhoto() = [|
}
|]

let private createAnimation(): Animation = {
FileId = ""
FileUniqueId = ""
Width = 0
Height = 0
Duration = 0
Thumb = None
FileName = None
MimeType = None
FileSize = None
}
let private createAnimation() = Animation.Create(
fileId = "",
fileUniqueId = "",
width = 0L,
height = 0L,
duration = 0L
)

let private createMessageWithCaption from caption =
{ defaultMessage with
Expand Down Expand Up @@ -356,7 +356,15 @@ module ReadMessageTests =
[<Fact>]
let forwardFromHiddenUser(): unit =
let message = { createEmptyMessage forwardingUser with
ForwardSenderName = Some "Hidden user"
ForwardOrigin = Some(
HiddenUser(
MessageOriginHiddenUser.Create(
``type`` = "hidden_user",
date = DateTime.MinValue,
senderUserName = "Hidden user"
)
)
)
Text = Some "test" }

Assert.Equal(
Expand All @@ -367,7 +375,15 @@ module ReadMessageTests =
[<Fact>]
let forwardFromChat(): unit =
let message = { createEmptyMessage forwardingUser with
ForwardFromChat = Some currentChat
ForwardOrigin = Some(
MessageOrigin.Chat(
MessageOriginChat.Create(
``type`` = "chat",
date = DateTime.MinValue,
senderChat = currentChat
)
)
)
Text = Some "test" }

Assert.Equal(
Expand Down
30 changes: 13 additions & 17 deletions Emulsion.Tests/Telegram/LinkGeneratorTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

open System

open Emulsion.ContentProxy
open Funogram.Telegram.Types
open Serilog.Core
open Xunit

open Emulsion.ContentProxy
open Emulsion.Database
open Emulsion.Settings
open Emulsion.Telegram
Expand Down Expand Up @@ -46,7 +46,7 @@ let private messageWithDocument =
Document = Some {
FileId = fileId1
FileUniqueId = fileId1
Thumb = None
Thumbnail = None
FileName = None
MimeType = None
FileSize = None
Expand All @@ -64,23 +64,19 @@ let private messageWithAudio =
Title = None
MimeType = None
FileSize = None
Thumb = None
Thumbnail = None
}
}

let private messageWithAnimation =
{ messageTemplate with
Animation = Some {
FileId = fileId1
FileUniqueId = fileId1
Width = 0
Height = 0
Duration = 0
Thumb = None
FileName = None
MimeType = None
FileSize = None
}
Animation = Some <| Animation.Create(
fileId = fileId1,
fileUniqueId = fileId1,
width = 0L,
height = 0L,
duration = 0L
)
}

let private messageWithPhoto =
Expand Down Expand Up @@ -135,7 +131,7 @@ let private messageWithAnimatedSticker =
height = 0,
isAnimated = true,
isVideo = false,
thumb = photo
thumbnail = photo
)
}

Expand All @@ -148,7 +144,7 @@ let private messageWithVideo =
Width = 0
Height = 0
Duration = 0
Thumb = None
Thumbnail = None
MimeType = None
FileSize = None
}
Expand All @@ -172,7 +168,7 @@ let private messageWithVideoNote =
FileUniqueId = fileId1
Length = 0
Duration = 0
Thumb = None
Thumbnail = None
FileSize = None
}
}
Expand Down
2 changes: 1 addition & 1 deletion Emulsion.Web/Emulsion.Web.fsproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<OutputType>Library</OutputType>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions Emulsion/Emulsion.fsproj
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<Version>2.4.2</Version>
<TargetFramework>net8.0</TargetFramework>
<Version>2.4.3</Version>
</PropertyGroup>
<ItemGroup>
<Compile Include="Logging.fs" />
Expand Down
Loading
Loading