Skip to content

fix: address issue causing failure to receive heartbeat #435

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
20 changes: 10 additions & 10 deletions src/wechaty/user/contact.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
# pytype: disable=pyi-error
from .url_link import UrlLink
from .mini_program import MiniProgram


log = get_logger('Contact')

Expand Down Expand Up @@ -190,7 +190,7 @@ async def find(cls,

Args:
query: the query body to build filter

Examples:
>>> # 1. find contacts based query string, will match one of: contact_id, weixin, name and alias
>>> # what's more, contact_id and weixin will follow extract match, name and alias will follow fuzzy match
Expand Down Expand Up @@ -319,7 +319,7 @@ async def say(self, message: Union[str, Message, FileBox, Contact, UrlLink, Mini

Args:
message: the message object to be sended to contact

Examples:
>>> contact = Contact.load('contact-id')
>>> await contact.say('hello')
Expand All @@ -331,7 +331,7 @@ async def say(self, message: Union[str, Message, FileBox, Contact, UrlLink, Mini
>>> await contact.say(MiniProgram('username', 'appid'))

Returns:
Message: if the message is send successfully, return the message object, otherwise return None
Message: if the message is send successfully, return the message object, otherwise return None
"""
if not message:
log.error('can"t say nothing')
Expand Down Expand Up @@ -360,7 +360,7 @@ async def say(self, message: Union[str, Message, FileBox, Contact, UrlLink, Mini
conversation_id=self.contact_id,
file=message
)

return None
elif isinstance(message, UrlLink):
# use this way to resolve circulation dependency import
msg_id = await self.puppet.message_send_url(
Expand Down Expand Up @@ -390,7 +390,7 @@ def name(self) -> str:
Examples:
>>> contact = Contact.load('contact-id')
>>> name: str = contact.name

Returns:
str: name of contact, if the payload is None, return empty string
"""
Expand All @@ -403,7 +403,7 @@ async def alias(self,
) -> Union[None, str]:
"""
Get or set alias of contact.

If new_alias is given, it will set alias to new_alias,
otherwise return current alias

Expand Down Expand Up @@ -527,7 +527,7 @@ def star(self) -> Optional[bool]:
def gender(self) -> ContactGender:
"""
Return the gender of contact.

Returns:
ContactGender: the object of contact gender
"""
Expand Down Expand Up @@ -571,7 +571,7 @@ async def avatar(self, file_box: Optional[FileBox] = None) -> FileBox:
Args:
file_box: If given, it will set it as new avatar,
else get the current avatar. Defaults to None.

Examples:
>>> contact = Contact.load('contact-id')
>>> avatar = contact.avatar()
Expand Down Expand Up @@ -627,7 +627,7 @@ def weixin(self) -> Optional[str]:
Examples:
>>> contact = Contact.load('contact-id')
>>> weixin = contact.weixin()

Returns:
identifier: the weixin union identifier of contact
"""
Expand Down
8 changes: 4 additions & 4 deletions src/wechaty/user/room.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ def filter_func(room: Room) -> bool:

@classmethod
async def find_all(cls,
query: Optional[Union[str, RoomQueryFilter, Callable[[Contact], bool]]] = None) -> List[Room]:
query: Optional[Union[str, RoomQueryFilter, Callable[[Contact], bool]]] = None,force_sync:bool=False) -> List[Room]:
"""
find all rooms based on query, which can be string, RoomQueryFilter, or callable<filter> function

Expand Down Expand Up @@ -228,9 +228,9 @@ async def find_all(cls,
# 1. load rooms with concurrent tasks
room_ids = await cls.get_puppet().room_search()
rooms: List[Room] = [cls.load(room_id) for room_id in room_ids]
tasks: List[Task] = [asyncio.create_task(room.ready()) for room in rooms]
tasks: List[Task] = [asyncio.create_task(room.ready(force_sync)) for room in rooms]
await gather_with_concurrency(PARALLEL_TASK_NUM, tasks)

# 2. filter the rooms
if not query:
return rooms
Expand Down Expand Up @@ -315,7 +315,7 @@ async def ready(self, force_sync: bool = False, load_members: bool = False) -> N
Returns:
None
"""
if self.is_ready():
if not force_sync and self.is_ready():
return

if force_sync:
Expand Down
2 changes: 1 addition & 1 deletion src/wechaty/wechaty.py
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,7 @@ async def heartbeat_listener(payload: EventHeartbeatPayload) -> None:
self.emit('heartbeat', payload.data)
await self.on_heartbeat(payload)

puppet.on('heart-beat', heartbeat_listener)
puppet.on('heartbeat', heartbeat_listener)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codebase verification

The event name 'heart-beat' still exists in the code and needs to be updated

Found remaining instances of 'heart-beat' in src/wechaty/wechaty.py that need to be updated for consistency:

  • Line with elif event_name == 'heart-beat': The condition should use 'heartbeat'
  • Line with log.info('receive <heart-beat> event <%s>', payload): The log message should use 'heartbeat'
🔗 Analysis chain

LGTM! The event name change looks correct.

The change from 'heart-beat' to 'heartbeat' aligns with:

  1. The emit function's usage of 'heartbeat'
  2. The naming convention of other events in the codebase
  3. The event name in puppet.py

Let's verify there are no other occurrences of 'heart-beat' that need to be updated:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for any remaining instances of 'heart-beat' in the codebase
rg "heart-beat" -l

# Search for heartbeat event usage to ensure consistency
rg "heartbeat" -A 2 -B 2

Length of output: 2532


elif event_name == 'friendship':
async def friendship_listener(payload: EventFriendshipPayload) -> None:
Expand Down