forked from soxtoby/SlackNet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ConversationConversion.cs
48 lines (43 loc) · 1.65 KB
/
ConversationConversion.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
using System.Linq;
namespace SlackNet.Bot;
static class ConversationConversion
{
public static Hub ToHub(this Conversation conversation) =>
conversation.IsIm
? (Hub)conversation.ToIm()
: conversation.ToChannel();
public static Channel ToChannel(this Conversation conversation) =>
CopyHubProperties(conversation, new Channel
{
Name = conversation.Name,
Creator = conversation.Creator,
IsArchived = conversation.IsArchived,
Topic = conversation.Topic,
Purpose = conversation.Topic
});
public static Im ToIm(this Conversation conversation) =>
CopyHubProperties(conversation, new Im
{
User = conversation.User,
IsUserDeleted = conversation.IsUserDeleted
});
private static THub CopyHubProperties<THub>(Conversation conversation, THub hub)
where THub : Hub
{
hub.Id = conversation.Id;
hub.IsIm = conversation.IsIm;
hub.IsChannel = conversation.IsChannel;
hub.IsGroup = conversation.IsGroup;
hub.IsMpim = conversation.IsMpim;
hub.IsOrgShared = conversation.IsOrgShared;
hub.Created = conversation.Created;
hub.Members = conversation.Members.ToArray();
hub.LastRead = conversation.LastRead;
hub.Latest = conversation.Latest;
hub.UnreadCount = conversation.UnreadCount;
hub.UnreadCountDisplay = conversation.UnreadCountDisplay;
hub.IsGeneral = conversation.IsGeneral;
hub.IsMember = conversation.IsMember;
return hub;
}
}