Skip to content

Commit

Permalink
Resync just description if GMeet is removed.
Browse files Browse the repository at this point in the history
  • Loading branch information
phw198 committed Nov 16, 2023
1 parent 2df34b9 commit a015c47
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 32 deletions.
30 changes: 1 addition & 29 deletions src/OutlookGoogleCalendarSync/OutlookOgcs/GMeet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -349,41 +349,13 @@ public static String RtfHtmlInfo(String meetingUrl, Boolean includeHeader = true
/// </summary>
/// <param name="ai">The appointment to update</param>
/// <param name="gMeetUrl">The URL of the Meeting</param>
public static void GoogleMeet(this Microsoft.Office.Interop.Outlook.AppointmentItem ai, String gMeetUrl) {
public static void GoogleMeet(this AppointmentItem ai, String gMeetUrl) {
Regex rgxGmeetUrl = new Regex(@"https:\/\/meet\.google\.com\/[a-z]{3}-[a-z]{4}-[a-z]{3}", RegexOptions.None);
OlBodyFormat bodyFormat = ai.BodyFormat();
log.Debug("Body format: " + bodyFormat.ToString());

if (String.IsNullOrEmpty(gMeetUrl)) {
if (!rgxGmeetUrl.IsMatch(ai.Body)) {
log.Debug("No GMeet info found to remove.");
CustomProperty.Remove(ref ai, CustomProperty.MetadataId.gMeetUrl);
return;
}
String oGMeetUrl = CustomProperty.Get(ai, CustomProperty.MetadataId.gMeetUrl);

if (!String.IsNullOrEmpty(ai.Body?.RemoveLineBreaks().Trim())) {
String gMeetTemplate = PlainInfo("", bodyFormat);
if (rgxGmeetUrl.Replace(ai.Body, "").RemoveLineBreaks() == gMeetTemplate.RemoveLineBreaks()) {
log.Debug("Description only contains GMeet info, which will be removed.");
Calendar.Instance.IOutlook.AddRtfBody(ref ai, "");
ai.Body = "";
} else {
if (bodyFormat == OlBodyFormat.olFormatPlain) {
if (ai.Body.Replace(PlainInfo(oGMeetUrl, bodyFormat), "").Length < ai.Body.Length) {
log.Debug("Retaining non-GMeet content.");
ai.Body = ai.Body.Replace(PlainInfo(oGMeetUrl, bodyFormat), "");
} else
log.Debug("Not safe to remove GMeet info.");
} else {
//log.Debug("Marking GMeet URL as cancelled.");
//GoogleMeet(ai, oGMeetUrl + " (cancelled)\r\n");
log.Debug("Not safe to remove GMeet info.");
}
}
}
CustomProperty.Remove(ref ai, CustomProperty.MetadataId.gMeetUrl);

} else {
CustomProperty.Add(ref ai, CustomProperty.MetadataId.gMeetUrl, gMeetUrl);

Expand Down
11 changes: 8 additions & 3 deletions src/OutlookGoogleCalendarSync/OutlookOgcs/OutlookCalendar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,7 @@ public Boolean UpdateCalendarEntry(ref AppointmentItem ai, Event ev, ref int ite

if (profile.SyncDirection.Id == Sync.Direction.GoogleToOutlook.Id || !profile.AddDescription_OnlyToGoogle) {
String aiBody = ai.Body?.RemoveLineBreaks();
Boolean descriptionChanged = false;
if (!String.IsNullOrEmpty(aiBody)) {
Regex htmlDataTag = new Regex(@"<data:image.*?>");
aiBody = htmlDataTag.Replace(aiBody, "");
Expand All @@ -606,12 +607,16 @@ public Boolean UpdateCalendarEntry(ref AppointmentItem ai, Event ev, ref int ite
if (bodyObfuscated.Length == 8 * 1024 && aiBody.Length > 8 * 1024) {
log.Warn("Event description has been truncated, so will not be synced to Outlook.");
} else {
if (Sync.Engine.CompareAttribute("Description", Sync.Direction.GoogleToOutlook, bodyObfuscated, aiBody, sb, ref itemModified))
if (descriptionChanged = Sync.Engine.CompareAttribute("Description", Sync.Direction.GoogleToOutlook, bodyObfuscated, aiBody, sb, ref itemModified))
ai.Body = bodyObfuscated;
}
if (Sync.Engine.CompareAttribute("Google Meet", Sync.Direction.GoogleToOutlook, ev.HangoutLink, oGMeetUrl, sb, ref itemModified)) {
ai.GoogleMeet(ev.HangoutLink);
if (String.IsNullOrEmpty(ev.HangoutLink) && !String.IsNullOrEmpty(oGMeetUrl) && !descriptionChanged)
log.Debug("Removing GMeet information from body.");
ai.Body = bodyObfuscated;
}
}
if (Sync.Engine.CompareAttribute("Google Meet", Sync.Direction.GoogleToOutlook, ev.HangoutLink, oGMeetUrl, sb, ref itemModified))
ai.GoogleMeet(ev.HangoutLink);
}

if (profile.AddLocation) {
Expand Down

0 comments on commit a015c47

Please sign in to comment.