-
Notifications
You must be signed in to change notification settings - Fork 93
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
Conversation
WalkthroughThe 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 Changes
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? TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Additionally, you can add CodeRabbit Configration File (
|
There was a problem hiding this 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
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
: TheLocationPayload
struct is well-defined and appropriately documented. Good job on including comments for fields likeAccuracy
to clarify their purpose.wechaty/user/message.go (2)
148-167
: > 📝 NOTEThis 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 genericsayable
interface and handle a*Location
type is a great enhancement, allowing for more flexibility in message types.
433-443
: The addition of theToLocation
method is well-implemented, enabling the conversion of messages to theLocation
type, which supports the new location message feature.wechaty-puppet/puppet.go (2)
34-35
: The addition of theMessageLocation
method to theiPuppet
interface is appropriate and aligns with the PR's objective to support location messages.
35-35
: TheMessageSendLocation
method complements theMessageLocation
method and supports the new functionality of sending location messages.wechaty-puppet-service/puppet_service.go (2)
597-620
: The implementation ofMessageLocation
correctly retrieves location data from the gRPC client and constructs aLocationPayload
. However, returning aLocationPayload
with "NOADDRESS" and "NONAME" whenresponse.Location
is nil (lines 607-611) might not be the best approach. It could be more appropriate to returnnil
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
: TheMessageSendLocation
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 theLocationPayload
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 whereMessageSendLocation
is called. This could include checks for valid latitude and longitude values, non-empty address and name fields, etc.
b, _ := json.Marshal(u) | ||
return string(b) |
There was a problem hiding this comment.
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.
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) |
func (l *Location) longitude() float64 { | ||
return l.payload.Longitude | ||
} |
There was a problem hiding this comment.
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.
func (l *Location) longitude() float64 { | |
return l.payload.Longitude | |
} | |
func (l *Location) Longitude() float64 { | |
return l.payload.Longitude | |
} |
func (p *PuppetMock) MessageLocation(messageID string) (*schemas.LocationPayload, error) { | ||
//TODO implement me | ||
panic("implement me") | ||
} |
There was a problem hiding this comment.
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?
func (p *PuppetMock) MessageSendLocation(conversationID string, payload *schemas.LocationPayload) (string, error) { | ||
//TODO implement me | ||
panic("implement me") | ||
} |
There was a problem hiding this comment.
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?
support location msg
Summary by CodeRabbit
Location
structure to manage location-related data such as accuracy, address, latitude, longitude, and name.Say
method for greater flexibility in message types, including support for location messages.UrlLinkPayload
structure for better readability.