Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F113714
D15.1732488735.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Award Token
Flag For Later
Size
3 KB
Referenced Files
None
Subscribers
None
D15.1732488735.diff
View Options
diff --git a/src/client/room/room.hpp b/src/client/room/room.hpp
--- a/src/client/room/room.hpp
+++ b/src/client/room/room.hpp
@@ -761,6 +761,15 @@
*/
auto relatedEvents(lager::reader<std::string> eventId, std::string relType) const -> lager::reader<EventList>;
+ /**
+ * Post a read receipt for this room.
+ *
+ * @param eventId The event id the user has read up to.
+ *
+ * @return A Promise that resolves when the read receipt is sent.
+ */
+ PromiseT postReceipt(std::string eventId) const;
+
private:
const lager::reader<SdkModel> &sdkCursor() const;
const lager::reader<RoomModel> &roomCursor() const;
diff --git a/src/client/room/room.cpp b/src/client/room/room.cpp
--- a/src/client/room/room.cpp
+++ b/src/client/room/room.cpp
@@ -875,4 +875,9 @@
return EventList(relatedEvents.begin(), relatedEvents.end());
}).make();
}
+
+ auto Room::postReceipt(std::string eventId) const -> PromiseT
+ {
+ return m_ctx.dispatch(PostReceiptAction{roomId().make().get(), eventId});
+ }
}
diff --git a/src/tests/client/room/read-receipt-test.cpp b/src/tests/client/room/read-receipt-test.cpp
--- a/src/tests/client/room/read-receipt-test.cpp
+++ b/src/tests/client/room/read-receipt-test.cpp
@@ -11,8 +11,14 @@
#include <catch2/catch_test_macros.hpp>
#include <catch2/matchers/catch_matchers_range_equals.hpp>
+#include <lager/event_loop/boost_asio.hpp>
+
#include <asio-promise-handler.hpp>
#include <room/room-model.hpp>
+#include <sdk-model.hpp>
+#include <client/client.hpp>
+#include <cprjobhandler.hpp>
+#include <lagerstoreeventemitter.hpp>
#include <testfixtures/factory.hpp>
@@ -153,3 +159,50 @@
auto expected2 = immer::flex_vector<EventReader>{{"@rikj:jki.re", 1796451550450}};
REQUIRE(readers2 == expected2);
}
+
+TEST_CASE("Posting receipts", "[client][room][receipt]")
+{
+ auto r = makeRoom();
+ auto m = makeClient(withRoom(r));
+
+ boost::asio::io_context io;
+ SingleTypePromiseInterface<EffectStatus> sgph{AsioPromiseHandler{io.get_executor()}};
+ auto jh = Kazv::CprJobHandler{io.get_executor()};
+ auto ee = Kazv::LagerStoreEventEmitter(lager::with_boost_asio_event_loop{io.get_executor()});
+
+ auto sdk = Kazv::makeSdk(
+ SdkModel{m},
+ jh,
+ ee,
+ Kazv::AsioPromiseHandler{io.get_executor()},
+ zug::identity
+ );
+
+ auto ctx = sdk.context();
+
+ auto postReceiptCalled = 0;
+ std::string postReceiptRoomId;
+ std::string postReceiptEventId;
+ auto mockContext = typename Client::ContextT([&sgph, &postReceiptCalled, &postReceiptRoomId, &postReceiptEventId](const auto &action) {
+ if (std::holds_alternative<PostReceiptAction>(action)) {
+ ++postReceiptCalled;
+ postReceiptRoomId = std::get<PostReceiptAction>(action).roomId;
+ postReceiptEventId = std::get<PostReceiptAction>(action).eventId;
+ return sgph.createResolved(EffectStatus(true, json::object()));
+ }
+ throw std::runtime_error{"unhandled action"};
+ }, sgph, lager::deps<>{});
+ auto client = Client(Client::InEventLoopTag{}, mockContext, sdk.context());
+
+ auto room = client.room(r.roomId);
+
+ room.postReceipt("$1")
+ .then([&io](auto) {
+ io.stop();
+ });
+ io.run();
+
+ REQUIRE(postReceiptCalled == 1);
+ REQUIRE(postReceiptRoomId == r.roomId);
+ REQUIRE(postReceiptEventId == "$1");
+}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sun, Nov 24, 2:52 PM (13 h, 25 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
39873
Default Alt Text
D15.1732488735.diff (3 KB)
Attached To
Mode
D15: Support posting read receipts
Attached
Detach File
Event Timeline
Log In to Comment