Skip to content

Commit 3e8f225

Browse files
committed
Add method to get all available reception people
1 parent 1a5900a commit 3e8f225

5 files changed

Lines changed: 49 additions & 10 deletions

File tree

API.Test/MessagesTests.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,4 +61,17 @@ public void GetFullMessage()
6161
_ = msg.Result;
6262
return;
6363
}
64+
65+
[Test]
66+
public void GetReceptionPeople()
67+
{
68+
Client.LoginAsync(s_Server, s_LoginName, s_UserName, s_Password).Wait();
69+
70+
Task<KeyValuePair<string, MessagePerson[]>[]> people = Client.MessageClient.GetMessagePeopleAsync();
71+
people.Wait();
72+
if (people.Result.Length > 0)
73+
Assert.Pass();
74+
else
75+
Assert.Fail();
76+
}
6477
}

WebUntisAPI.Client/MessageClient.cs

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ public MessageClient(WebUntisClient client)
3535
/// </summary>
3636
/// <param name="ct">Cancellation token</param>
3737
/// <returns>The count of unread messages</returns>
38-
/// <exception cref="ObjectDisposedException">Thrown when the instance was disposed</exception>
39-
/// <exception cref="UnauthorizedAccessException">Thrown when you're logged in</exception>
38+
/// <exception cref="ObjectDisposedException">Thrown when the client instance was disposed</exception>
39+
/// <exception cref="UnauthorizedAccessException">Thrown when the client aren't logged in</exception>
4040
/// <exception cref="HttpRequestException">Thrown when an error happened while the http request</exception>
4141
public async Task<int> GetUnreadMessagesCountAsync(CancellationToken ct = default)
4242
{
@@ -49,8 +49,8 @@ public async Task<int> GetUnreadMessagesCountAsync(CancellationToken ct = defaul
4949
/// </summary>
5050
/// <param name="ct">Cancllation token</param>
5151
/// <returns></returns>
52-
/// <exception cref="ObjectDisposedException">Thrown when the instance was disposed</exception>
53-
/// <exception cref="UnauthorizedAccessException">Thrown when you're logged in</exception>
52+
/// <exception cref="ObjectDisposedException">Thrown when the client instance was disposed</exception>
53+
/// <exception cref="UnauthorizedAccessException">Thrown when the client aren't logged in</exception>
5454
/// <exception cref="HttpRequestException">Thrown when an error happened while the http request</exception>
5555
public async Task<MessagePermissions> GetMessagePermissionsAsync(CancellationToken ct = default)
5656
{
@@ -63,8 +63,8 @@ public async Task<MessagePermissions> GetMessagePermissionsAsync(CancellationTok
6363
/// </summary>
6464
/// <param name="ct">Cancellation token</param>
6565
/// <returns>The message previews</returns>
66-
/// <exception cref="ObjectDisposedException">Thrown when the instance was disposed</exception>
67-
/// <exception cref="UnauthorizedAccessException">Thrown when you're logged in</exception>
66+
/// <exception cref="ObjectDisposedException">Thrown when the client instance was disposed</exception>
67+
/// <exception cref="UnauthorizedAccessException">Thrown when the client aren't logged in</exception>
6868
/// <exception cref="HttpRequestException">Thrown when an error happened while the http request</exception>
6969
public async Task<MessagePreview[]> GetMessageInboxAsync(CancellationToken ct = default)
7070
{
@@ -73,5 +73,25 @@ public async Task<MessagePreview[]> GetMessageInboxAsync(CancellationToken ct =
7373
JArray jsonMsg = JObject.Parse(responseString).Value<JArray>("incomingMessages");
7474
return new JsonSerializer().Deserialize<List<MessagePreview>>(jsonMsg.CreateReader()).ToArray();
7575
}
76+
77+
/// <summary>
78+
/// Get all available reception people
79+
/// </summary>
80+
/// <param name="ct">Cancellation token</param>
81+
/// <returns>The people (<see cref="KeyValuePair{TKey, TValue}.Key"/> is the type of people that are contained in <see cref="KeyValuePair{TKey, TValue}.Value"/>)</returns>
82+
/// <exception cref="ObjectDisposedException">Thrown when the client instance was disposed</exception>
83+
/// <exception cref="UnauthorizedAccessException">Thrown when the client aren't logged in</exception>
84+
/// <exception cref="HttpRequestException">Thrown when an error happened while the http request</exception>
85+
public async Task<KeyValuePair<string, MessagePerson[]>[]> GetMessagePeopleAsync(CancellationToken ct = default)
86+
{
87+
string responseString = await _client.MakeAPIGetRequestAsync("/WebUntis/api/rest/view/v1/messages/recipients/static/persons", ct);
88+
89+
List<KeyValuePair<string, MessagePerson[]>> personTypes = new List<KeyValuePair<string, MessagePerson[]>>();
90+
JArray types = JArray.Parse(responseString);
91+
foreach (JObject personType in types.Cast<JObject>())
92+
personTypes.Add(new KeyValuePair<string, MessagePerson[]>(personType.Value<string>("type"),
93+
new JsonSerializer().Deserialize<List<MessagePerson>>(personType.Value<JArray>("persons").CreateReader()).ToArray()));
94+
return personTypes.ToArray();
95+
}
7696
}
7797
}

WebUntisAPI.Client/Models/Message.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public class Message
3636
/// The sender of the message
3737
/// </summary>
3838
[JsonProperty("sender")]
39-
public MessageProfile Sender { get; set; }
39+
public MessagePerson Sender { get; set; }
4040

4141
/// <summary>
4242
/// All the recipients for a message
@@ -45,7 +45,7 @@ public class Message
4545
/// When its <see langword="null"/> is the recipient the current user
4646
/// </remarks>
4747
[JsonProperty("recipients")]
48-
public List<MessageProfile> Recipients { get; set; } = null;
48+
public List<MessagePerson> Recipients { get; set; } = null;
4949

5050
/// <summary>
5151
/// The send time of the message

WebUntisAPI.Client/Models/MessageProfile.cs renamed to WebUntisAPI.Client/Models/MessagePerson.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,20 @@ namespace WebUntisAPI.Client.Models
1212
/// The user profile at untis messenges
1313
/// </summary>
1414
[DebuggerDisplay("{DisplayName, nq}")]
15-
public class MessageProfile
15+
public class MessagePerson
1616
{
1717
/// <summary>
1818
/// The name of the class from the user
1919
/// </summary>
2020
[JsonProperty("className")]
2121
public string ClassName { get; set; } = null;
2222

23+
/// <summary>
24+
/// Tags of the person
25+
/// </summary>
26+
[JsonProperty("tags")]
27+
public List<string> Tags { get; set; } = new List<string>();
28+
2329
/// <summary>
2430
/// The displayed name of the user
2531
/// </summary>

WebUntisAPI.Client/Models/MessagePreview.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public class MessagePreview
4242
/// The sender of the message
4343
/// </summary>
4444
[JsonProperty("sender")]
45-
public MessageProfile Sender { get; set; }
45+
public MessagePerson Sender { get; set; }
4646

4747
/// <summary>
4848
/// The send time of the message

0 commit comments

Comments
 (0)