Skip to content
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
62 changes: 62 additions & 0 deletions SlackNet.Tests/Objects/ConversationTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
using EasyAssertions;
using Newtonsoft.Json;
using NUnit.Framework;

namespace SlackNet.Tests.Objects;

public class ConversationTests
{
private JsonSerializerSettings _sut;

[SetUp]
public void SetUp()
{
_sut = Default.JsonSettings(Default.SlackTypeResolver(Default.AssembliesContainingSlackTypes)).SerializerSettings;
}

[Test]
public void Conversation_DirectMessage_HasContextTeamIdUpdatedAndIsOpen()
{
var result = Deserialize<Conversation>(@"{ ""id"": ""D12345678"", ""created"": 1788600021, ""updated"": 1788600021450, ""is_im"": true, ""is_open"": true, ""context_team_id"": ""T12345678"", ""user"": ""U12345678"" }");

result.ContextTeamId.ShouldBe("T12345678");
result.Updated.ShouldBe(1788600021450);
result.IsOpen.ShouldBe(true);
}

[Test]
public void Conversation_WithoutThoseFields_HasDefaults()
{
var result = Deserialize<Conversation>(@"{ ""id"": ""C12345678"", ""is_channel"": true }");

result.ContextTeamId.ShouldBeNull();
result.Updated.ShouldBe(0L);
result.IsOpen.ShouldBe(false);
}

[Test]
public void Conversation_SharedChannel_HasFrozenStateAndTeamIds()
{
var result = Deserialize<Conversation>(@"{ ""id"": ""C12345678"", ""is_ext_shared"": true, ""is_frozen"": true, ""shared_team_ids"": [""T111"", ""T222""], ""internal_team_ids"": [""T111""], ""connected_team_ids"": [""T333""], ""pending_connected_team_ids"": [""T444""] }");

result.IsFrozen.ShouldBe(true);
result.SharedTeamIds.ShouldMatch(["T111", "T222"]);
result.InternalTeamIds.ShouldMatch(["T111"]);
result.ConnectedTeamIds.ShouldMatch(["T333"]);
result.PendingConnectedTeamIds.ShouldMatch(["T444"]);
}

[Test]
public void Conversation_NotShared_HasNoTeamIds()
{
var result = Deserialize<Conversation>(@"{ ""id"": ""C12345678"", ""is_channel"": true }");

result.IsFrozen.ShouldBe(false);
result.SharedTeamIds.ShouldBeEmpty();
result.InternalTeamIds.ShouldBeEmpty();
result.ConnectedTeamIds.ShouldBeEmpty();
result.PendingConnectedTeamIds.ShouldBeEmpty();
}

private T Deserialize<T>(string json) => JsonConvert.DeserializeObject<T>(json, _sut);
}
40 changes: 40 additions & 0 deletions SlackNet/Objects/Conversation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ public class Conversation
[JsonIgnore]
public DateTime CreatedDate => Created.ToDateTime().GetValueOrDefault();

/// <summary>
/// The timestamp, in milliseconds (not seconds like <see cref="Created"/>), when the channel settings were updated - for example, the "topic" or "description" of the channel changed.
/// </summary>
public long Updated { get; set; }

/// <summary>
/// The user ID of the member that created this channel.
/// </summary>
Expand All @@ -49,11 +54,21 @@ public class Conversation
/// </summary>
public string ConversationHostId { get; set; }

/// <summary>
/// The ID of the workspace the conversation is within.
/// </summary>
public string ContextTeamId { get; set; }

/// <summary>
/// Indicates a conversation is archived. Frozen in time.
/// </summary>
public bool IsArchived { get; set; }

/// <summary>
/// Whether the conversation is frozen (e.g. a disconnected Slack Connect channel becomes a read-only frozen copy on the away-team side).
/// </summary>
public bool IsFrozen { get; set; }

/// <summary>
/// Means the channel is the workspace's "general" discussion channel (even if it's not named #general but it might be anyway).
/// That might be important to your app because almost every user is a member.
Expand Down Expand Up @@ -85,6 +100,26 @@ public class Conversation

public object[] PendingShared { get; set; }

/// <summary>
/// IDs of workspaces the channel is shared with.
/// </summary>
public IList<string> SharedTeamIds { get; set; } = [];

/// <summary>
/// Internal team IDs for shared channels.
/// </summary>
public IList<string> InternalTeamIds { get; set; } = [];

/// <summary>
/// Connected external team IDs.
/// </summary>
public IList<string> ConnectedTeamIds { get; set; } = [];

/// <summary>
/// Pending connected team IDs.
/// </summary>
public IList<string> PendingConnectedTeamIds { get; set; } = [];

/// <summary>
/// Is intriguing. It means the conversation is ready to become an <see cref="IsExtShared"/> channel but isn't quite ready yet
/// and needs some kind of approval or sign off. Best to treat it as if it were a shared channel, even if it traverses only one workspace.
Expand All @@ -106,6 +141,11 @@ public class Conversation
/// </summary>
public bool IsMpim { get; set; }

/// <summary>
/// Whether a DM is open; this field is DM/MPIM-specific.
/// </summary>
public bool IsOpen { get; set; }

/// <summary>
/// The timestamp for the last message the calling user has read in this channel.
/// </summary>
Expand Down
Loading