Skip to content

Commit

Permalink
Prepare for the next Funogram update
Browse files Browse the repository at this point in the history
  • Loading branch information
ForNeVeR committed Dec 31, 2023
1 parent b622f10 commit 7b79480
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 47 deletions.
10 changes: 6 additions & 4 deletions Emulsion.Telegram/Funogram.fs
Original file line number Diff line number Diff line change
Expand Up @@ -169,10 +169,12 @@ 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

Check failure on line 172 in Emulsion.Telegram/Funogram.fs

View workflow job for this annotation

GitHub Actions / main (ubuntu-22.04)

The type 'Message' does not define the field, constructor or member 'ForwardOrigin'.
| Some(User { SenderUser = user }) -> Some (getUserDisplayName user)

Check failure on line 173 in Emulsion.Telegram/Funogram.fs

View workflow job for this annotation

GitHub Actions / main (ubuntu-22.04)

The record label 'SenderUser' is not defined. Maybe you want one of the following:� SenderChat
| Some(HiddenUser { SenderUserName = name }) -> Some name
// TODO: For the last two, there's AuthorSignature field. Probably we should try using it?
| 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

Check failure on line 92 in Emulsion.Telegram/LinkGenerator.fs

View workflow job for this annotation

GitHub Actions / main (ubuntu-22.04)

The type 'Sticker' does not define the field, constructor or member 'Thumbnail'. Maybe you want one of the following:� Thumb

Check failure on line 92 in Emulsion.Telegram/LinkGenerator.fs

View workflow job for this annotation

GitHub Actions / main (ubuntu-22.04)

The type 'Sticker' does not define the field, constructor or member 'Thumbnail'. Maybe you want one of the following:� Thumb
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
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: 12 additions & 18 deletions Emulsion.Tests/Telegram/LinkGeneratorTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,10 @@ open System

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

open Emulsion.Database
open Emulsion.Settings
open Emulsion.Telegram
open Emulsion.TestFramework

let private hostingSettings = {
Expand Down Expand Up @@ -46,7 +44,7 @@ let private messageWithDocument =
Document = Some {
FileId = fileId1
FileUniqueId = fileId1
Thumb = None
Thumbnail = None
FileName = None
MimeType = None
FileSize = None
Expand All @@ -64,23 +62,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 +129,7 @@ let private messageWithAnimatedSticker =
height = 0,
isAnimated = true,
isVideo = false,
thumb = photo
thumbnail = photo
)
}

Expand All @@ -148,7 +142,7 @@ let private messageWithVideo =
Width = 0
Height = 0
Duration = 0
Thumb = None
Thumbnail = None
MimeType = None
FileSize = None
}
Expand All @@ -172,7 +166,7 @@ let private messageWithVideoNote =
FileUniqueId = fileId1
Length = 0
Duration = 0
Thumb = None
Thumbnail = None
FileSize = None
}
}
Expand Down

0 comments on commit 7b79480

Please sign in to comment.