Skip to content

Commit

Permalink
Messaging UI: add a label to pending messages on disconnect
Browse files Browse the repository at this point in the history
If a device goes offline before receiving confirmation for a pending
message, add a label indicating the message may not have been sent.

When receiving new messages, compare the content and timestamp before
removing a pending message, rather than unconditionally removing them
when the device reconnects.

closes #1355
  • Loading branch information
andyholmes committed Jul 27, 2022
1 parent 4b951b9 commit 5ddf120
Showing 1 changed file with 22 additions and 17 deletions.
39 changes: 22 additions & 17 deletions src/service/ui/messaging.js
Original file line number Diff line number Diff line change
Expand Up @@ -444,8 +444,14 @@ const Conversation = GObject.registerClass({
}

_onConnected(device) {
if (device.connected)
this.pending_box.foreach(msg => msg.destroy());
// The device has disconnected, so add a label to any pending messages
// indicating they may not have completed sending.
if (!device.connected) {
this.pending_box.foreach(pending => {
pending.sender_label.label = _('Message not sent');
pending.sender_label.visible = true;
});
}
}

_onDestroy(conversation) {
Expand Down Expand Up @@ -495,19 +501,12 @@ const Conversation = GObject.registerClass({
this.plugin.sendMessage(this.addresses, this.entry.text);

// Add a phony message in the pending box
const message = new Gtk.Label({
label: URI.linkify(this.entry.text),
halign: Gtk.Align.END,
selectable: true,
use_markup: true,
visible: true,
wrap: true,
wrap_mode: Pango.WrapMode.WORD_CHAR,
xalign: 0,
const message = new ConversationMessage(null, {
addresses: this.addresses,
date: Date.now(),
body: this.entry.text,
type: Sms.MessageBox.SENT,
});
message.get_style_context().add_class('message-out');
message.date = Date.now();
message.type = Sms.MessageBox.SENT;

// Notify to reveal the pending box
this.pending_box.add(message);
Expand Down Expand Up @@ -664,10 +663,16 @@ const Conversation = GObject.registerClass({
this.list.add(row);
this.list.invalidate_headers();

// Remove the first pending message
// Check pending messages for confirmation
if (this.has_pending && message.type === Sms.MessageBox.SENT) {
this.pending_box.get_children()[0].destroy();
this.notify('has-pending');
for (const pending of this.pending_box.get_children()) {
if (message.body === pending.message.body &&
message.date >= pending.message.date) {
pending.destroy();
this.notify('has-pending');
break;
}
}
}
} catch (e) {
debug(e);
Expand Down

0 comments on commit 5ddf120

Please sign in to comment.