chatview: improve choice of displayed best name and id

Goes hand-in-hand with https://review.jami.net/c/ring-lrc/+/19096.

Change-Id: I1dd220215ebf9c0cc3c867b5594e1f3b99429997
parent 5f18701d
......@@ -1182,26 +1182,30 @@ update_chatview_frame(ChatView* self)
return;
}
// get alias and bestName
auto alias = contactInfo.profileInfo.alias;
auto bestName = contactInfo.registeredName;
// get bestName and bestId
auto bestName = contactInfo.profileInfo.alias.simplified();
auto bestId = contactInfo.registeredName.simplified();
if (bestName.isEmpty())
bestName = contactInfo.profileInfo.uri;
if (bestName == alias)
alias = "";
bestName.remove('\r');
alias.remove('\r');
bestName = contactInfo.registeredName.simplified();
if (bestId.isEmpty())
bestId = contactInfo.profileInfo.uri.simplified();
if (bestName == bestId)
bestName = "";
// get temporary status
bool temp = contactInfo.profileInfo.type == lrc::api::profile::Type::TEMPORARY || contactInfo.profileInfo.type == lrc::api::profile::Type::PENDING;
bool temp = contactInfo.profileInfo.type == lrc::api::profile::Type::TEMPORARY;
webkit_chat_update_chatview_frame(WEBKIT_CHAT_CONTAINER(priv->webkit_chat_container),
(*priv->accountInfo_)->enabled,
contactInfo.isBanned, temp, qUtf8Printable(alias), qUtf8Printable(bestName));
webkit_chat_update_chatview_frame(
WEBKIT_CHAT_CONTAINER(priv->webkit_chat_container),
(*priv->accountInfo_)->enabled,
contactInfo.isBanned,
temp,
qUtf8Printable(bestName),
qUtf8Printable(bestId));
webkit_chat_container_set_invitation(WEBKIT_CHAT_CONTAINER(priv->webkit_chat_container),
priv->conversation_->isRequest,
bestName.toStdString(),
contactInfo.profileInfo.uri.toStdString());
bestId.toStdString());
if (priv->conversation_->isSwarm() && priv->conversation_->isRequest) {
webkit_chat_hide_controls(WEBKIT_CHAT_CONTAINER(priv->webkit_chat_container), true);
webkit_chat_hide_message_bar(WEBKIT_CHAT_CONTAINER(priv->webkit_chat_container), true);
......
......@@ -770,11 +770,16 @@ webkit_chat_container_update_history(WebKitChatContainer *view,
}
void
webkit_chat_container_set_invitation(WebKitChatContainer *view, bool show,
const std::string& contactUri, const std::string& contactId)
webkit_chat_container_set_invitation(WebKitChatContainer *view,
bool show,
const std::string& bestName,
const std::string& bestId)
{
// TODO better escape names
gchar* function_call = g_strdup_printf(show ? "showInvitation(\"%s\", \"%s\")" : "showInvitation()", contactUri.c_str(), contactId.c_str());
gchar* function_call = g_strdup_printf(
show ? "showInvitation(\"%s\", \"%s\")" : "showInvitation()",
bestName.c_str(),
bestId.c_str());
webkit_chat_container_execute_js(view, function_call);
g_free(function_call);
}
......@@ -890,11 +895,18 @@ webkit_chat_set_is_composing(WebKitChatContainer *view, const std::string& conta
}
void
webkit_chat_update_chatview_frame(WebKitChatContainer *view, bool accountEnabled, bool isBanned, bool isTemporary, const gchar* alias, const gchar* bestId)
{
gchar* function_call = g_strdup_printf("update_chatview_frame(%s, %s, %s, \"%s\", \"%s\")",
accountEnabled ? "true" : "false",
isBanned ? "true" : "false", isTemporary ? "true" : "false", alias, bestId);
webkit_chat_update_chatview_frame(WebKitChatContainer *view,
bool accountEnabled, bool isBanned,
bool isInvited,
const gchar* bestName,
const gchar* bestId)
{
gchar* function_call = g_strdup_printf(
"update_chatview_frame(%s, %s, %s, \"%s\", \"%s\")",
accountEnabled ? "true" : "false",
isBanned ? "true" : "false",
isInvited ? "true" : "false",
bestName, bestId);
webkit_chat_container_execute_js(view, function_call);
g_free(function_call);
}
......@@ -54,7 +54,7 @@ void webkit_chat_container_update_history (WebKitChatContainer *view
void webkit_chat_container_set_sender_image (WebKitChatContainer *view, const std::string& sender, const std::string& senderImage);
gboolean webkit_chat_container_is_ready (WebKitChatContainer *view);
void webkit_chat_container_set_display_links (WebKitChatContainer *view, bool display);
void webkit_chat_container_set_invitation (WebKitChatContainer *view, bool show, const std::string& contactUri, const std::string& contactId);
void webkit_chat_container_set_invitation (WebKitChatContainer *view, bool show, const std::string& bestName, const std::string& bestId);
void webkit_chat_set_header_visible (WebKitChatContainer *view, bool isVisible);
void webkit_chat_hide_controls (WebKitChatContainer *view, bool hide);
void webkit_chat_hide_message_bar (WebKitChatContainer *view, bool hide);
......@@ -63,6 +63,6 @@ void webkit_chat_set_plugin_visible (WebKitChatContainer *view
void webkit_chat_set_dark_mode (WebKitChatContainer *view, bool darkMode, const std::string& background);
void webkit_chat_set_is_swarm (WebKitChatContainer *view, bool isSwarm);
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);
void webkit_chat_update_chatview_frame (WebKitChatContainer *view, bool accountEnabled, bool isBanned, bool isInvited, const gchar* bestName, const gchar* bestId);
G_END_DECLS
Markdown is supported
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