Skip to content

Commit

Permalink
Send typing status
Browse files Browse the repository at this point in the history
  • Loading branch information
naxuroqa committed Feb 19, 2018
1 parent e693392 commit 2388812
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/tox/ToxSession.vala
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ namespace Venom {

public abstract void self_set_user_name(string name);
public abstract void self_set_status_message(string status);
public abstract void self_set_typing(uint32 friend_number, bool typing) throws ToxError;

public abstract uint8[] self_get_address();

Expand Down Expand Up @@ -407,6 +408,15 @@ namespace Venom {
listener.on_friend_message_sent(friend_number, ret, message);
}

public virtual void self_set_typing(uint32 friend_number, bool typing) throws ToxError {
var e = ErrSetTyping.OK;
handle.self_set_typing(friend_number, typing, ref e);
if (e != ErrSetTyping.OK) {
logger.i("self_set_typing failed: " + e.to_string());
throw new ToxError.GENERIC(e.to_string());
}
}

private void conference_set_title_private(uint32 conference_number, string title) throws ToxError {
var e = ErrConferenceTitle.OK;
handle.conference_set_title(conference_number, title, ref e);
Expand Down
10 changes: 10 additions & 0 deletions src/tox/ToxSessionListener.vala
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ namespace Venom {
private GLib.HashTable<uint32, IContact> friends;
private GLib.HashTable<uint32, IContact> conferences;

public bool show_typing { get; set; }

public ToxSessionListenerImpl(ILogger logger, UserInfo user_info, Contacts contacts, GLib.HashTable<IContact, Conversation> conversations) {
logger.d("ToxSessionListenerImpl created.");
this.logger = logger;
Expand Down Expand Up @@ -106,6 +108,14 @@ namespace Venom {
session.friend_send_message(contact.tox_friend_number, message);
}

public virtual void on_set_typing(IContact c, bool typing) throws Error {
if (!show_typing) {
return;
}
var contact = c as Contact;
session.self_set_typing(contact.tox_friend_number, typing);
}

public virtual void on_send_conference_message(IContact c, string message) throws Error {
var conference = c as GroupchatContact;
session.conference_send_message(conference.tox_conference_number, message);
Expand Down
2 changes: 2 additions & 0 deletions src/ui/ApplicationWindow.vala
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ namespace Venom {
session_listener = new ToxSessionListenerImpl(logger, user_info, contacts, conversations);
session_listener.attach_to_session(session);

settings_database.bind_property("enable-send-typing", session_listener, "show-typing", BindingFlags.SYNC_CREATE);

init_widgets();
init_callbacks();

Expand Down
20 changes: 20 additions & 0 deletions src/ui/ConversationWindow.vala
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ namespace Venom {
private ILogger logger;
private Conversation conversation;
private ConversationWidgetListener listener;
private bool is_typing;

public ConversationWindow(ApplicationWindow app_window, ILogger logger, Conversation conversation, ConversationWidgetListener listener) {
this.app_window = app_window;
Expand All @@ -64,6 +65,7 @@ namespace Venom {
unmap.connect(() => { message_list.bind_model(null, null); });

text_view.key_press_event.connect(on_keypress);
text_view.buffer.changed.connect(on_buffer_changed);
app_window.add_action_entries(win_entries, this);

// trigger autoscroll
Expand Down Expand Up @@ -106,6 +108,23 @@ namespace Venom {
} catch (Error e) {
logger.e("Could not send message: " + e.message);
}
try_set_typing(false);
}

private void on_buffer_changed() {
var typing = text_view.buffer.text != "";
if (typing != is_typing) {
is_typing = typing;
try_set_typing(typing);
}
}

private void try_set_typing(bool typing) {
try {
listener.on_set_typing(conversation.get_contact(), typing);
} catch (Error e) {
logger.e("Could not set typing status: " + e.message);
}
}

private bool on_keypress(Gdk.EventKey event) {
Expand Down Expand Up @@ -146,6 +165,7 @@ namespace Venom {

public interface ConversationWidgetListener : GLib.Object {
public abstract void on_send_message(IContact contact, string message) throws Error;
public abstract void on_set_typing(IContact contact, bool typing) throws Error;
}

public class ConversationModel : GLib.Object, GLib.ListModel {
Expand Down

0 comments on commit 2388812

Please sign in to comment.