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
51 changes: 51 additions & 0 deletions SlackNet.Tests/Objects/UserTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,55 @@ public void Serialization_WorksCorrectlyForAvatarFields()
"https://secure.gravatar.com/avatar/invalid.jpg?s=24\u0026d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0008-24.png");

}

[Test]
public void Serialization_WorksCorrectlyForIsEmailConfirmed()
{
var settings = Default.JsonSettings(Default.SlackTypeResolver(Default.AssembliesContainingSlackTypes)).SerializerSettings;

var user = JsonConvert.DeserializeObject<User>(@"{ ""id"": ""U12345678"", ""is_email_confirmed"": true }", settings);

user.IsEmailConfirmed.ShouldBe(true);
}

[Test]
public void Serialization_WorksCorrectlyForWhoCanShareContactCard()
{
var settings = Default.JsonSettings(Default.SlackTypeResolver(Default.AssembliesContainingSlackTypes)).SerializerSettings;

var user = JsonConvert.DeserializeObject<User>(@"{ ""id"": ""U12345678"", ""who_can_share_contact_card"": ""EVERYONE"" }", settings);

user.WhoCanShareContactCard.ShouldBe("EVERYONE");
}

[Test]
public void Serialization_WorksCorrectlyForIsWorkflowBot()
{
var settings = Default.JsonSettings(Default.SlackTypeResolver(Default.AssembliesContainingSlackTypes)).SerializerSettings;

var user = JsonConvert.DeserializeObject<User>(@"{ ""id"": ""B12345678"", ""is_bot"": true, ""is_workflow_bot"": true }", settings);

user.IsWorkflowBot.ShouldBe(true);
}

[Test]
public void Serialization_WorksCorrectlyForDisplayNameNormalized()
{
var settings = Default.JsonSettings(Default.SlackTypeResolver(Default.AssembliesContainingSlackTypes)).SerializerSettings;

var user = JsonConvert.DeserializeObject<User>(@"{ ""id"": ""U12345678"", ""profile"": { ""display_name"": ""Zo\u00eb"", ""display_name_normalized"": ""Zo"" } }", settings);

user.Profile.DisplayNameNormalized.ShouldBe("Zo");
}

[Test]
public void Serialization_WorksCorrectlyForImage1024AndIsCustomImage()
{
var settings = Default.JsonSettings(Default.SlackTypeResolver(Default.AssembliesContainingSlackTypes)).SerializerSettings;

var user = JsonConvert.DeserializeObject<User>(@"{ ""id"": ""U12345678"", ""profile"": { ""image_1024"": ""https://avatars.slack-edge.com/profile_1024.png"", ""is_custom_image"": true } }", settings);

user.Profile.Image1024.ShouldBe("https://avatars.slack-edge.com/profile_1024.png");
user.Profile.IsCustomImage.ShouldBe(true);
}
}
6 changes: 6 additions & 0 deletions SlackNet/Objects/User.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,23 @@ public class User
public bool IsRestricted { get; set; }
public bool IsUltraRestricted { get; set; }
public bool IsBot { get; set; }
/// <summary>Whether this is a workflow bot user.</summary>
public bool IsWorkflowBot { get; set; }
public bool IsStranger { get; set; }
public int Updated { get; set; }
public bool IsAppUser { get; set; }
public bool IsInvitedUser { get; set; }
/// <summary>Whether the user's email address has been confirmed.</summary>
public bool IsEmailConfirmed { get; set; }
[JsonIgnore]
public DateTime UpdateTime => Updated.ToDateTime().GetValueOrDefault();
[JsonProperty("has_2fa")]
public bool Has2FA { get; set; }
public string TwoFactorType { get; set; }
public string Locale { get; set; }
public EnterpriseUser EnterpriseUser { get; set; }
/// <summary>Contact card sharing permission setting.</summary>
public string WhoCanShareContactCard { get; set; }

public override string ToString() => Link.User(Id).ToString();
}
7 changes: 7 additions & 0 deletions SlackNet/Objects/UserProfile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ public class UserProfile
public string RealName { get; set; }
public string RealNameNormalized { get; set; }
public string DisplayName { get; set; }
/// <summary>The <see cref="DisplayName"/> field, but with any non-Latin characters filtered out.</summary>
public string DisplayNameNormalized { get; set; }
public string Pronouns { get; set; }
public string Email { get; set; }
public string HuddleState { get; set; }
Expand All @@ -40,6 +42,11 @@ public class UserProfile
public string Image192 { get; set; }
[JsonProperty("image_512")]
public string Image512 { get; set; }
/// <summary>1024px profile image URL.</summary>
[JsonProperty("image_1024")]
public string Image1024 { get; set; }
/// <summary>Whether the user uploaded a custom profile image.</summary>
public bool IsCustomImage { get; set; }
[JsonConverter(typeof(IgnoreArrayConverter))] // Slack returns an empty array instead of an object if profile has been modified, but no custom fields have been set
public IDictionary<string, UserProfileField> Fields { get; set; } = new Dictionary<string, UserProfileField>();
}
Loading