Skip to content

Commit

Permalink
Fixed topic unpublishing when it's not supposed to
Browse files Browse the repository at this point in the history
  • Loading branch information
Gold872 committed Sep 30, 2023
1 parent b7019fa commit a878cba
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions lib/services/nt4.dart
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,16 @@ class NT4Client {
_subscribedTopics.remove(sub);
_wsUnsubscribe(sub);

if (_clientPublishedTopics.containsKey(sub.topic)) {
unpublishTopic(_clientPublishedTopics[sub.topic]!);
// If there are no other subscriptions that are in the same table/tree
if (!_subscribedTopics.any((element) =>
element.topic.startsWith('${sub.topic}/') ||
'${sub.topic}/'.startsWith(element.topic))) {
// If there are any topics associated with the table/tree, unpublish them
for (NT4Topic topic in _clientPublishedTopics.values.where((element) =>
element.name.startsWith('${sub.topic}/') ||
'${sub.topic}/'.startsWith(element.name))) {
Future(() => unpublishTopic(topic));
}
}
}
}
Expand Down

0 comments on commit a878cba

Please sign in to comment.