1
1
using System . Linq ;
2
2
using Outlook = Microsoft . Office . Interop . Outlook ;
3
3
using System . Text . RegularExpressions ;
4
+ using System . Threading . Tasks ;
5
+ using System . Windows . Forms ;
4
6
5
7
namespace JitsiMeetOutlook
6
8
{
@@ -14,16 +16,89 @@ private void initialise()
14
16
// Set language
15
17
setLanguage ( ) ;
16
18
19
+ // Assign the domain prevailing at appointment item launch
20
+ Properties . Settings . Default . Reload ( ) ;
21
+ oldDomain = Properties . Settings . Default . Domain ;
22
+
17
23
// Assign the relevant appointment item
18
24
Outlook . Inspector inspector = ( Outlook . Inspector ) this . Context ;
19
25
appointmentItem = inspector . CurrentItem as Outlook . AppointmentItem ;
20
26
21
- // Assign the domain prevailing at appointment item launch
22
- Properties . Settings . Default . Reload ( ) ;
23
- oldDomain = Properties . Settings . Default . Domain ;
27
+ // Display Ribbon if this is a Jitsi Meeting
28
+ MessageBox . Show ( "DEBUG: " + appointmentItem . Location ) ;
29
+
30
+ if ( appointmentItem . Location == "Jitsi Meet" )
31
+ {
32
+ groupJitsiMeetControls . Visible = true ;
33
+ groupNewMeeting . Visible = false ;
34
+ InitializeRibbonWithCurrentData ( ) ;
35
+ }
36
+ else
37
+ {
38
+ groupNewMeeting . Visible = true ;
39
+ groupJitsiMeetControls . Visible = false ;
40
+ }
41
+
42
+
24
43
}
25
44
26
- public void setRoomId ( string newRoomId )
45
+
46
+ private void InitializeRibbonWithCurrentData ( )
47
+ {
48
+ var roomId = Utils . findRoomId ( appointmentItem . Body , oldDomain ) ;
49
+ if ( roomId != string . Empty )
50
+ {
51
+ // The Meeting already exists
52
+ // TODO: Not working correctly because edited body are in RTF Format
53
+ // Update Conrol State from the embedded text
54
+ setRoomIdText ( roomId ) ;
55
+
56
+ var url = Utils . GetUrl ( appointmentItem . Body , oldDomain ) ;
57
+ if ( Utils . SettingIsActive ( url , "requireDisplayName" ) )
58
+ {
59
+ buttonRequireDisplayName . Checked = true ;
60
+ }
61
+ if ( Utils . SettingIsActive ( url , "startWithAudioMuted" ) )
62
+ {
63
+ buttonStartWithAudioMuted . Checked = true ;
64
+ }
65
+ if ( Utils . SettingIsActive ( url , "startWithVideoMuted" ) )
66
+ {
67
+ buttonStartWithVideoMuted . Checked = true ;
68
+ }
69
+
70
+ }
71
+ else
72
+ {
73
+ // New Meeting
74
+ if ( Properties . Settings . Default . roomID . Length == 0 )
75
+ {
76
+ randomiseRoomId ( ) ;
77
+ }
78
+ else
79
+ {
80
+ setRoomId ( Properties . Settings . Default . roomID ) ;
81
+ }
82
+ if ( Properties . Settings . Default . requireDisplayName )
83
+ {
84
+ toggleRequireName ( ) ;
85
+ buttonRequireDisplayName . Checked = true ;
86
+ }
87
+ if ( Properties . Settings . Default . startWithAudioMuted )
88
+ {
89
+ toggleMuteOnStart ( ) ;
90
+ buttonStartWithAudioMuted . Checked = true ;
91
+ }
92
+ if ( Properties . Settings . Default . startWithVideoMuted )
93
+ {
94
+ toggleVideoOnStart ( ) ;
95
+ buttonStartWithVideoMuted . Checked = true ;
96
+ }
97
+ }
98
+
99
+ }
100
+
101
+ public async void setRoomId ( string newRoomId )
27
102
{
28
103
string newDomain = JitsiUrl . getDomain ( ) ;
29
104
string oldBody = appointmentItem . Body ;
@@ -35,51 +110,45 @@ public void setRoomId(string newRoomId)
35
110
try
36
111
{
37
112
// Replace old domain for new domain
38
- newBody = oldBody . Replace ( findRoomId ( ) , newRoomIdLegal ) ;
113
+ newBody = oldBody . Replace ( Utils . findRoomId ( appointmentItem . Body , oldDomain ) , newRoomIdLegal ) ;
39
114
newBody = newBody . Replace ( oldDomain , newDomain ) ;
115
+ newBody = await generateBody ( newRoomIdLegal ) ;
40
116
}
41
117
catch
42
118
{
43
119
// If replacement failed, append new message text
44
120
if ( string . IsNullOrWhiteSpace ( oldBody ) )
45
121
{
46
- newBody = NewJitsiAppointment . generateBody ( newRoomIdLegal ) ;
122
+ newBody = await generateBody ( newRoomIdLegal ) ;
47
123
}
48
124
else
49
125
{
50
- newBody = oldBody + "\n " + NewJitsiAppointment . generateBody ( newRoomIdLegal ) ;
126
+ newBody = oldBody + "\n " + generateBody ( newRoomIdLegal ) ;
51
127
}
52
128
53
129
this . buttonStartWithAudioMuted . Checked = false ;
54
130
this . buttonStartWithVideoMuted . Checked = false ;
55
131
this . buttonRequireDisplayName . Checked = false ;
56
-
57
132
}
58
133
59
-
60
134
fieldRoomID . Text = newRoomIdLegal ;
61
135
appointmentItem . Body = newBody ;
62
136
63
137
oldDomain = newDomain ;
64
- }
65
-
66
-
67
- private string escapeDomain ( )
68
- {
69
- string escapedDomain = Regex . Escape ( oldDomain ) ;
70
- if ( ! escapedDomain . EndsWith ( "/" ) )
71
- {
72
- escapedDomain += "/" ;
73
- }
74
- return escapedDomain ;
75
138
}
76
139
77
- public string findRoomId ( )
140
+ public static async Task < string > generateBody ( string roomId )
78
141
{
79
- string roomId = Regex . Match ( appointmentItem . Body , "(?<=" + escapeDomain ( ) + ")\\ S+?(?=(#config|&config|\\ s))" ) . Value ; // Match all non-blanks after jitsi url and before config or end
80
- return roomId ;
142
+ return Globals . ThisAddIn . getElementTranslation ( "appointmentItem" , "textBodyMessage" )
143
+ + ( JitsiUrl . getUrlBase ( ) + roomId )
144
+ + Globals . ThisAddIn . getElementTranslation ( "appointmentItem" , "textBodyMessagePhone" )
145
+ + await Globals . ThisAddIn . JitsiApiService . getPhoneNumbers ( roomId )
146
+ + Globals . ThisAddIn . getElementTranslation ( "appointmentItem" , "textBodyPin" )
147
+ + await Globals . ThisAddIn . JitsiApiService . getPIN ( roomId )
148
+ + Globals . ThisAddIn . getElementTranslation ( "appointmentItem" , "textBodyDisclaimer" ) ;
81
149
}
82
150
151
+
83
152
public void randomiseRoomId ( )
84
153
{
85
154
setRoomId ( JitsiUrl . generateRandomId ( ) ) ;
@@ -99,19 +168,34 @@ public void toggleRequireName()
99
168
toggleSetting ( "requireDisplayName" ) ;
100
169
}
101
170
171
+ private void setRoomIdText ( string roomIdText )
172
+ {
173
+ if ( roomIdText != null )
174
+ {
175
+ fieldRoomID . Text = roomIdText ;
176
+ }
177
+ }
178
+
179
+ private void addJitsiMeeting ( )
180
+ {
181
+ appointmentItem . Location = "Jitsi Meet" ;
182
+ initialise ( ) ;
183
+
184
+ }
185
+
102
186
private void toggleSetting ( string setting )
103
187
{
104
188
// Find Jitsi URL in message
105
189
string oldBody = appointmentItem . Body ;
106
- string urlMatch = Regex . Match ( oldBody , escapeDomain ( ) + " \\ S+" ) . Value ;
190
+ string urlMatch = Utils . GetUrl ( oldBody , oldDomain ) ;
107
191
108
192
// Remove setting if present
109
193
string urlNew ;
110
- if ( urlMatch . Contains ( "config." + setting + "=true" ) )
194
+ if ( Utils . SettingIsActive ( urlMatch , setting ) )
111
195
{
112
196
urlNew = Regex . Replace ( urlMatch , "(#|&)config\\ ." + setting + "=true" , "" ) ;
113
- }
114
-
197
+ }
198
+
115
199
// Otherwise add
116
200
else
117
201
{
0 commit comments