diff --git a/mobile/api.go b/mobile/api.go index 8a1580f8..f3de70b0 100644 --- a/mobile/api.go +++ b/mobile/api.go @@ -272,13 +272,11 @@ func Start() string { } for _, topic := range wakuState.relayTopics { - topic := topic - sub, err := wakuState.node.Relay().SubscribeToTopic(wakuState.ctx, topic) + err := relaySubscribe(topic) if err != nil { wakuState.node.Stop() - return MakeJSONResponse(fmt.Errorf("could not subscribe to topic: %s, %w", topic, err)) + return MakeJSONResponse(err) } - wakuState.node.Broadcaster().Unregister(&topic, sub.C) } return MakeJSONResponse(nil) diff --git a/mobile/api_relay.go b/mobile/api_relay.go index 764cd480..efc0379b 100644 --- a/mobile/api_relay.go +++ b/mobile/api_relay.go @@ -79,11 +79,7 @@ func RelayPublishEncodeSymmetric(messageJSON string, topic string, symmetricKey return PrepareJSONResponse(hash, err) } -func RelaySubscribe(topic string) string { - if wakuState.node == nil { - return MakeJSONResponse(errWakuNodeNotReady) - } - +func relaySubscribe(topic string) error { topicToSubscribe := getTopic(topic) relaySubsMutex.Lock() @@ -91,12 +87,12 @@ func RelaySubscribe(topic string) string { _, ok := relaySubscriptions[topicToSubscribe] if ok { - return MakeJSONResponse(nil) + return nil } subscription, err := wakuState.node.Relay().SubscribeToTopic(context.Background(), topicToSubscribe) if err != nil { - return MakeJSONResponse(err) + return err } relaySubscriptions[topicToSubscribe] = subscription @@ -107,7 +103,15 @@ func RelaySubscribe(topic string) string { } }(subscription) - return MakeJSONResponse(nil) + return nil +} + +func RelaySubscribe(topic string) string { + if wakuState.node == nil { + return MakeJSONResponse(errWakuNodeNotReady) + } + + return MakeJSONResponse(relaySubscribe(topic)) } func RelayUnsubscribe(topic string) string {