Skip to content
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

feat(location): support location msg #162

Merged
merged 1 commit into from
Apr 1, 2024
Merged

feat(location): support location msg #162

merged 1 commit into from
Apr 1, 2024

Conversation

dchaofei
Copy link
Collaborator

@dchaofei dchaofei commented Mar 29, 2024

support location msg

message.ToLocation()

message.Say(user.NewLocation(&schemas.LocationPayload{
		Accuracy:  15,
		Address:   "北京市北京市海淀区45 Chengfu Rd",
		Latitude:  39.995120999999997,
		Longitude: 116.334154,
		Name:      "东升乡人民政府(海淀区成府路45号)",
	}))

Summary by CodeRabbit

  • New Features
    • Introduced location sharing capabilities with methods to send and retrieve location information.
    • Added a new Location structure to manage location-related data such as accuracy, address, latitude, longitude, and name.
  • Refactor
    • Enhanced the Say method for greater flexibility in message types, including support for location messages.
  • Style
    • Updated indentation in the UrlLinkPayload structure for better readability.

@dchaofei dchaofei requested a review from a team as a code owner March 29, 2024 10:21
@dosubot dosubot bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Mar 29, 2024
Copy link

coderabbitai bot commented Mar 29, 2024

Walkthrough

The recent updates across the Wechaty libraries introduce and enhance location-related functionalities. New methods for sending and retrieving location messages have been added to various components, alongside a new LocationPayload struct for representing location data. Additionally, the Say method in the Message struct has been refactored for greater flexibility, accommodating a wider range of message types through a generic interface.

Changes

Files Change Summary
.../puppet-mock/puppet_mock.go Added MessageLocation and MessageSendLocation methods.
.../puppet-service/puppet_service.go Added MessageLocation, MessageSendLocation functions; updated MessageRawPayload.
wechaty-puppet/puppet.go Added MessageLocation and MessageSendLocation to iPuppet interface.
.../puppet/schemas/location.go Introduced LocationPayload struct for location data representation.
.../puppet/schemas/url_link.go Updated indentation and method implementation in UrlLinkPayload struct.
wechaty/user/location.go Added Location struct with location-related methods.
wechaty/user/message.go Refactored Say method for generic sayable interface; added ToLocation method.

🐰✨
In the land of code and wire,
Where the bytes and logic mire,
A rabbit hopped with a mission so grand,
To share locations across the digital land.
With a hop, skip, and a function call,
"Let's send locations, big and small!"
🌍📍💫

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share

Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit-tests for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit tests for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 4

Review Status

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 6e2107c and ca15c07.
Files selected for processing (7)
  • wechaty-puppet-mock/puppet_mock.go (1 hunks)
  • wechaty-puppet-service/puppet_service.go (1 hunks)
  • wechaty-puppet/puppet.go (1 hunks)
  • wechaty-puppet/schemas/location.go (1 hunks)
  • wechaty-puppet/schemas/url_link.go (1 hunks)
  • wechaty/user/location.go (1 hunks)
  • wechaty/user/message.go (3 hunks)
Additional Context Used
Additional comments not posted (7)
wechaty-puppet/schemas/location.go (1)

3-9: The LocationPayload struct is well-defined and appropriately documented. Good job on including comments for fields like Accuracy to clarify their purpose.

wechaty/user/message.go (2)

148-167: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [151-178]

The refactoring of the Say method to accept a more generic sayable interface and handle a *Location type is a great enhancement, allowing for more flexibility in message types.


433-443: The addition of the ToLocation method is well-implemented, enabling the conversion of messages to the Location type, which supports the new location message feature.

wechaty-puppet/puppet.go (2)

34-35: The addition of the MessageLocation method to the iPuppet interface is appropriate and aligns with the PR's objective to support location messages.


35-35: The MessageSendLocation method complements the MessageLocation method and supports the new functionality of sending location messages.

wechaty-puppet-service/puppet_service.go (2)

597-620: The implementation of MessageLocation correctly retrieves location data from the gRPC client and constructs a LocationPayload. However, returning a LocationPayload with "NOADDRESS" and "NONAME" when response.Location is nil (lines 607-611) might not be the best approach. It could be more appropriate to return nil or an error indicating that no location data is available, to avoid misleading the caller with dummy data.

Consider changing the behavior to return nil or a specific error when no location data is found, to clearly communicate the absence of data to the caller.


622-641: The MessageSendLocation function correctly sends location data to a conversation. The function is well-implemented, with clear logging and error handling. However, it's important to ensure that the LocationPayload provided to this function is validated before attempting to send it. This is to prevent sending incomplete or incorrect location data.

Ensure that there's validation for LocationPayload either within this function or upstream where MessageSendLocation is called. This could include checks for valid latitude and longitude values, non-empty address and name fields, etc.

Comment on lines +13 to +14
b, _ := json.Marshal(u)
return string(b)
Copy link

Choose a reason for hiding this comment

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

Consider handling the error returned by json.Marshal to ensure robust error handling and avoid potential issues if marshaling fails.

func (u *UrlLinkPayload) ToJson() string {
-   b, _ := json.Marshal(u)
+   b, err := json.Marshal(u)
+   if err != nil {
+       // Handle error (e.g., log it, return an error message, etc.)
+       return ""
+   }
    return string(b)
}

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
b, _ := json.Marshal(u)
return string(b)
b, err := json.Marshal(u)
if err != nil {
// Handle error (e.g., log it, return an error message, etc.)
return ""
}
return string(b)

Comment on lines +34 to +36
func (l *Location) longitude() float64 {
return l.payload.Longitude
}
Copy link

Choose a reason for hiding this comment

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

The method longitude should be exported for consistency with other getters. Consider renaming it to Longitude.

- func (l *Location) longitude() float64 {
+ func (l *Location) Longitude() float64 {

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
func (l *Location) longitude() float64 {
return l.payload.Longitude
}
func (l *Location) Longitude() float64 {
return l.payload.Longitude
}

Comment on lines +15 to +18
func (p *PuppetMock) MessageLocation(messageID string) (*schemas.LocationPayload, error) {
//TODO implement me
panic("implement me")
}
Copy link

Choose a reason for hiding this comment

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

The MessageLocation method is currently a placeholder. Consider documenting the expected behavior or purpose of this method for future implementation.

Would you like me to suggest a basic implementation or further documentation for this method?

Comment on lines +20 to +23
func (p *PuppetMock) MessageSendLocation(conversationID string, payload *schemas.LocationPayload) (string, error) {
//TODO implement me
panic("implement me")
}
Copy link

Choose a reason for hiding this comment

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

Similar to MessageLocation, MessageSendLocation is also a placeholder. It would be beneficial to document the expected behavior or purpose of this method.

Would you like assistance in suggesting a basic implementation or further documentation for this method?

@dchaofei dchaofei merged commit cbec08a into master Apr 1, 2024
3 of 4 checks passed
@dchaofei dchaofei deleted the location branch April 1, 2024 10:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size:L This PR changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant