ably / ably-go

Go client library SDK for Ably realtime messaging service
https://ably.com/download
Apache License 2.0
81 stars 31 forks source link

Publish in Realtime channel #597

Open amimimor opened 1 year ago

amimimor commented 1 year ago

While trying to understand how to publish directly to a single subscriber with the realtime channel, I came across this: https://github.com/ably/ably-go/blob/d88b30fdf5dec58a80fa698680dcb8523e2314fc/ably/realtime_channel.go#L596-L613

When using the Publish method, it effectively creates a []*Message{{Name: name, Data: data}} and calls the PublishMultiple. Given this in the iteration over L608 (where v is type *Message from the passed in slice):

a) one cannot publish any message that bares additional properties (never there is a ClientId property) b) therefore, the conditional in the snippet above is never evaluated to true

Additionally, and CMIIW, I'm failing to understand the usage of the Publish method with the data being passed as ably.Message (as in realtime_channel_test.go), since what would happen (given the above snippet) if I call publish like so: Publish(context.Background(), "name", able.Message{Name: "name", Data: "hi", OtherPublicProp: "a"}) ... and would effectively create a []*Message{{Name: name, Data: able.Message{Name: "name", Data: "hi", OtherPublicProp: "a"}}, i.e. a Message wrapping the passed in Message, and call PublishMultiple with this slice as param, so even if I wanted to build my own Message with a ClientId, it would be wrapped in a Message that doesn't have a ClientId

┆Issue is synchronized with this Jira Task by Unito

sync-by-unito[bot] commented 1 year ago

➤ Automation for Jira commented:

The link to the corresponding Jira issue is https://ably.atlassian.net/browse/SDK-3620