-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathLyncConversation.cs
160 lines (140 loc) · 4.74 KB
/
LyncConversation.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
using Microsoft.Lync.Model;
using Microsoft.Lync.Model.Conversation;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BusinessCats
{
public class LyncConversation
{
public void UpdateDesc()
{
desc = Describe(conversation);
}
public string Describe()
{
return Describe(conversation);
}
public static string Describe(Conversation conversation)
{
string people = "";
foreach (var participant in conversation.Participants)
{
if (participant.IsSelf)
{
continue;
}
var name = participant.Contact.GetContactInformation(ContactInformationType.DisplayName);
people += name.ToString() + "; ";
}
people = people.TrimEnd(';', ' ');
string subject = "";
{
object subjectObj;
if (conversation.Properties.TryGetValue(ConversationProperty.Subject, out subjectObj))
{
if (subjectObj is string)
{
subject = (string)subjectObj;
}
else
{
subject = subjectObj.ToString();
}
}
}
if (!string.IsNullOrEmpty(subject))
{
return $"{subject} ({people})";
}
else
{
return people;
}
}
public string DescribeAsTitle()
{
return DescribeAsTitle(conversation);
}
public static string DescribeAsTitle(Conversation conversation)
{
int participantCount = conversation.Participants.Count;
if (participantCount == 2)
{
foreach (var p in conversation.Participants)
{
if (p.IsSelf)
{
continue;
}
object val;
if (p.Properties.TryGetValue(ParticipantProperty.Name, out val) && val is string)
{
return val as string;
}
}
}
string participants = "";
{
string suffix = (participantCount == 1) ? "" : "s";
participants = $"({participantCount} Participant{suffix})";
}
string subject = "";
{
object subjectObj;
if (conversation.Properties.TryGetValue(ConversationProperty.Subject, out subjectObj))
{
if (subjectObj is string)
{
subject = (string)subjectObj;
}
else
{
subject = subjectObj.ToString();
}
}
}
if (string.IsNullOrEmpty(subject))
{
subject = "Conversation";
}
return $"{subject} {participants}";
}
// Subject can't be updated in new Meet Now conversation
// Subject can't be updated once conversation in progress
// Seems to only work for single-participant conversations, which then converts
// to normal conversation with the subject when more participants added... at
// which point you can't change the subject any more.
// ConversationManager.AddConversation is different than Meet Now
// a Conversation with only yourself will not work right
// a Conversation only shows up when a message is sent
public async static Task DoUpdateSubject(Conversation conversation, string subject)
{
try
{
await Task.Factory.FromAsync(conversation.BeginSetProperty, conversation.EndSetProperty, ConversationProperty.Subject, subject, conversation);
}
catch (Exception ex)
{
System.Diagnostics.Debug.Print(ex.ToString());
}
}
public string desc;
public Conversation conversation;
public Dictionary<Participant, LyncParticipant> participants;
public LyncParticipant FindParticipant(Participant participant)
{
if (participants.ContainsKey(participant))
{
return participants[participant];
}
return null;
}
public override string ToString()
{
return desc;
}
}
}