1
0
Fork 0
mirror of https://git.jami.net/savoirfairelinux/jami-client-qt.git synced 2025-07-19 15:05:40 +02:00

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
This commit is contained in:
Nicolas Vengeon 2023-02-03 15:54:28 -05:00 committed by Sébastien Blin
parent 977092171e
commit b2643f5967
7 changed files with 51 additions and 12 deletions

View file

@ -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 {

View file

@ -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)
}
}

View file

@ -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
{

View file

@ -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);

View file

@ -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)

View file

@ -152,6 +152,12 @@ MessageListModel::end() const
return interactions_.end();
}
reverseIterator
MessageListModel::rend()
{
return interactions_.rend();
}
constIterator
MessageListModel::cend() const
{

View file

@ -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;