From 67f68a9f29d561acf997e1c0205e36642abf579a Mon Sep 17 00:00:00 2001 From: John Johansson <1345217+we4sz@users.noreply.github.com> Date: Sat, 31 Oct 2026 08:53:13 +0100 Subject: [PATCH] Adding UserTeam, SourceTeam, DisplayAsBot, MediaDisplayType and HasMoreShares to File --- SlackNet.Tests/Objects/FileTests.cs | 49 +++++++++++++++++++++++++++++ SlackNet/Objects/File.cs | 9 ++++++ 2 files changed, 58 insertions(+) create mode 100644 SlackNet.Tests/Objects/FileTests.cs diff --git a/SlackNet.Tests/Objects/FileTests.cs b/SlackNet.Tests/Objects/FileTests.cs new file mode 100644 index 00000000..f23c1a9f --- /dev/null +++ b/SlackNet.Tests/Objects/FileTests.cs @@ -0,0 +1,49 @@ +using EasyAssertions; +using Newtonsoft.Json; +using NUnit.Framework; + +namespace SlackNet.Tests.Objects; + +public class FileTests +{ + private JsonSerializerSettings _sut; + + [SetUp] + public void SetUp() + { + _sut = Default.JsonSettings(Default.SlackTypeResolver(Default.AssembliesContainingSlackTypes)).SerializerSettings; + } + + [Test] + public void File_FromSharedChannel_HasUserTeamAndSourceTeam() + { + var result = Deserialize(@"{ ""id"": ""F12345678"", ""user"": ""U12345678"", ""user_team"": ""T111"", ""source_team"": ""T222"" }"); + + result.UserTeam.ShouldBe("T111"); + result.SourceTeam.ShouldBe("T222"); + } + + [Test] + public void File_WithShareAndMediaFields_HasThem() + { + var result = Deserialize(@"{ ""id"": ""F12345678"", ""media_display_type"": ""unknown"", ""display_as_bot"": true, ""has_more_shares"": true }"); + + result.MediaDisplayType.ShouldBe("unknown"); + result.DisplayAsBot.ShouldBe(true); + result.HasMoreShares.ShouldBe(true); + } + + [Test] + public void File_WithoutThoseFields_HasDefaults() + { + var result = Deserialize(@"{ ""id"": ""F12345678"" }"); + + result.UserTeam.ShouldBeNull(); + result.SourceTeam.ShouldBeNull(); + result.MediaDisplayType.ShouldBeNull(); + result.DisplayAsBot.ShouldBe(false); + result.HasMoreShares.ShouldBe(false); + } + + private T Deserialize(string json) => JsonConvert.DeserializeObject(json, _sut); +} diff --git a/SlackNet/Objects/File.cs b/SlackNet/Objects/File.cs index fff89f6c..a83ee063 100644 --- a/SlackNet/Objects/File.cs +++ b/SlackNet/Objects/File.cs @@ -14,12 +14,19 @@ public class File public string Mimetype { get; set; } public string Filetype { get; set; } public string PrettyType { get; set; } + /// How the media should be displayed. + public string MediaDisplayType { get; set; } public string User { get; set; } + /// Team of the user who created the file. + public string UserTeam { get; set; } + /// Team where the file originated. + public string SourceTeam { get; set; } public string Mode { get; set; } public bool Editable { get; set; } public bool IsExternal { get; set; } public string ExternalType { get; set; } public string Username { get; set; } + public bool DisplayAsBot { get; set; } public int Size { get; set; } public string UrlPrivate { get; set; } public string UrlPrivateDownload { get; set; } @@ -50,6 +57,8 @@ public class File public bool IsStarred { get; set; } public string[] PinnedTo { get; set; } public bool SkippedShares { get; set; } + /// Whether there are additional shares not returned. + public bool HasMoreShares { get; set; } public FileShares Shares { get; set; } public IList TeamsSharedWith { get; set; } public bool IsRestrictedSharingEnabled { get; set; }