Skip to content

Commit e770dcd

Browse files
committed
Fix pinned messages being dropped by accident
1 parent be9f68a commit e770dcd

2 files changed

Lines changed: 24 additions & 3 deletions

File tree

src/pinned_messages_manager.vala

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,15 @@ namespace Dc {
55
public Gtk.Revealer revealer { get; private set; }
66

77
private unowned Window? window = null;
8+
private unowned RpcClient? rpc = null;
89
private Gtk.Box bar_content;
910
private int[] msg_ids = {};
1011
private int current_chat_id = 0;
1112
private unowned GLib.ListStore message_store;
1213
private unowned SettingsManager settings;
1314

15+
public string? self_email { get; set; default = null; }
16+
1417
public PinnedMessagesManager (GLib.ListStore message_store,
1518
SettingsManager settings) {
1619
this.message_store = message_store;
@@ -25,6 +28,7 @@ namespace Dc {
2528
}
2629

2730
public void set_window (Window w) { this.window = w; }
31+
public void set_rpc (RpcClient r) { this.rpc = r; }
2832

2933
public void load_for_chat (int chat_id) {
3034
current_chat_id = chat_id;
@@ -68,10 +72,10 @@ namespace Dc {
6872
m.is_pinned = is_pinned (msg_id);
6973
refresh_in_store (msg_id);
7074
}
71-
update_bar ();
75+
update_bar.begin ();
7276
}
7377

74-
public void update_bar () {
78+
public async void update_bar () {
7579
/* Clear existing pinned entries */
7680
Gtk.Widget? child;
7781
while ((child = bar_content.get_first_child ()) != null) {
@@ -94,6 +98,18 @@ namespace Dc {
9498
sender = m.is_outgoing ? "You" : (m.sender_name ?? "");
9599
}
96100

101+
/* Fetch from RPC if not in the loaded batch */
102+
if (text == null && sender == null && rpc != null) {
103+
try {
104+
var msg_obj = yield rpc.get_message (rpc.account_id, pin_id);
105+
if (msg_obj != null) {
106+
var fetched = RpcClient.parse_message (msg_obj, self_email);
107+
text = fetched.text;
108+
sender = fetched.is_outgoing ? "You" : (fetched.sender_name ?? "");
109+
}
110+
} catch (Error e) { /* skip on error */ }
111+
}
112+
97113
if (text == null && sender == null) continue;
98114

99115
var row_btn = new Gtk.Button ();

src/window.vala

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,7 @@ namespace Dc {
356356

357357
private async void try_connect () {
358358
rpc = ((Dc.Application) this.application).rpc;
359+
pinned.set_rpc (rpc);
359360

360361
/* Find the RPC server binary */
361362
string[]? rpc_cmd = AccountFinder.find_rpc_server ();
@@ -408,11 +409,13 @@ namespace Dc {
408409
msg_actions = new MessageActions (this, rpc, message_store, pinned,
409410
compose_bar, settings);
410411
msg_actions.self_email = self_email;
412+
pinned.self_email = self_email;
411413

412414
if (rpc.account_id > 0) {
413415
try {
414416
self_email = yield rpc.get_config (rpc.account_id, "addr");
415417
msg_actions.self_email = self_email;
418+
pinned.self_email = self_email;
416419
events.self_email = self_email;
417420
} catch (Error ce) {
418421
self_email = null;
@@ -577,7 +580,7 @@ namespace Dc {
577580
return Source.REMOVE;
578581
});
579582

580-
pinned.update_bar ();
583+
pinned.update_bar.begin ();
581584
} catch (Error e) {
582585
show_toast ("Failed to load messages: " + e.message);
583586
}
@@ -1015,6 +1018,7 @@ namespace Dc {
10151018
if (rpc.account_id <= 0) {
10161019
self_email = null;
10171020
if (msg_actions != null) msg_actions.self_email = null;
1021+
pinned.self_email = null;
10181022
content_stack.visible_child_name = "empty";
10191023
current_chat_id = 0;
10201024
return;
@@ -1025,6 +1029,7 @@ namespace Dc {
10251029
self_email = null;
10261030
}
10271031
if (msg_actions != null) msg_actions.self_email = self_email;
1032+
pinned.self_email = self_email;
10281033
if (events != null) events.self_email = self_email;
10291034
current_chat_id = 0;
10301035
content_stack.visible_child_name = "empty";

0 commit comments

Comments
 (0)