From 75724e4043b5bb98399ed7040416b57a7585b5ab Mon Sep 17 00:00:00 2001 From: tk Date: Sat, 16 Aug 2025 14:43:05 +0200 Subject: [PATCH] yield quote updates --- .../lib/src/quotes/quotes_endpoint.dart | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/wien_talks/wien_talks_server/lib/src/quotes/quotes_endpoint.dart b/wien_talks/wien_talks_server/lib/src/quotes/quotes_endpoint.dart index 532d6fc..5cfe820 100644 --- a/wien_talks/wien_talks_server/lib/src/quotes/quotes_endpoint.dart +++ b/wien_talks/wien_talks_server/lib/src/quotes/quotes_endpoint.dart @@ -3,6 +3,22 @@ import 'package:wien_talks_server/src/generated/protocol.dart'; import 'package:wien_talks_server/src/quotes/quote_controller.dart'; class QuoteEndpoint extends Endpoint { + static const _channelQuoteUpdates = 'quote-updates'; + + Future updateQuote(Session session, Quote quote) async { + await Quote.db.updateRow(session, quote); + await session.messages.postMessage(_channelQuoteUpdates, quote); + } + + Stream quoteUpdates(Session session) async* { + var updateStream = + session.messages.createStream(_channelQuoteUpdates); + + await for (var quote in updateStream) { + yield quote; + } + } + Future createQuote(Session session, CreateQuoteRequest req) async { final authInfo = await session.authenticated; final userId = authInfo?.userId; @@ -29,6 +45,8 @@ class QuoteEndpoint extends Endpoint { ); final inserted = await session.db.insertRow(quote); + await session.messages.postMessage(_channelQuoteUpdates, quote); + return inserted; }