Page MenuHomePhorge

D296.1778816213.diff
No OneTemporary

Size
7 KB
Referenced Files
None
Subscribers
None

D296.1778816213.diff

diff --git a/src/client/room/local-draft.hpp b/src/client/room/local-draft.hpp
new file mode 100644
--- /dev/null
+++ b/src/client/room/local-draft.hpp
@@ -0,0 +1,61 @@
+/*
+ * This file is part of libkazv.
+ * SPDX-FileCopyrightText: 2026 nannanko <nannankokazv.moe>
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+
+#pragma once
+#include <libkazv-config.hpp>
+
+#include <cstdint>
+#include <string>
+
+#include <boost/serialization/split_free.hpp>
+#include <boost/serialization/version.hpp>
+
+namespace Kazv
+{
+ /**
+ * Local draft.
+ */
+ struct LocalDraft
+ {
+ std::string text;
+ std::string relType;
+ std::string relatedEventId;
+ friend bool operator==(const LocalDraft &a, const LocalDraft &b) = default;
+ friend bool operator!=(const LocalDraft &a, const LocalDraft &b) = default;
+ };
+}
+
+namespace boost::serialization
+{
+ template<class Archive>
+ void save(Archive &ar, const Kazv::LocalDraft &l, std::uint32_t const version)
+ {
+ using namespace Kazv;
+ ar
+ & l.text
+ & l.relType
+ & l.relatedEventId;
+ }
+
+ template<class Archive>
+ void load(Archive &ar, Kazv::LocalDraft &l, std::uint32_t const version)
+ {
+ using namespace Kazv;
+ ar
+ & l.text
+ & l.relType
+ & l.relatedEventId;
+ }
+
+ template<class Archive>
+ void serialize(Archive &ar, Kazv::LocalDraft &l, std::uint32_t const version)
+ {
+ using boost::serialization::split_free;
+ split_free(ar, l, version);
+ }
+}
+
+BOOST_CLASS_VERSION(Kazv::LocalDraft, 10)
diff --git a/src/client/room/room-model.hpp b/src/client/room/room-model.hpp
--- a/src/client/room/room-model.hpp
+++ b/src/client/room/room-model.hpp
@@ -27,6 +27,7 @@
#include "push-rules-desc.hpp"
#include "local-echo.hpp"
#include "clientutil.hpp"
+#include "local-draft.hpp"
namespace Kazv
{
@@ -120,6 +121,17 @@
std::string localDraft;
};
+ struct SetDraftRelAction
+ {
+ std::string text;
+ std::string relType;
+ std::string relatedEventId;
+ };
+
+ struct PopLocalDraftAction
+ {
+ };
+
struct SetRoomEncryptionAction
{
};
@@ -256,7 +268,7 @@
immer::map<std::string, Event> ephemeral;
- std::string localDraft;
+ immer::flex_vector<LocalDraft> localDrafts;
bool encrypted{false};
/// a marker to indicate whether we need to rotate
@@ -377,6 +389,8 @@
ChangeInviteStateAction,
AddEphemeralAction,
SetLocalDraftAction,
+ SetDraftRelAction,
+ PopLocalDraftAction,
SetRoomEncryptionAction,
MarkMembersFullyLoadedAction,
SetHeroIdsAction,
@@ -441,8 +455,6 @@
& r.timelineGaps
& r.ephemeral
- & r.localDraft
-
& r.encrypted
& r.shouldRotateSessionKey
@@ -491,6 +503,9 @@
if (version >= 9) {
ar & r.nonTimelineEvents;
}
+ if (version >= 10) {
+ ar & r.localDrafts;
+ }
}
template<class Archive>
@@ -502,5 +517,5 @@
BOOST_CLASS_VERSION(Kazv::PendingRoomKeyEvent, 1)
BOOST_CLASS_VERSION(Kazv::ReadReceipt, 0)
-BOOST_CLASS_VERSION(Kazv::RoomModel, 9)
+BOOST_CLASS_VERSION(Kazv::RoomModel, 10)
BOOST_CLASS_VERSION(Kazv::RoomListModel, 0)
diff --git a/src/client/room/room-model.cpp b/src/client/room/room-model.cpp
--- a/src/client/room/room-model.cpp
+++ b/src/client/room/room-model.cpp
@@ -277,7 +277,23 @@
return r;
},
[&](SetLocalDraftAction a) {
- r.localDraft = a.localDraft;
+ r.localDrafts = r.localDrafts.update(r.localDrafts.size() - 1,
+ [&a](auto localDraft) {
+ localDraft.text = a.localDraft;
+ return localDraft;
+ });
+ return r;
+ },
+ [&](SetDraftRelAction a) {
+ r.localDrafts = r.localDrafts.push_front({
+ a.text,
+ a.relType,
+ a.relatedEventId
+ });
+ return r;
+ },
+ [&](PopLocalDraftAction) {
+ r.localDrafts = r.localDrafts.drop(1);
return r;
},
[&](SetRoomEncryptionAction) {
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
@@ -335,8 +335,8 @@
KAZV_WRAP_ATTR(RoomModel, roomCursor(), roomId);
/*lager::reader<RoomMembership>*/
KAZV_WRAP_ATTR(RoomModel, roomCursor(), membership);
- /*lager::reader<std::string>*/
- KAZV_WRAP_ATTR(RoomModel, roomCursor(), localDraft);
+ /*lager::reader<immer::flex_vector<Kazv::LocalDraft>>*/
+ KAZV_WRAP_ATTR(RoomModel, roomCursor(), localDrafts);
/* lager::reader<bool> */
KAZV_WRAP_ATTR(RoomModel, roomCursor(), membersFullyLoaded);
@@ -375,7 +375,7 @@
* Set local draft for this room.
*
* After the returned Promise is resolved,
- * @c localDraft() will contain @c localDraft .
+ * @c localDrafts() will contain @c localDrafts.
*
* @param localDraft The local draft to send.
* @return A Promise that resolves when the local draft
@@ -383,6 +383,32 @@
*/
PromiseT setLocalDraft(std::string localDraft) const;
+ /**
+ * Set local draft and related event for this room.
+ *
+ * After the returned Promise is resolved,
+ * @c localDrafts() will contain @c localDrafts.
+ *
+ * @param text The local draft to send.
+ * @param relType One of ["m.replace", "m.reply"].
+ * @param relatedEventId The eventId related to the local draft.
+ * @return A Promise that resolves when the local draft
+ * has been set, or when there is an error.
+ */
+ PromiseT pushLocalDraft(std::string text,
+ std::string relType, std::string relatedEventId) const;
+
+ /**
+ * Pop a Kazv::LocalDraft in RoomModel::localDrafts.
+ *
+ * After the returned Promise is resolved,
+ * @c localDrafts() will contain @c localDrafts.
+ *
+ * @return A Promise that resolves when the local drafts
+ * has been popped, or when there is an error.
+ */
+ PromiseT popLocalDraft() const;
+
/**
* Send an event to this room.
*
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
@@ -323,6 +323,20 @@
return m_ctx.dispatch(UpdateRoomAction{+roomId(), SetLocalDraftAction{localDraft}});
}
+ auto Room::pushLocalDraft(std::string text,
+ std::string relType, std::string relatedEventId) const -> PromiseT
+ {
+ using namespace CursorOp;
+ return m_ctx.dispatch(UpdateRoomAction{+roomId(), SetDraftRelAction{
+ text, relType, relatedEventId}});
+ }
+
+ auto Room::popLocalDraft() const -> PromiseT
+ {
+ using namespace CursorOp;
+ return m_ctx.dispatch(UpdateRoomAction{+roomId(), PopLocalDraftAction {}});
+ }
+
auto Room::sendMessage(Event msg) const
-> PromiseT
{

File Metadata

Mime Type
text/plain
Expires
Thu, May 14, 8:36 PM (14 h, 44 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1470053
Default Alt Text
D296.1778816213.diff (7 KB)

Event Timeline