aboutsummaryrefslogtreecommitdiff
path: root/main/src/ui/conversation_selector
diff options
context:
space:
mode:
authorfiaxh <git@mx.ax.lt>2017-03-18 23:44:05 +0100
committerfiaxh <git@mx.ax.lt>2017-03-18 23:44:05 +0100
commitbe2234835a96601ac7dfffa93bd27a70a02b299e (patch)
treee452bda72de538a209a913f900a059cbdc954b82 /main/src/ui/conversation_selector
parent582cc78edd35d7d3a9ab6ddc579919306a2325f5 (diff)
downloaddino-be2234835a96601ac7dfffa93bd27a70a02b299e.tar.gz
dino-be2234835a96601ac7dfffa93bd27a70a02b299e.zip
Preselect next conversation when closed and crossfade
Diffstat (limited to 'main/src/ui/conversation_selector')
-rw-r--r--main/src/ui/conversation_selector/conversation_row.vala5
-rw-r--r--main/src/ui/conversation_selector/list.vala58
2 files changed, 42 insertions, 21 deletions
diff --git a/main/src/ui/conversation_selector/conversation_row.vala b/main/src/ui/conversation_selector/conversation_row.vala
index 0a6b7e70..ef3984c1 100644
--- a/main/src/ui/conversation_selector/conversation_row.vala
+++ b/main/src/ui/conversation_selector/conversation_row.vala
@@ -11,6 +11,9 @@ namespace Dino.Ui.ConversationSelector {
[GtkTemplate (ui = "/org/dino-im/conversation_selector/conversation_row.ui")]
public abstract class ConversationRow : ListBoxRow {
+ public signal void closed();
+ public signal void disappeared();
+
[GtkChild] protected Image image;
[GtkChild] private Label name_label;
[GtkChild] private Label time_label;
@@ -120,8 +123,10 @@ public abstract class ConversationRow : ListBoxRow {
private void on_x_button_clicked() {
main_revealer.set_transition_type(RevealerTransitionType.SLIDE_UP);
main_revealer.set_reveal_child(false);
+ closed();
main_revealer.notify["child-revealed"].connect(() => {
conversation.active = false;
+ disappeared();
});
}
diff --git a/main/src/ui/conversation_selector/list.vala b/main/src/ui/conversation_selector/list.vala
index 804cfad3..071ac504 100644
--- a/main/src/ui/conversation_selector/list.vala
+++ b/main/src/ui/conversation_selector/list.vala
@@ -32,10 +32,10 @@ public class List : ListBox {
Idle.add(() => {add_conversation(conversation); return false;});
});
MessageManager.get_instance(stream_interactor).message_received.connect((message, conversation) => {
- Idle.add(() => {message_received(message, conversation); return false;});
+ Idle.add(() => {on_message_received(message, conversation); return false;});
});
MessageManager.get_instance(stream_interactor).message_sent.connect((message, conversation) => {
- Idle.add(() => {message_received(message, conversation); return false;});
+ Idle.add(() => {on_message_received(message, conversation); return false;});
});
PresenceManager.get_instance(stream_interactor).show_received.connect((show, jid, account) => {
Idle.add(() => {
@@ -93,7 +93,21 @@ public class List : ListBox {
invalidate_filter();
}
- public void add_conversation(Conversation conversation) {
+ public void on_conversation_selected(Conversation conversation) {
+ if (!rows.has_key(conversation)) {
+ add_conversation(conversation);
+ }
+ this.select_row(rows[conversation]);
+ }
+
+ private void on_message_received(Entities.Message message, Conversation conversation) {
+ if (rows.has_key(conversation)) {
+ rows[conversation].message_received(message);
+ invalidate_sort();
+ }
+ }
+
+ private void add_conversation(Conversation conversation) {
ConversationRow row;
if (!rows.has_key(conversation)) {
if (conversation.type_ == Conversation.Type.GROUPCHAT) {
@@ -103,33 +117,35 @@ public class List : ListBox {
}
rows[conversation] = row;
add(row);
+ row.closed.connect(() => { on_conversation_closed(conversation); });
+ row.disappeared.connect(() => { on_conversation_disappeared(conversation); });
row.main_revealer.set_reveal_child(true);
- conversation.notify["active"].connect((s, p) => {
- if (rows.has_key(conversation) && !conversation.active) {
- remove_conversation(conversation);
- }
- });
}
invalidate_sort();
queue_draw();
}
- public void remove_conversation(Conversation conversation) {
- remove(rows[conversation]);
- rows.unset(conversation);
- }
-
- public void on_conversation_selected(Conversation conversation) {
- if (!rows.has_key(conversation)) {
- add_conversation(conversation);
+ private void on_conversation_closed(Conversation conversation) {
+ if (get_selected_row() == rows[conversation]) {
+ int index = rows[conversation].get_index();
+ ListBoxRow? index_p1 = get_row_at_index(index + 1);
+ if (index_p1 != null) {
+ select_row(index_p1);
+ row_activated(index_p1);
+ } else if (index > 0) {
+ ListBoxRow? index_m1 = get_row_at_index(index - 1);
+ if (index_m1 != null) {
+ select_row(index_m1);
+ row_activated(index_p1);
+ }
+ }
}
- this.select_row(rows[conversation]);
}
- private void message_received(Entities.Message message, Conversation conversation) {
- if (rows.has_key(conversation)) {
- rows[conversation].message_received(message);
- invalidate_sort();
+ private void on_conversation_disappeared(Conversation conversation) {
+ if (rows.has_key(conversation) && !conversation.active) {
+ remove(rows[conversation]);
+ rows.unset(conversation);
}
}