Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/release/2.6' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
petrjasek committed Mar 25, 2024
2 parents 03a21be + 2077f08 commit a049558
Show file tree
Hide file tree
Showing 12 changed files with 267 additions and 228 deletions.
21 changes: 13 additions & 8 deletions assets/agenda/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -572,9 +572,9 @@ export const SET_NEW_ITEM = 'SET_NEW_ITEM';
export function setAndUpdateNewItems(data: any) {
return function(dispatch: any, getState: any) {
const item = data.item || {};
const state = getState();

if (item.type !== 'agenda') {
const state = getState();

// Check if the item is used in the preview or opened agenda item
// If yes, make it available to the preview
Expand All @@ -596,15 +596,20 @@ export function setAndUpdateNewItems(data: any) {
return Promise.resolve();
}

dispatch(updateItem(item));
const {itemsById} = state;
const prevItem = itemsById[item['_id']];

// Fetch related planning items if the updated item has planning_items
if (item.item_type === 'event' && item.planning_items && item.planning_items.length > 0) {
item.planning_items.forEach((plan: IAgendaItem) => {
dispatch(fetchItem(plan._id));
});
// If coverage is updated in the item fetch all items and reintilized group listing.
if (prevItem && prevItem.coverages?.length !== item?.coverages?.length) {
dispatch(fetchItems());
} else {
dispatch(updateItem(item));
if (item.item_type === 'event' && item.planning_items && item.planning_items.length > 0) {
item.planning_items.forEach((plan: IAgendaItem) => {
dispatch(fetchItem(plan._id));}
);
}
}

// Do not use 'killed' items for new-item notifications
if (item.state === 'killed') {
return Promise.resolve();
Expand Down
11 changes: 10 additions & 1 deletion assets/agenda/components/MultiDayListLabel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,21 @@ function getLabelSectionClass(current: number, days: number): string {
return 'multiday-label--mid';
}

function getCurrentOccurrenceNumber(current: number, days: number): number {
if (current < 1) {
return 1;
} else if (current > days) {
return days;
}
return current;
}

export const MultiDayListLabel = React.memo(({current, days}: IProps) => (
<span className="multiday-label__wrap ms-2">
<span className={`multiday-label ${getLabelSectionClass(current, days)}`}>
<span className="multiday-label__label">{gettext('Day:')}</span>
<span className="multiday-label__value">
<span>{current > days ? days : current}</span>
<span>{getCurrentOccurrenceNumber(current, days)}</span>
<span className="multiday-label__value-divide">/</span>
<span>{days}</span>
</span>
Expand Down
2 changes: 1 addition & 1 deletion assets/agenda/tests/utils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ describe('utils', () => {
const groupedItems = keyBy(utils.groupItems(items, moment('2018-10-15'), undefined, 'day'), 'date');

expect(groupedItems.hasOwnProperty('15-10-2018')).toBe(false);
expect(groupedItems.hasOwnProperty('17-10-2018')).toBe(false);
expect(groupedItems.hasOwnProperty('17-10-2018')).toBe(true);
expect(groupedItems.hasOwnProperty('16-10-2018')).toBe(true);
expect(groupedItems.hasOwnProperty('18-10-2018')).toBe(true);
expect(groupedItems['16-10-2018'].items).toEqual(['foo']);
Expand Down
18 changes: 5 additions & 13 deletions assets/agenda/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -648,7 +648,7 @@ export function getExtraDates(item: IAgendaItem): Array<moment.Moment> {
* @param item: Event or Planning item
* @returns {Array.<{date: moment.Moment}>}
*/
export function getDisplayDates(item: IAgendaItem): Array<{date: string}> {
function getDisplayDates(item: IAgendaItem): Array<{date: string}> {
if (item._hits == null || item._hits.matched_planning_items == null) {
return item.display_dates ?? [];
} else if (item.planning_items == null || item.planning_items.length === 0) {
Expand Down Expand Up @@ -695,14 +695,10 @@ export function getDisplayDates(item: IAgendaItem): Array<{date: string}> {

/**
* Checks if a date is in extra dates
*
* @param {Object} item
* @param {Date} date to check (moment)
* @return {Boolean}
*/
export function containsExtraDate(item: IAgendaItem, dateToCheck: moment.Moment) {
return getDisplayDates(item)
.map((ed) => moment(ed.date).format('YYYY-MM-DD'))
function containsExtraDate(dateToCheck: moment.Moment, extraDates: Array<moment.Moment>) {
return extraDates
.map((ed) => ed.format('YYYY-MM-DD'))
.includes(dateToCheck.format('YYYY-MM-DD'));
}

Expand Down Expand Up @@ -788,7 +784,6 @@ export function groupItems(
}

const itemEndDate = getEndDate(item);
const scheduleType = getScheduleType(item);

// If item is an event and was actioned (postponed, rescheduled, cancelled only incase of multi-day event)
// actioned_date is set. In this case, use that as the cut off date.
Expand Down Expand Up @@ -824,10 +819,7 @@ export function groupItems(
// use clone otherwise it would modify start and potentially also maxStart, moments are mutable
for (const day = start.clone(); day.isSameOrBefore(end, 'day'); day.add(1, 'd')) {
const isBetween = isBetweenDay(day, itemStartDate, itemEndDate, item.dates.all_day, item.dates.no_end_time);
const containsExtra = containsExtraDate(item, day);
const addGroupItem: boolean = (item.event == null || item._hits?.matched_planning_items != null) && itemExtraDates.length ?
containsExtra || (scheduleType === SCHEDULE_TYPE.MULTI_DAY && isBetween) :
isBetween || containsExtra;
const addGroupItem = isBetween || containsExtraDate(day, itemExtraDates);

if (grouper(day) !== key && addGroupItem) {
key = grouper(day);
Expand Down
10 changes: 7 additions & 3 deletions newsroom/push.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,15 @@ def push():
if item.get("type") == "event":
orig = app.data.find_one("agenda", req=None, _id=item["guid"])
_id = publish_event(item, orig)
notify_new_agenda_item.delay(_id, check_topics=True)
notify_new_agenda_item.delay(_id, check_topics=True, is_new=orig is None)
elif item.get("type") == "planning":
orig = app.data.find_one("agenda", req=None, _id=item["guid"]) or {}
item["planning_date"] = parse_date_str(item["planning_date"])
plan_id = publish_planning_item(item, orig)
event_id = publish_planning_into_event(item)
# Prefer parent Event when sending notificaitons
_id = event_id or plan_id
notify_new_agenda_item.delay(_id, check_topics=True)
notify_new_agenda_item.delay(_id, check_topics=True, is_new=orig is None)
elif item.get("type") == "text":
orig = superdesk.get_resource_service("items").find_one(req=None, _id=item["guid"])
item["_id"] = publish_item(item, orig)
Expand Down Expand Up @@ -763,10 +763,14 @@ def notify_new_wire_item(_id, check_topics=True):


@celery.task
def notify_new_agenda_item(_id, check_topics=True):
def notify_new_agenda_item(_id, check_topics=True, is_new=False):
with locked(_id, "agenda"):
agenda = app.data.find_one("agenda", req=None, _id=_id)
if agenda:
if agenda.get("recurrence_id") and agenda.get("recurrence_id") != _id and is_new:
logger.info("Ignoring recurring event %s", _id)
return

superdesk.get_resource_service("agenda").enhance_items([agenda])
notify_new_item(agenda, check_topics=check_topics)

Expand Down
2 changes: 1 addition & 1 deletion newsroom/topics/topics.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ def get_user_id_to_topic_for_subscribers(
user_topic_map: Dict[ObjectId, Dict[ObjectId, Topic]] = {}
for topic in get_topics_with_subscribers():
for subscriber in topic.get("subscribers") or []:
if notification_type is not None and subscriber["notification_type"] != notification_type:
if notification_type is not None and subscriber.get("notification_type") != notification_type:
continue
user_topic_map.setdefault(subscriber["user_id"], {})
user_topic_map[subscriber["user_id"]][topic["_id"]] = topic
Expand Down
Binary file modified newsroom/translations/fi/LC_MESSAGES/messages.mo
Binary file not shown.
Loading

0 comments on commit a049558

Please sign in to comment.