From d151ac49f26ece58a83450592f9b6e3ead6a84fe Mon Sep 17 00:00:00 2001 From: Kegan Dougal Date: Thu, 18 Jun 2015 09:32:04 +0100 Subject: [PATCH] Mark events which fail to send. --- CHANGELOG.md | 6 ++++-- README.md | 2 +- examples/node/app.js | 5 ++++- lib/client.js | 4 ++++ lib/matrix.js | 2 ++ lib/models/event.js | 7 +++---- 6 files changed, 18 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 695bc8253..94c8b3438 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,5 +11,7 @@ New properties: New features: * Local echo. When you send an event using the SDK it will immediately be - added to the timeline with the event.status of `'sending'`. When the event is - finally sent, this status will be removed. + added to the timeline with the event.status of `EventStatus.SENDING`. When + the event is finally sent, this status will be removed. + * Not sent status. When an event fails to send using the SDK, it will have the + `event.status` of `EventStatus.NOT_SENT`. diff --git a/README.md b/README.md index e929ea2cf..f401c2834 100644 --- a/README.md +++ b/README.md @@ -48,11 +48,11 @@ events for incoming data and state changes. Aside from wrapping the HTTP API, it that have just been sent will appear in the timeline as 'sending', until it completes. This is beneficial because it prevents there being a gap between hitting the send button and having the "remote echo" arrive. + - Mark messages which failed to send as not sent. Later versions of the SDK will: - Automatically retry requests to send messages due to network errors. - Automatically retry requests to send messages due to rate limiting errors. - - Mark events' sent status (e.g. 'not sent'). - Handle queueing of messages. - Handle pagination. - Expose a `RoomSummary` which would be suitable for a recents page. diff --git a/examples/node/app.js b/examples/node/app.js index f777c6380..a7533be6f 100644 --- a/examples/node/app.js +++ b/examples/node/app.js @@ -153,9 +153,12 @@ function printLine(event) { if (event.getSender() === myUserId) { name = "Me"; separator = ">>>"; - if (event.status === "sending") { + if (event.status === sdk.EventStatus.SENDING) { separator = "..."; } + else if (event.status === sdk.EventStatus.NOT_SENT) { + separator = " x "; + } } var body = ""; diff --git a/lib/client.js b/lib/client.js index f5527ac37..9ec66c886 100644 --- a/lib/client.js +++ b/lib/client.js @@ -274,6 +274,10 @@ MatrixClient.prototype.sendEvent = function(roomId, eventType, content, txnId, localEvent.status = null; } } + }, function(err) { + if (localEvent) { + localEvent.status = EventStatus.NOT_SENT; + } }); }; diff --git a/lib/matrix.js b/lib/matrix.js index 0e04b9904..1a307a6b8 100644 --- a/lib/matrix.js +++ b/lib/matrix.js @@ -2,6 +2,8 @@ /** The {@link module:models/event.MatrixEvent|MatrixEvent} class. */ module.exports.MatrixEvent = require("./models/event").MatrixEvent; +/** The {@link module:models/event.EventStatus|EventStatus} enum. */ +module.exports.EventStatus = require("./models/event").EventStatus; /** The {@link module:store/memory.MatrixInMemoryStore|MatrixInMemoryStore} class. */ module.exports.MatrixInMemoryStore = require("./store/memory").MatrixInMemoryStore; /** The {@link module:http-api.MatrixHttpApi|MatrixHttpApi} class. */ diff --git a/lib/models/event.js b/lib/models/event.js index 7e783e499..57ad84db7 100644 --- a/lib/models/event.js +++ b/lib/models/event.js @@ -12,11 +12,10 @@ * @enum {string} */ module.exports.EventStatus = { - UNKNOWN: "unknown", - SENT: "sent", + /** The event was not sent and will no longer be retried. */ NOT_SENT: "not_sent", - SENDING: "sending", - INCOMING: "incoming" + /** The event is in the process of being sent. */ + SENDING: "sending" }; /**