Skip to content
Snippets Groups Projects
Commit b2643f59 authored by Nicolas Vengeon's avatar Nicolas Vengeon Committed by Sébastien Blin
Browse files

messagelistmodel: correctly search for index in model

Iterate through CPP elements and use positionView(ListView.Center)
as other approach seems bugguy or slower.

Change-Id: I43879969ccb457166879a156efb482e77ff07d6b
parent 97709217
No related branches found
No related tags found
No related merge requests found
......@@ -54,6 +54,7 @@ Control {
readonly property real msgRadius: 20
readonly property real hPadding: JamiTheme.sbsMessageBasePreferredPadding
property bool textHovered: false
property alias replyAnimation: selectAnimation
width: ListView.view ? ListView.view.width : 0
height: mainColumnLayout.implicitHeight
......@@ -353,6 +354,20 @@ Control {
to: 0
duration: JamiTheme.longFadeDuration
}
PropertyAnimation {
properties: "opacity"
target: opacityMask
from: 0
to: 1
duration: JamiTheme.longFadeDuration
}
PropertyAnimation {
properties: "opacity"
target: opacityMask
from: 1
to: 0
duration: JamiTheme.longFadeDuration
}
}
OpacityMask {
......
......@@ -152,16 +152,9 @@ JamiListView {
Connections {
target: CurrentConversation
function onIdChanged() { fadeAnimation.start() }
function onScrollTo(id) {
var idx = -1
for (var i = 1; i < root.count; i++) {
var delegate = root.itemAtIndex(i)
if (delegate && delegate.id === id) {
idx = i
}
}
positionViewAtIndex(idx, ListView.Center)
var idx = MessagesAdapter.getMessageIndexFromId(id)
positionViewAtIndex(idx, ListView.Visible)
}
}
......
......@@ -761,6 +761,23 @@ MessagesAdapter::getConvMedias()
}
}
int
MessagesAdapter::getMessageIndexFromId(QString& id)
{
const QString& convId = lrcInstance_->get_selectedConvUid();
const auto& conversation = lrcInstance_->getConversationFromConvUid(convId);
auto allInteractions = conversation.interactions.get();
int index = 0;
for (auto it = allInteractions->rbegin(); it != allInteractions->rend(); it++) {
if (interaction::isDisplayedInChatview(it->second.type)) {
if (it->first == id)
return index;
index++;
}
}
return -1;
}
MessageListModel*
MessagesAdapter::getMsgListSourceModel() const
{
......
......@@ -42,9 +42,7 @@ public:
auto index = sourceModel()->index(sourceRow, 0, sourceParent);
auto type = static_cast<interaction::Type>(
sourceModel()->data(index, MessageList::Role::Type).toInt());
return type != interaction::Type::MERGE && type != interaction::Type::EDITED
&& type != interaction::Type::REACTION && type != interaction::Type::VOTE
&& type != interaction::Type::UPDATE_PROFILE && type != interaction::Type::INVALID;
return interaction::isDisplayedInChatview(type);
};
bool lessThan(const QModelIndex& left, const QModelIndex& right) const override
{
......@@ -136,6 +134,7 @@ protected:
Q_INVOKABLE QVariant dataForInteraction(const QString& interactionId,
int role = Qt::DisplayRole) const;
Q_INVOKABLE void getConvMedias();
Q_INVOKABLE int getMessageIndexFromId(QString& id);
// Run corrsponding js functions, c++ to qml.
void setMessagesImageContent(const QString& path, bool isBased64 = false);
......
......@@ -47,6 +47,13 @@ enum class Type {
COUNT__
};
Q_ENUM_NS(Type)
static inline bool
isDisplayedInChatview(const Type& type)
{
return type != interaction::Type::MERGE && type != interaction::Type::EDITED
&& type != interaction::Type::REACTION && type != interaction::Type::VOTE
&& type != interaction::Type::UPDATE_PROFILE && type != interaction::Type::INVALID;
}
static inline const QString
to_string(const Type& type)
......
......@@ -152,6 +152,12 @@ MessageListModel::end() const
return interactions_.end();
}
reverseIterator
MessageListModel::rend()
{
return interactions_.rend();
}
constIterator
MessageListModel::cend() const
{
......
......@@ -96,6 +96,8 @@ public:
interaction::Info& operator[](const QString& messageId);
iterator end();
constIterator end() const;
reverseIterator rend();
constIterator cend() const;
iterator begin();
constIterator begin() const;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment