Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix event name, make batch call to seen
  • Loading branch information
vickiniu committed Mar 12, 2026
commit f42470759f25b42ea780db31102646baf234a120
17 changes: 9 additions & 8 deletions securedrop/journalist_app/api2/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,19 +302,20 @@ def handle_source_conversation_seen(event: Event, minor: int) -> EventResult:
)

user = session.get_user()
seen: list[ItemUUID] = []
for item in source.collection:
if item.interaction_count <= event.data.upper_bound:
utils.mark_seen([item], user)
seen.append(item.uuid)
db.session.refresh(item)
seen_items = [
item for item in source.collection if item.interaction_count <= event.data.upper_bound
]

db.session.refresh(source)
if seen_items:
utils.mark_seen(seen_items, user)
for item in seen_items:
db.session.refresh(item)
db.session.refresh(source)
return EventResult(
event_id=event.id,
status=(EventStatusCode.OK, None),
sources={source.uuid: source},
items={item_uuid: None for item_uuid in seen},
items={item.uuid: item.uuid for item in seen_items},
)

@staticmethod
Expand Down
4 changes: 2 additions & 2 deletions securedrop/journalist_app/api2/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class EventType(StrEnum):
SOURCE_CONVERSATION_TRUNCATED = auto()
SOURCE_STARRED = auto()
SOURCE_UNSTARRED = auto()
SOURCE_SEEN = auto()
SOURCE_CONVERSATION_SEEN = auto()


class EventStatusCode(IntEnum):
Expand Down Expand Up @@ -172,7 +172,7 @@ def __post_init__(self) -> None:
EventType.SOURCE_CONVERSATION_TRUNCATED: (SourceTarget, SourceConversationTruncatedData),
EventType.SOURCE_STARRED: (SourceTarget, None),
EventType.SOURCE_UNSTARRED: (SourceTarget, None),
EventType.SOURCE_SEEN: (SourceTarget, SourceConversationSeenData),
EventType.SOURCE_CONVERSATION_SEEN: (SourceTarget, SourceConversationSeenData),
}


Expand Down
1 change: 1 addition & 0 deletions securedrop/tests/test_journalist_api2.py
Original file line number Diff line number Diff line change
Expand Up @@ -1370,6 +1370,7 @@ def test_api2_source_conversation_seen(

if count <= upper_bound:
assert item_uuid in response.json["items"]
assert response.json["items"][item_uuid] is not None
if submission is not None:
assert submission.seen is True
else:
Expand Down