Skip to content

Commit

Permalink
feat: remove unused dependencies, add event for received searches
Browse files Browse the repository at this point in the history
  • Loading branch information
JurgenR committed Oct 5, 2023
1 parent 87609d5 commit 6dab482
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 12 deletions.
8 changes: 8 additions & 0 deletions src/aioslsk/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,14 @@ class SearchResultEvent(Event):
result: SearchResult


@dataclass(frozen=True)
class SearchRequestReceivedEvent(Event):
"""Emitted when a search request by another user has been received"""
username: str
query: str
result_count: int


@dataclass(frozen=True)
class SimilarUsersEvent(Event):
users: List[User]
Expand Down
20 changes: 10 additions & 10 deletions src/aioslsk/search/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,16 @@
InternalEventBus,
ConnectionStateChangedEvent,
MessageReceivedEvent,
UserDirectoryEvent,
UserInfoEvent,
UserSharesReplyEvent,
SearchRequestReceivedEvent,
SearchResultEvent,
)
from ..protocol.messages import (
ChatRoomSearch,
DistributedSearchRequest,
DistributedServerSearchRequest,
FileSearch,
MessageDataclass,
PeerDirectoryContentsRequest,
PeerDirectoryContentsReply,
PeerSearchReply,
PeerSharesRequest,
PeerSharesReply,
PeerUserInfoReply,
PeerUserInfoRequest,
ServerSearchRequest,
UserSearch,
WishlistInterval,
Expand Down Expand Up @@ -145,11 +137,19 @@ async def _query_shares_and_reply(self, ticket: int, username: str, query: str):
"""
visible, locked = self._shares_manager.query(query, username=username)

result_count = len(visible) + len(locked)
self.received_searches.append(
ReceivedSearch(
username=username,
query=query,
matched_files=len(visible) + len(locked)
result_count=result_count
)
)
await self._event_bus.emit(
SearchRequestReceivedEvent(
username=username,
query=query,
result_count=result_count
)
)

Expand Down
6 changes: 4 additions & 2 deletions src/aioslsk/search/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@ class SearchType(Enum):

@dataclass
class ReceivedSearch:
"""Used for keeping track of searches received from the distributed parent"""
"""Used for keeping track of searches received from the distributed parent
or server
"""
username: str
query: str
matched_files: int
result_count: int


@dataclass
Expand Down

0 comments on commit 6dab482

Please sign in to comment.