Commit 76b99874 authored by Sébastien Blin's avatar Sébastien Blin
Browse files

chatview: add typing indicator support

Change-Id: Ia200bc7d66ebabee24efe833aface281ee98bad2
parent 4f6f5f5d
......@@ -39,6 +39,10 @@
<default>true</default>
<summary>Enable notifications for incoming calls.</summary>
</key>
<key name="enable-typing-indication" type="b">
<default>true</default>
<summary>Enable typing indications into the chatview.</summary>
</key>
<key name="enable-pending-notifications" type="b">
<default>true</default>
<summary>Enable notifications for pending requests.</summary>
......
......@@ -97,6 +97,7 @@ struct _ChatViewPrivate
AccountInfoPointer const * accountInfo_;
QMetaObject::Connection new_interaction_connection;
QMetaObject::Connection composing_changed_connection;
QMetaObject::Connection interaction_removed;
QMetaObject::Connection update_interaction_connection;
QMetaObject::Connection update_add_to_conversations;
......@@ -155,6 +156,7 @@ chat_view_dispose(GObject *object)
priv = CHAT_VIEW_GET_PRIVATE(view);
QObject::disconnect(priv->new_interaction_connection);
QObject::disconnect(priv->composing_changed_connection);
QObject::disconnect(priv->update_interaction_connection);
QObject::disconnect(priv->interaction_removed);
QObject::disconnect(priv->update_add_to_conversations);
......@@ -641,6 +643,12 @@ webkit_chat_container_script_dialog(GtkWidget* webview, gchar *interaction, Chat
} catch (...) {
// ignore
}
} else if (order.find("ON_COMPOSING:") == 0) {
auto composing = order.substr(std::string("ON_COMPOSING:").size()) == "true";
if (!priv->conversation_) return;
if (g_settings_get_boolean(priv->settings, "enable-typing-indication")) {
(*priv->accountInfo_)->conversationModel->setIsComposing(priv->conversation_->uid, composing);
}
}
}
......@@ -1135,6 +1143,18 @@ build_chat_view(ChatView* self)
}
});
priv->composing_changed_connection = QObject::connect(
&*(*priv->accountInfo_)->conversationModel, &lrc::api::ConversationModel::composingStatusChanged,
[self, priv](const QString& uid, const QString& contactUri, bool isComposing) {
if (!g_settings_get_boolean(priv->settings, "enable-typing-indication")) return;
if (!priv->conversation_) return;
if (uid == priv->conversation_->uid) {
webkit_chat_set_is_composing(
WEBKIT_CHAT_CONTAINER(priv->webkit_chat_container),
contactUri.toStdString(), isComposing);
}
});
priv->cpp = new CppImpl();
if (webkit_chat_container_is_ready(WEBKIT_CHAT_CONTAINER(priv->webkit_chat_container)))
......
......@@ -64,6 +64,7 @@ struct _GeneralSettingsViewPrivate
GtkWidget *request_notifications_button;
GtkWidget *chat_notifications_button;
GtkWidget *media_chatview_button;
GtkWidget *typing_indication_button;
GtkWidget *chatview_pos_button;
GtkWidget *button_choose_downloads_directory;
......@@ -313,6 +314,9 @@ general_settings_view_init(GeneralSettingsView *self)
g_settings_bind(priv->settings, "enable-display-links",
priv->media_chatview_button, "active",
G_SETTINGS_BIND_DEFAULT);
g_settings_bind(priv->settings, "enable-typing-indication",
priv->typing_indication_button, "active",
G_SETTINGS_BIND_DEFAULT);
g_settings_bind(priv->settings, "enable-pending-notifications",
priv->request_notifications_button, "active",
G_SETTINGS_BIND_DEFAULT);
......@@ -411,6 +415,7 @@ general_settings_view_class_init(GeneralSettingsViewClass *klass)
gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), GeneralSettingsView, incoming_open_button);
gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), GeneralSettingsView, call_notifications_button);
gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), GeneralSettingsView, media_chatview_button);
gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), GeneralSettingsView, typing_indication_button);
gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), GeneralSettingsView, request_notifications_button);
gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), GeneralSettingsView, chat_notifications_button);
gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), GeneralSettingsView, chatview_pos_button);
......
......@@ -797,6 +797,14 @@ webkit_chat_set_dark_mode(WebKitChatContainer *view, bool darkMode, const std::s
g_free(function_call);
}
void
webkit_chat_set_is_composing(WebKitChatContainer *view, const std::string& contactUri, bool isComposing)
{
gchar* function_call = g_strdup_printf("showTypingIndicator(\"%s\", %s)", contactUri.c_str(), isComposing ? "true" : "false");
webkit_chat_container_execute_js(view, function_call);
g_free(function_call);
}
void
webkit_chat_update_chatview_frame(WebKitChatContainer *view, bool accountEnabled, bool isBanned, bool isTemporary, const gchar* alias, const gchar* bestId)
{
......
......@@ -57,6 +57,7 @@ void webkit_chat_container_set_invitation (WebKitChatContainer *view
void webkit_chat_set_header_visible (WebKitChatContainer *view, bool isVisible);
void webkit_chat_set_record_visible (WebKitChatContainer *view, bool isVisible);
void webkit_chat_set_dark_mode (WebKitChatContainer *view, bool darkMode, const std::string& background);
void webkit_chat_set_is_composing (WebKitChatContainer *view, const std::string& contactUri, bool isComposing);
void webkit_chat_update_chatview_frame (WebKitChatContainer *view, bool accountEnabled, bool isBanned, bool isInvited, const gchar* alias, const gchar* bestId);
G_END_DECLS
......@@ -361,6 +361,42 @@
<property name="halign">fill</property>
<property name="selection_mode">none</property>
<child>
<!-- Typing indication -->
<object class="GtkListBoxRow" id="typing_indication_row">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="halign">fill</property>
<child>
<object class="GtkBox" id="typing_indication_box">
<property name="visible">True</property>
<property name="halign">fill</property>
<property name="orientation">horizontal</property>
<property name="margin_left">12</property>
<property name="margin_right">12</property>
<property name="margin_top">12</property>
<property name="margin_bottom">12</property>
<child>
<object class="GtkLabel" id="label_typing_indication">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Show typing indications</property>
</object>
</child>
<child>
<object class="GtkSwitch" id="typing_indication_button">
<property name="visible">True</property>
<property name="can_focus">True</property>
</object>
<packing>
<property name="pack_type">end</property>
</packing>
</child>
</object>
</child>
</object>
</child>
<child>
<!-- Chatview medias -->
<object class="GtkListBoxRow" id="media_chatview_row">
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment