Commit f33a8f52 authored by Sébastien Blin's avatar Sébastien Blin Committed by Philippe Gorley

chatview: show generated avatar into the chatview

Change-Id: I7f132d4c5d7a1e68463cd065015e2639664250f6
Gitlab: #947
parent 9f8431e4
...@@ -30,6 +30,9 @@ ...@@ -30,6 +30,9 @@
// GTK // GTK
#include <glib/gi18n.h> #include <glib/gi18n.h>
// Qt
#include <QSize>
// LRC // LRC
#include <api/contactmodel.h> #include <api/contactmodel.h>
#include <api/conversationmodel.h> #include <api/conversationmodel.h>
...@@ -38,8 +41,12 @@ ...@@ -38,8 +41,12 @@
#include <api/call.h> #include <api/call.h>
// Client // Client
#include "utils/files.h"
#include "marshals.h" #include "marshals.h"
#include "utils/files.h"
#include "native/pixbufmanipulator.h"
/* size of avatar */
static constexpr int AVATAR_WIDTH = 150; /* px */
static constexpr int AVATAR_HEIGHT = 150; /* px */
struct CppImpl { struct CppImpl {
struct Interaction { struct Interaction {
...@@ -460,25 +467,41 @@ load_participants_images(ChatView *self) ...@@ -460,25 +467,41 @@ load_participants_images(ChatView *self)
auto contactUri = priv->conversation_->participants.front(); auto contactUri = priv->conversation_->participants.front();
try{ try{
auto& contact = (*priv->accountInfo_)->contactModel->getContact(contactUri); auto& contact = (*priv->accountInfo_)->contactModel->getContact(contactUri);
if (!contact.profileInfo.avatar.empty()) { std::string avatar_str = contact.profileInfo.avatar;
webkit_chat_container_set_sender_image( if (avatar_str.empty()) {
WEBKIT_CHAT_CONTAINER(priv->webkit_chat_container), auto var_photo = Interfaces::PixbufManipulator().conversationPhoto(
contactUri, *priv->conversation_,
contact.profileInfo.avatar **(priv->accountInfo_),
); QSize(AVATAR_WIDTH, AVATAR_HEIGHT),
contact.isPresent
);
auto image = var_photo.value<std::shared_ptr<GdkPixbuf>>();
auto ba = Interfaces::PixbufManipulator().toByteArray(var_photo);
avatar_str = ba.toBase64().toStdString();
} }
webkit_chat_container_set_sender_image(
WEBKIT_CHAT_CONTAINER(priv->webkit_chat_container),
contactUri,
avatar_str
);
} catch (const std::out_of_range&) { } catch (const std::out_of_range&) {
// ContactModel::getContact() exception // ContactModel::getContact() exception
} }
// For this account // For this account
if (!(*priv->accountInfo_)->profileInfo.avatar.empty()) { std::string avatar_str = (*priv->accountInfo_)->profileInfo.avatar;
webkit_chat_container_set_sender_image( if (avatar_str.empty()) {
WEBKIT_CHAT_CONTAINER(priv->webkit_chat_container), auto default_photo = QVariant::fromValue(Interfaces::PixbufManipulator().scaleAndFrame(
(*priv->accountInfo_)->profileInfo.uri, Interfaces::PixbufManipulator().generateAvatar("", "").get(),
(*priv->accountInfo_)->profileInfo.avatar QSize(AVATAR_WIDTH, AVATAR_HEIGHT), false));
); auto ba = Interfaces::PixbufManipulator().toByteArray(default_photo);
avatar_str = ba.toBase64().toStdString();
} }
webkit_chat_container_set_sender_image(
WEBKIT_CHAT_CONTAINER(priv->webkit_chat_container),
(*priv->accountInfo_)->profileInfo.uri,
avatar_str
);
} }
static void static void
......
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