diff --git a/MattermostApi/ApiEntry.cs b/MattermostApi/ApiEntry.cs index 9217963..dfeb421 100644 --- a/MattermostApi/ApiEntry.cs +++ b/MattermostApi/ApiEntry.cs @@ -12,16 +12,16 @@ public class UnixMsecDateTimeConverter : Newtonsoft.Json.JsonConverter { static readonly DateTime epoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc); public override bool CanConvert(Type objectType) { - return objectType == typeof(DateTime); + return objectType == typeof(DateTime) || objectType == typeof(DateTime?); } public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { - var t = (long)reader.Value; - return t == 0 ? DateTime.MinValue : epoch.AddMilliseconds(t); + var t = (long?)reader.Value; + return t == null ? (DateTime?)null : t == 0 ? DateTime.MinValue : epoch.AddMilliseconds((long)t); } public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) { - long msec = value == null ? 0 : (long)((DateTime)value - epoch).TotalMilliseconds; + long? msec = value == null ? (long?)null : (long)((DateTime)value - epoch).TotalMilliseconds; writer.WriteValue(msec); } } @@ -253,7 +253,9 @@ public IEnumerable All(Api api) { /// Override for the odd list return that doesn't use pages. /// public virtual ApiList Convert(JObject j) { - return j.ConvertToObject>(); + ApiList result = j.ConvertToObject>(); + result.Request = Request; + return result; } } diff --git a/MattermostApi/MattermostApi.csproj b/MattermostApi/MattermostApi.csproj index c0a2a0f..fa23bba 100644 --- a/MattermostApi/MattermostApi.csproj +++ b/MattermostApi/MattermostApi.csproj @@ -12,8 +12,8 @@ https://github.com/nikkilocke/MattermostApi https://github.com/nikkilocke/MattermostApi GitHub - Added static AddUser methods to Team and Channel - 1.0.6 + Fixed bug in ApiList + 1.0.10 diff --git a/MattermostApi/User.cs b/MattermostApi/User.cs index f71f33d..067558b 100644 --- a/MattermostApi/User.cs +++ b/MattermostApi/User.cs @@ -45,9 +45,9 @@ public class SearchUsersQuery : ListRequest { public class TeamForUser : ApiEntryBase { public string id; - public DateTime create_at; - public DateTime update_at; - public DateTime delete_at; + public DateTime? create_at; + public DateTime? update_at; + public DateTime? delete_at; public string display_name; public string name; public string description; @@ -55,7 +55,7 @@ public class TeamForUser : ApiEntryBase { public string type; public string allowed_domains; public string invite_id; - public bool allow_open_invite; + public bool? allow_open_invite; public string company_name; public string scheme_id; public string group_constrained; @@ -78,25 +78,41 @@ public class UserCreateInfo : ApiEntryBase { public NotifyProps notify_props; } + public class Preference : ApiEntryBase { + public string user_id; + public string category; + public string name; + public string value; + + public Preference() { + } + + public Preference(string category, string name, string value) { + this.category = category; + this.name = name; + this.value = value; + } + } + public class User : ApiEntryWithId { public string username; public string first_name; public string last_name; public string nickname; public string email; - public bool email_verified; + public bool? email_verified; public string auth_service; public string roles; public string locale; public NotifyProps notify_props; public JToken props; - public DateTime last_password_update; - public DateTime last_picture_update; - public int failed_attempts; - public bool mfa_active; + public DateTime? last_password_update; + public DateTime? last_picture_update; + public int? failed_attempts; + public bool? mfa_active; public TimeZone timezone; public string terms_of_service_id; - public DateTime terms_of_service_create_at; + public DateTime? terms_of_service_create_at; public static async Task> GetAll(Api api, GetUsersQuery query = null) { return await api.GetAsync>("users", query); @@ -162,5 +178,13 @@ public async Task> ChannelsForTeam(Api api, string team_id) { public async Task GetUnreadMessages(Api api, string channel_id) { return await api.GetAsync(Api.Combine("users", id, "channels", channel_id, "unread")); } + + static public async Task SetPreference(Api api, string user_id, params Preference [] preferences) { + foreach (Preference p in preferences) + p.user_id = user_id; + await api.PutAsync(Api.Combine("users", user_id, "preferences"), null, preferences); + } + + } }