Skip to content

Commit

Permalink
custom time modified property added and attendee fixed (#8)
Browse files Browse the repository at this point in the history
* custom time modified property added and attendee fixed

* attendee refactoring
  • Loading branch information
Artooorcheck authored Oct 24, 2024
1 parent 6696335 commit defdb82
Show file tree
Hide file tree
Showing 2 changed files with 125 additions and 102 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public class QueryOutlookFolderByGetTableStrategy : IQueryOutlookFolderStrategy
private const string PR_LONG_TERM_ENTRYID_FROM_TABLE = "http://schemas.microsoft.com/mapi/proptag/0x66700102";
private const string PR_ENTRYID = "http://schemas.microsoft.com/mapi/proptag/0x0FFF0102";
private const string LastModificationTimeColumnId = "LastModificationTime";
private const string UserModificationTimeColumnId = "UserModifiedTime";
private const string SubjectColumnId = "Subject";
private const string StartColumnId = "Start";
private const string EndColumnId = "End";
Expand All @@ -65,7 +66,7 @@ List<AppointmentSlim> IQueryOutlookAppointmentItemFolderStrategy.QueryAppointmen
table.Columns.Add(SubjectColumnId);
table.Columns.Add(StartColumnId);
table.Columns.Add(EndColumnId);

table.Columns.Add(UserModificationTimeColumnId);
while (!table.EndOfTable)
{
var row = table.GetNextRow();
Expand Down Expand Up @@ -101,10 +102,18 @@ List<AppointmentSlim> IQueryOutlookAppointmentItemFolderStrategy.QueryAppointmen
var appointmentId = new AppointmentId(entryId, globalAppointmentId);

var lastModificationTimeObject = row[LastModificationTimeColumnId];
var userModificationTimeObject = row[UserModificationTimeColumnId];
DateTime lastModificationTime;
DateTime userModificationTime;
if (lastModificationTimeObject != null)
{
lastModificationTime = ((DateTime) lastModificationTimeObject).ToUniversalTime();
if (userModificationTimeObject != null)
{
userModificationTime = ((DateTime)userModificationTimeObject).ToUniversalTime();
if (userModificationTime > lastModificationTime)
lastModificationTime = userModificationTime;
}
}
else
{
Expand Down
216 changes: 115 additions & 101 deletions CalDavSynchronizer/Implementation/Events/EventEntityMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -650,26 +650,35 @@ private OlResponseStatus MapParticipation2To1(string value)
}

private void MapOrganizer1To2(AppointmentItem source, IEvent target, IEntitySynchronizationLogger logger)
{
if (source.MeetingStatus != OlMeetingStatus.olNonMeeting)
{
using (var organizerWrapper = GenericComObjectWrapper.Create(OutlookUtility.GetEventOrganizerOrNull(source, logger, s_logger, _outlookMajorVersion)))
{
if (organizerWrapper.Inner != null)
{
if (StringComparer.InvariantCultureIgnoreCase.Compare(organizerWrapper.Inner.Name, source.Organizer) == 0)
{
SetOrganizer(target, organizerWrapper.Inner, organizerWrapper.Inner.Address, logger);
}
else
{
string organizerEmail = OutlookUtility.GetSenderEmailAddressOrNull(source, logger, s_logger);
SetOrganizer(target, source.Organizer, organizerEmail, logger);
}

SetOrganizerSchedulingParameters(source, target, logger);
}
}
{
using (var organizerWrapper = GenericComObjectWrapper.Create(OutlookUtility.GetEventOrganizerOrNull(source, logger, s_logger, _outlookMajorVersion)))
{
if (organizerWrapper.Inner != null)
{
var email = "";
if (StringComparer.InvariantCultureIgnoreCase.Compare(organizerWrapper.Inner.Name, source.Organizer) == 0)
{
SetOrganizer(target, organizerWrapper.Inner, organizerWrapper.Inner.Address, logger);
email = CreateMailUriOrNull(organizerWrapper.Inner.Address, logger);
}
else
{
string organizerEmail = OutlookUtility.GetSenderEmailAddressOrNull(source, logger, s_logger);
SetOrganizer(target, source.Organizer, organizerEmail, logger);
email = CreateMailUriOrNull(organizerEmail, logger);
}

//Добавление организатора участником, так как VK не воспринимает изменение списка участников по CalDAV, если список пуст
var ownAttendee = new Attendee();
ownAttendee.Value = new Uri(email);
ownAttendee.CommonName = source.Organizer;
ownAttendee.RSVP = true;
ownAttendee.ParticipationStatus = (source.MeetingStatus == OlMeetingStatus.olMeetingReceivedAndCanceled) ? "DECLINED" : MapParticipation1To2(source.ResponseStatus);
if (_configuration.ScheduleAgentClient)
ownAttendee.Parameters.Add("SCHEDULE-AGENT", "CLIENT");
target.Attendees.Add(ownAttendee);
SetOrganizerSchedulingParameters(source, target, logger);
}
}
}

Expand Down Expand Up @@ -1398,8 +1407,13 @@ private void MapRecurrenceExceptions2To1(
private async Task<bool> MapAttendees1To2(AppointmentItem source, IEvent target, IEntitySynchronizationLogger logger)
{
var organizerSet = false;
var ownAttendeeSet = false;

var ownAttendeeSet = false;

if (source.MeetingStatus == OlMeetingStatus.olNonMeeting)
{
return organizerSet;
}

foreach (var recipient in source.Recipients.ToSafeEnumerable<Recipient>())
{
string recipientMailAddressOrNull = null;
Expand All @@ -1419,85 +1433,85 @@ private async Task<bool> MapAttendees1To2(AppointmentItem source, IEvent target,
logger.LogWarning("Can't get AddressEntry of recipient", ex);
}

var nameWithoutEmail = OutlookUtility.RemoveEmailFromName(recipient);

if ((OlMeetingRecipientType) recipient.Type == OlMeetingRecipientType.olResource)
{
var attendee = new Attendee();
attendee.Type = "RESOURCE";
attendee.ParticipationStatus = "ACCEPTED";
attendee.CommonName = nameWithoutEmail;
attendee.Role = "REQ-PARTICIPANT";

var resourceUri = await _calendarResourceResolver.GetResourceUriOrNull(nameWithoutEmail);

if (resourceUri != null)
{
attendee.Value = resourceUri;
if (!string.IsNullOrEmpty(recipientMailAddressOrNull))
{
attendee.Parameters.Add("EMAIL", recipientMailAddressOrNull);
}
}
else
{
if (!string.IsNullOrEmpty(recipient.Address))
{
var recipientMailUrl = CreateMailUriOrNull(recipientMailAddressOrNull ?? recipient.Address, logger);
if (recipientMailUrl != null)
{
attendee.Value = new Uri(recipientMailUrl);
}
}
}

target.Attendees.Add(attendee);
}
else if (!IsOwnIdentity(recipientMailAddressOrNull))
{
var attendee = new Attendee();

if (!string.IsNullOrEmpty(recipient.Address))
{
var recipientMailUrl = CreateMailUriOrNull(recipientMailAddressOrNull ?? recipient.Address, logger);
if (recipientMailUrl != null)
{
attendee.Value = new Uri(recipientMailUrl);
}
}

attendee.ParticipationStatus = MapParticipation1To2(recipient.MeetingResponseStatus);
attendee.CommonName = nameWithoutEmail;
attendee.Role = MapAttendeeType1To2((OlMeetingRecipientType) recipient.Type);

attendee.RSVP = true;
if (_configuration.ScheduleAgentClient)
attendee.Parameters.Add("SCHEDULE-AGENT", "CLIENT");
target.Attendees.Add(attendee);
}
else
{
if ((source.MeetingStatus == OlMeetingStatus.olMeetingReceived || source.MeetingStatus == OlMeetingStatus.olMeetingReceivedAndCanceled) && (!ownAttendeeSet))
{
var ownAttendee = new Attendee();

if (!string.IsNullOrEmpty(recipient.Address))
{
var recipientMailUrl = CreateMailUriOrNull(recipientMailAddressOrNull ?? recipient.Address, logger);
if (recipientMailUrl != null)
{
ownAttendee.Value = new Uri(recipientMailUrl);
}
}

ownAttendee.CommonName = nameWithoutEmail;
ownAttendee.ParticipationStatus = (source.MeetingStatus == OlMeetingStatus.olMeetingReceivedAndCanceled) ? "DECLINED" : MapParticipation1To2(source.ResponseStatus);
ownAttendee.Role = MapAttendeeType1To2((OlMeetingRecipientType) recipient.Type);
if (_configuration.ScheduleAgentClient)
ownAttendee.Parameters.Add("SCHEDULE-AGENT", "CLIENT");
target.Attendees.Add(ownAttendee);
ownAttendeeSet = true;
}
var nameWithoutEmail = OutlookUtility.RemoveEmailFromName(recipient);

if ((OlMeetingRecipientType) recipient.Type == OlMeetingRecipientType.olResource)
{
var attendee = new Attendee();
attendee.Type = "RESOURCE";
attendee.ParticipationStatus = "ACCEPTED";
attendee.CommonName = nameWithoutEmail;
attendee.Role = "REQ-PARTICIPANT";

var resourceUri = await _calendarResourceResolver.GetResourceUriOrNull(nameWithoutEmail);

if (resourceUri != null)
{
attendee.Value = resourceUri;
if (!string.IsNullOrEmpty(recipientMailAddressOrNull))
{
attendee.Parameters.Add("EMAIL", recipientMailAddressOrNull);
}
}
else
{
if (!string.IsNullOrEmpty(recipient.Address))
{
var recipientMailUrl = CreateMailUriOrNull(recipientMailAddressOrNull ?? recipient.Address, logger);
if (recipientMailUrl != null)
{
attendee.Value = new Uri(recipientMailUrl);
}
}
}

target.Attendees.Add(attendee);
}
else if (!IsOwnIdentity(recipientMailAddressOrNull))
{
var attendee = new Attendee();

if (!string.IsNullOrEmpty(recipient.Address))
{
var recipientMailUrl = CreateMailUriOrNull(recipientMailAddressOrNull ?? recipient.Address, logger);
if (recipientMailUrl != null)
{
attendee.Value = new Uri(recipientMailUrl);
}
}

attendee.ParticipationStatus = MapParticipation1To2(recipient.MeetingResponseStatus);
attendee.CommonName = nameWithoutEmail;
attendee.Role = MapAttendeeType1To2((OlMeetingRecipientType) recipient.Type);

attendee.RSVP = true;
if (_configuration.ScheduleAgentClient)
attendee.Parameters.Add("SCHEDULE-AGENT", "CLIENT");
target.Attendees.Add(attendee);
}
else
{
if ((source.MeetingStatus == OlMeetingStatus.olMeetingReceived || source.MeetingStatus == OlMeetingStatus.olMeetingReceivedAndCanceled) && (!ownAttendeeSet))
{
var ownAttendee = new Attendee();

if (!string.IsNullOrEmpty(recipient.Address))
{
var recipientMailUrl = CreateMailUriOrNull(recipientMailAddressOrNull ?? recipient.Address, logger);
if (recipientMailUrl != null)
{
ownAttendee.Value = new Uri(recipientMailUrl);
}
}

ownAttendee.CommonName = nameWithoutEmail;
ownAttendee.ParticipationStatus = (source.MeetingStatus == OlMeetingStatus.olMeetingReceivedAndCanceled) ? "DECLINED" : MapParticipation1To2(source.ResponseStatus);
ownAttendee.Role = MapAttendeeType1To2((OlMeetingRecipientType) recipient.Type);
if (_configuration.ScheduleAgentClient)
ownAttendee.Parameters.Add("SCHEDULE-AGENT", "CLIENT");
target.Attendees.Add(ownAttendee);
ownAttendeeSet = true;
}
}

if (((OlMeetingRecipientType) recipient.Type) == OlMeetingRecipientType.olOrganizer)
Expand Down

0 comments on commit defdb82

Please sign in to comment.