use of com.zimbra.cs.mailbox.calendar.Alarm in project zm-mailbox by Zimbra.
the class CalendarItem method getNextAlarmHelperForTasks.
/**
* Find the next absolute trigger alarm. This is primarily for tasks. Tasks have a slightly different constraint
* on alarms than appointments do. In particular, the absolute trigger time of tasks need not be before DTSTART
* or DUE, whereas alarms for appointments are meaningful only if it triggers before DTSTART. A reminder for a
* meeting that has already started is useless, but a reminder for an over-due task can be quite useful.
*
* @param atOrAfter
* @param snoozeUntil
* @param forEmailAction
* @return
*/
private AlarmData getNextAlarmHelperForTasks(long atOrAfter, long snoozeUntil, boolean forEmailAction) {
// Find the two nearest alarms that surround atOrAfter such that t(alarm1) <= atOrAfter < t(alarm2).
Alarm alarm1 = null, alarm2 = null;
// trigger times for alarm1 and alarm2
long trigger1 = Long.MIN_VALUE, trigger2 = Long.MAX_VALUE;
// instance start time for alarm1 and alarm2
long instStart1 = 0, instStart2 = 0;
// invId and compNum for inst1 and inst2
int invId1 = 0, compNum1 = 0, invId2 = 0, compNum2 = 0;
for (Invite inv : mInvites) {
if (inv.isCancel())
continue;
// The invite can have multiple alarms.
for (Iterator<Alarm> alarms = inv.alarmsIterator(); alarms.hasNext(); ) {
Alarm alarm = alarms.next();
if (Action.EMAIL.equals(alarm.getAction()) == forEmailAction && alarm.getTriggerAbsolute() != null) {
long trg = alarm.getTriggerAbsolute().getUtcTime();
if (trg <= atOrAfter) {
if (trg > trigger1) {
trigger1 = trg;
alarm1 = alarm;
instStart1 = inv.getStartTime() != null ? inv.getStartTime().getUtcTime() : 0;
invId1 = inv.getMailItemId();
compNum1 = inv.getComponentNum();
}
} else {
// trg > atOrAfter
if (trg < trigger2) {
trigger2 = trg;
alarm2 = alarm;
instStart2 = inv.getStartTime() != null ? inv.getStartTime().getUtcTime() : 0;
invId2 = inv.getMailItemId();
compNum2 = inv.getComponentNum();
}
}
}
}
}
AlarmData ad1 = alarm1 != null ? new AlarmData(trigger1, snoozeUntil, instStart1, invId1, compNum1, alarm1) : null;
AlarmData ad2 = alarm2 != null ? new AlarmData(trigger2, AlarmData.NO_SNOOZE, instStart2, invId2, compNum2, alarm2) : null;
return chooseNextAlarm(atOrAfter, snoozeUntil, ad1, ad2);
}
use of com.zimbra.cs.mailbox.calendar.Alarm in project zm-mailbox by Zimbra.
the class CalendarItem method computeNextAlarms.
/**
* Returns the next trigger times for alarms defined on the given Invite.
* @param inv
* @param lastAlarmsAt Map key is the 0-based alarm position and value is the last trigger time
* for that alarm.
* @return NextAlarms object that tells trigger time and instance start time by alarm position.
* It will not contain alarm position if that alarm doesn't have next trigger time later
* than its last trigger time.
*/
public NextAlarms computeNextAlarms(Invite inv, Map<Integer, Long> lastAlarmsAt) throws ServiceException {
NextAlarms result = new NextAlarms();
if (inv.getRecurrence() == null) {
// non-recurring appointment or exception instance
long instStart = 0, instEnd = 0;
ParsedDateTime dtstart = inv.getStartTime();
if (dtstart != null)
instStart = dtstart.getUtcTime();
ParsedDateTime dtend = inv.getEffectiveEndTime();
if (dtend != null)
instEnd = dtend.getUtcTime();
List<Alarm> alarms = inv.getAlarms();
int index = 0;
for (Iterator<Alarm> iter = alarms.iterator(); iter.hasNext(); index++) {
Alarm alarm = iter.next();
Long lastAtLong = lastAlarmsAt.get(index);
if (lastAtLong != null) {
long lastAt = lastAtLong.longValue();
long triggerAt = alarm.getTriggerTime(instStart, instEnd);
if (lastAt < triggerAt)
result.add(index, triggerAt, instStart);
}
}
} else {
// series invite of recurring appointment
long oldest;
oldest = Long.MAX_VALUE;
for (long lastAt : lastAlarmsAt.values()) {
oldest = Math.min(oldest, lastAt);
}
long endTime = getNextAlarmRecurrenceExpansionLimit();
Collection<Instance> instances = expandInstances(oldest, endTime, false);
List<Alarm> alarms = inv.getAlarms();
int index = 0;
for (Iterator<Alarm> iter = alarms.iterator(); iter.hasNext(); index++) {
Alarm alarm = iter.next();
Long lastAtLong = lastAlarmsAt.get(index);
if (lastAtLong != null) {
long lastAt = lastAtLong.longValue();
for (Instance inst : instances) {
if (// only look at non-exception instances
inst.isException())
continue;
long instStart = inst.getStart();
if (instStart < lastAt && inst.hasStart())
continue;
long triggerAt = alarm.getTriggerTime(instStart, inst.getEnd());
if (lastAt < triggerAt) {
result.add(index, triggerAt, instStart);
// We can break now because we know alarms on later instances are even later.
break;
}
}
}
}
}
return result;
}
use of com.zimbra.cs.mailbox.calendar.Alarm in project zm-mailbox by Zimbra.
the class CalendarItem method getNextAlarmHelper.
private AlarmData getNextAlarmHelper(long atOrAfter, long snoozeUntil, Collection<Instance> instances, long rangeStart, boolean forEmailAction) {
// Find the two nearest alarms that surround atOrAfter such that t(alarm1) <= atOrAfter < t(alarm2).
Alarm alarm1 = null, alarm2 = null;
// trigger times for alarm1 and alarm2
long trigger1 = Long.MIN_VALUE, trigger2 = Long.MAX_VALUE;
// instance start time for alarm1 and alarm2
long instStart1 = 0, instStart2 = 0;
// invId and compNum for inst1 and inst2
int invId1 = 0, compNum1 = 0, invId2 = 0, compNum2 = 0;
for (Instance inst : instances) {
long instStart = inst.getStart();
long instEnd = inst.getEnd();
if (inst.hasStart() && inst.hasEnd()) {
// Ignore instances that ended already.
if (instEnd <= rangeStart)
continue;
// For appointments (but not tasks), ignore instances whose start time has come and gone.
if (instStart < rangeStart && (this instanceof Appointment))
continue;
}
InviteInfo invId = inst.getInviteInfo();
Invite inv = getInvite(invId.getMsgId(), invId.getComponentId());
assert (inv != null);
// The instance can have multiple alarms.
for (Iterator<Alarm> alarms = inv.alarmsIterator(); alarms.hasNext(); ) {
Alarm alarm = alarms.next();
if (Action.EMAIL.equals(alarm.getAction()) == forEmailAction) {
long trg = alarm.getTriggerTime(instStart, instEnd);
if (trg <= atOrAfter) {
if (trg > trigger1) {
trigger1 = trg;
alarm1 = alarm;
instStart1 = instStart;
invId1 = invId.getMsgId();
compNum1 = invId.getComponentId();
}
} else {
// trg > atOrAfter
if (trg < trigger2) {
trigger2 = trg;
alarm2 = alarm;
instStart2 = instStart;
invId2 = invId.getMsgId();
compNum2 = invId.getComponentId();
}
}
}
}
if (alarm1 != null && alarm2 != null) {
break;
}
}
AlarmData ad1 = alarm1 != null ? new AlarmData(trigger1, snoozeUntil, instStart1, invId1, compNum1, alarm1) : null;
AlarmData ad2 = alarm2 != null ? new AlarmData(trigger2, AlarmData.NO_SNOOZE, instStart2, invId2, compNum2, alarm2) : null;
return chooseNextAlarm(atOrAfter, snoozeUntil, ad1, ad2);
}
use of com.zimbra.cs.mailbox.calendar.Alarm in project zm-mailbox by Zimbra.
the class CacheToXML method encodeAlarmData.
private static void encodeAlarmData(Element parent, AlarmData alarmData, boolean showAll) {
Element alarmElem = parent.addElement(MailConstants.E_CAL_ALARM_DATA);
long nextAlarm = alarmData.getNextAt();
if (nextAlarm < Long.MAX_VALUE)
alarmElem.addAttribute(MailConstants.A_CAL_NEXT_ALARM, nextAlarm);
// Start time of the meeting instance we're reminding about.
long alarmInstStart = alarmData.getNextInstanceStart();
if (alarmInstStart != 0)
alarmElem.addAttribute(MailConstants.A_CAL_ALARM_INSTANCE_START, alarmInstStart);
// Some info on the meeting instance the reminder is for.
// These allow the UI to display tooltip and issue a Get
// call on the correct meeting instance.
alarmElem.addAttribute(MailConstants.A_CAL_INV_ID, alarmData.getInvId());
alarmElem.addAttribute(MailConstants.A_CAL_COMPONENT_NUM, alarmData.getCompNum());
if (showAll) {
alarmElem.addAttribute(MailConstants.A_NAME, alarmData.getSummary());
alarmElem.addAttribute(MailConstants.A_CAL_LOCATION, alarmData.getLocation());
Alarm alarmObj = alarmData.getAlarm();
if (alarmObj != null)
alarmObj.toXml(alarmElem);
}
}
use of com.zimbra.cs.mailbox.calendar.Alarm in project zm-mailbox by Zimbra.
the class ToXML method encodeAlarmData.
public static Element encodeAlarmData(Element parent, CalendarItem calItem, AlarmData alarmData) {
Element alarmElem = parent.addElement(MailConstants.E_CAL_ALARM_DATA);
encodeAlarmTimes(alarmElem, calItem);
// Start time of the meeting instance we're reminding about.
long alarmInstStart = alarmData.getNextInstanceStart();
if (alarmInstStart != 0) {
alarmElem.addAttribute(MailConstants.A_CAL_ALARM_INSTANCE_START, alarmInstStart);
}
int alarmInvId = alarmData.getInvId();
int alarmCompNum = alarmData.getCompNum();
Invite alarmInv = calItem.getInvite(alarmInvId, alarmCompNum);
if (alarmInv != null) {
// Some info on the meeting instance the reminder is for.
// These allow the UI to display tooltip and issue a Get
// call on the correct meeting instance.
alarmElem.addAttribute(MailConstants.A_NAME, alarmInv.getName());
alarmElem.addAttribute(MailConstants.A_CAL_LOCATION, alarmInv.getLocation());
alarmElem.addAttribute(MailConstants.A_CAL_INV_ID, alarmInvId);
alarmElem.addAttribute(MailConstants.A_CAL_COMPONENT_NUM, alarmCompNum);
}
Alarm alarmObj = alarmData.getAlarm();
if (alarmObj != null) {
alarmObj.toXml(alarmElem);
}
return alarmElem;
}
Aggregations