aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKitsune Ral <Kitsune-Ral@users.sf.net>2018-08-03 17:14:40 +0900
committerKitsune Ral <Kitsune-Ral@users.sf.net>2018-08-03 17:14:40 +0900
commit527a12eb5b6009f679b7e18eceda782f3f5747b7 (patch)
tree0f33e6db11f5e9862708e70a31f0d1c1303a65ab
parentde72fb7f9b6e36021c284c011f19714defe80713 (diff)
downloadlibquotient-527a12eb5b6009f679b7e18eceda782f3f5747b7.tar.gz
libquotient-527a12eb5b6009f679b7e18eceda782f3f5747b7.zip
Room::retryMessage and Room::discardMessage
-rw-r--r--lib/room.cpp21
-rw-r--r--lib/room.h4
2 files changed, 25 insertions, 0 deletions
diff --git a/lib/room.cpp b/lib/room.cpp
index e615060b..3467e301 100644
--- a/lib/room.cpp
+++ b/lib/room.cpp
@@ -1195,6 +1195,27 @@ QString Room::postMessage(const QString& type, const QString& plainText)
return d->sendEvent<RoomMessageEvent>(plainText, type);
}
+QString Room::retryMessage(const QString& txnId)
+{
+ auto it = std::find_if(d->unsyncedEvents.begin(), d->unsyncedEvents.end(),
+ [txnId] (const auto& evt) { return evt->transactionId() == txnId; });
+ Q_ASSERT(it != d->unsyncedEvents.end());
+ qDebug(EVENTS) << "Retrying transaction" << txnId;
+ it->resetStatus();
+ return d->doSendEvent(it->event());
+}
+
+void Room::discardMessage(const QString& txnId)
+{
+ auto it = std::find_if(d->unsyncedEvents.begin(), d->unsyncedEvents.end(),
+ [txnId] (const auto& evt) { return evt->transactionId() == txnId; });
+ Q_ASSERT(it != d->unsyncedEvents.end());
+ qDebug(EVENTS) << "Discarding transaction" << txnId;
+ emit pendingEventAboutToDiscard(it - d->unsyncedEvents.begin());
+ d->unsyncedEvents.erase(it);
+ emit pendingEventDiscarded();
+}
+
QString Room::postMessage(const QString& plainText, MessageEventType type)
{
return d->sendEvent<RoomMessageEvent>(plainText, type);
diff --git a/lib/room.h b/lib/room.h
index 15e2146e..5c7524d6 100644
--- a/lib/room.h
+++ b/lib/room.h
@@ -318,6 +318,8 @@ namespace QMatrixClient
/** @deprecated If you have a custom event type, construct the event
* and pass it as a whole to postMessage() */
QString postMessage(const QString& type, const QString& plainText);
+ QString retryMessage(const QString& txnId);
+ void discardMessage(const QString& txnId);
void setName(const QString& newName);
void setCanonicalAlias(const QString& newAlias);
void setTopic(const QString& newTopic);
@@ -353,6 +355,8 @@ namespace QMatrixClient
void pendingEventAboutToMerge(RoomEvent* serverEvent,
int pendingEventIndex);
void pendingEventMerged();
+ void pendingEventAboutToDiscard(int pendingEventIndex);
+ void pendingEventDiscarded();
void pendingEventChanged(int pendingEventIndex);
/**