Timeline management

This commit is contained in:
Julien Wadel 2021-04-30 11:52:33 +02:00
parent c74654204a
commit 40bae25564
12 changed files with 125 additions and 22 deletions

View file

@ -248,14 +248,14 @@ void ChatProxyModel::resetMessageCount(){
}
}
std::shared_ptr<ChatModel> ChatProxyModel::getChatRoom () const{
std::shared_ptr<ChatModel> ChatProxyModel::getChatModel () const{
return mChatModel;
}
void ChatProxyModel::setChatRoom (std::shared_ptr<ChatModel> chatModel){
void ChatProxyModel::setChatModel (std::shared_ptr<ChatModel> chatModel){
mChatRoom = chatModel->getChatRoom();
reload();
emit chatRoomChanged();
emit chatModelChanged();
}
// -----------------------------------------------------------------------------

View file

@ -39,7 +39,7 @@ class ChatProxyModel : public QSortFilterProxyModel {
Q_PROPERTY(QString fullPeerAddress READ getFullPeerAddress WRITE setFullPeerAddress NOTIFY fullPeerAddressChanged);
Q_PROPERTY(QString fullLocalAddress READ getFullLocalAddress WRITE setFullLocalAddress NOTIFY fullLocalAddressChanged);
Q_PROPERTY(int isSecure READ getIsSecure WRITE setIsSecure NOTIFY isSecureChanged);
Q_PROPERTY(std::shared_ptr<ChatModel> chatRoom READ getChatRoom WRITE setChatRoom NOTIFY chatRoomChanged);
Q_PROPERTY(std::shared_ptr<ChatModel> chatModel READ getChatModel WRITE setChatModel NOTIFY chatModelChanged);
//Q_PROPERTY(bool isSecure MEMBER mIsSecure NOTIFY isSecureChanged);
Q_PROPERTY(bool isRemoteComposing READ getIsRemoteComposing NOTIFY isRemoteComposingChanged);
//Q_PROPERTY(bool isSecure READ getIsSecure NOTIFY isSecureChanged);
@ -75,7 +75,7 @@ signals:
bool isRemoteComposingChanged (bool status);
bool isSecureChanged(bool secure);
void chatRoomChanged();
void chatModelChanged();
void moreEntriesLoaded (int n);
@ -100,8 +100,8 @@ private:
int getIsSecure () const;
void setIsSecure (const int &secure);
std::shared_ptr<ChatModel> getChatRoom () const;
void setChatRoom (std::shared_ptr<ChatModel> chatRoom);
std::shared_ptr<ChatModel> getChatModel() const;
void setChatModel (std::shared_ptr<ChatModel> chatModel);
bool getIsRemoteComposing () const;

View file

@ -36,10 +36,18 @@ TimelineListModel::TimelineListModel (QObject *parent) : QAbstractListModel(pare
}
// -----------------------------------------------------------------------------
TimelineModel * TimelineListModel::getAt(const int& index){
return mTimelines[index];
}
void TimelineListModel::reset(){
initTimeline();
}
void TimelineListModel::update(){
}
int TimelineListModel::rowCount (const QModelIndex &) const {
return mTimelines.count();
}
@ -126,6 +134,36 @@ void TimelineListModel::initTimeline () {
}
*/
}
TimelineModel * TimelineListModel::getTimeline(std::shared_ptr<linphone::ChatRoom> chatRoom, const bool &create){
if(chatRoom){
for(auto it = mTimelines.begin() ; it != mTimelines.end() ; ++it){
if( (*it)->getChatModel()->getChatRoom() == chatRoom){
return *it;
}
}
if(create)
return new TimelineModel(chatRoom);
}
return nullptr;
}
void TimelineListModel::updateTimelines () {
CoreManager *coreManager = CoreManager::getInstance();
auto currentAddress = coreManager->getAccountSettingsModel()->getUsedSipAddress();
std::list<std::shared_ptr<linphone::ChatRoom>> allChatRooms = coreManager->getCore()->getChatRooms();
QList<TimelineModel*> models;
for(auto itAllChatRooms = allChatRooms.begin() ; itAllChatRooms != allChatRooms.end() ; ++itAllChatRooms){
if((*itAllChatRooms)->getMe()->getAddress()->weakEqual(currentAddress)){
models << getTimeline(*itAllChatRooms, true);
//models << new TimelineModel(*itAllChatRooms);
}
}
//beginInsertRows(QModelIndex(), 0, models.count()-1);
mTimelines = models;
}
/*
// Create a new TimelineModel and put it in the list
void TimelineListModel::add(){

View file

@ -22,6 +22,7 @@
#define TIMELINE_LIST_MODEL_H_
#include <QSortFilterProxyModel>
#include "components/chat/ChatModel.hpp"
class TimelineModel;
// =============================================================================
@ -33,6 +34,9 @@ public:
TimelineListModel (QObject *parent = Q_NULLPTR);
void reset();
void update();
TimelineModel * getAt(const int& index);
TimelineModel * getTimeline(std::shared_ptr<linphone::ChatRoom> chatRoom, const bool &create);
int rowCount (const QModelIndex &index = QModelIndex()) const override;
@ -46,7 +50,10 @@ private:
bool removeRow (int row, const QModelIndex &parent = QModelIndex());
bool removeRows (int row, int count, const QModelIndex &parent = QModelIndex()) override;
void initTimeline ();
void updateTimelines();
QList<TimelineModel*> mTimelines;
};

View file

@ -65,6 +65,6 @@ int TimelineModel::getPresenceStatus() const{
return 0;
}
std::shared_ptr<ChatModel> TimelineModel::getChatRoom() const{
std::shared_ptr<ChatModel> TimelineModel::getChatModel() const{
return mChatModel;
}

View file

@ -40,7 +40,7 @@ public:
Q_PROPERTY(QString fullPeerAddress READ getFullPeerAddress NOTIFY fullPeerAddressChanged)
Q_PROPERTY(QString fullLocalAddress READ getFullLocalAddress NOTIFY fullLocalAddressChanged)
Q_PROPERTY(std::shared_ptr<ChatModel> chatRoom READ getChatRoom CONSTANT)
Q_PROPERTY(std::shared_ptr<ChatModel> chatModel READ getChatModel CONSTANT)
// Contact
Q_PROPERTY(QString sipAddress READ getFullPeerAddress NOTIFY fullPeerAddressChanged)
@ -57,7 +57,7 @@ public:
int getPresenceStatus() const;
std::shared_ptr<ChatModel> getChatRoom() const;
Q_INVOKABLE std::shared_ptr<ChatModel> getChatModel() const;
QDateTime mTimestamp;
std::shared_ptr<ChatModel> mChatModel;

View file

@ -35,10 +35,41 @@
// -----------------------------------------------------------------------------
TimelineProxyModel::TimelineProxyModel (QObject *parent) : QSortFilterProxyModel(parent) {
setSourceModel(CoreManager::getInstance()->getTimelineListModel());
CoreManager *coreManager = CoreManager::getInstance();
AccountSettingsModel *accountSettingsModel = coreManager->getAccountSettingsModel();
setSourceModel(CoreManager::getInstance()->getTimelineListModel());
QObject::connect(accountSettingsModel, &AccountSettingsModel::accountSettingsUpdated, this, [this]() {
dynamic_cast<TimelineListModel*>(sourceModel())->update();
invalidate();
updateCurrentSelection();
});
QObject::connect(coreManager->getSipAddressesModel(), &SipAddressesModel::sipAddressReset, this, [this]() {
dynamic_cast<TimelineListModel*>(sourceModel())->reset();
invalidate();// Invalidate and reload GUI if the model has been reset
updateCurrentSelection();
});
sort(0);
}
// -----------------------------------------------------------------------------
void TimelineProxyModel::setCurrentChatModel(std::shared_ptr<ChatModel> data){
mCurrentChatModel = data;
emit currentChatModelChanged(mCurrentChatModel);
emit currentTimelineChanged(dynamic_cast<TimelineListModel*>(sourceModel())->getTimeline(mCurrentChatModel->getChatRoom(), false));
}
std::shared_ptr<ChatModel> TimelineProxyModel::getCurrentChatModel()const{
return mCurrentChatModel;
}
void TimelineProxyModel::updateCurrentSelection(){
auto currentAddress = CoreManager::getInstance()->getAccountSettingsModel()->getUsedSipAddress();
if(mCurrentChatModel && !mCurrentChatModel->getChatRoom()->getMe()->getAddress()->weakEqual(currentAddress) ){
setCurrentChatModel(nullptr);
}
}
// -----------------------------------------------------------------------------
bool TimelineProxyModel::filterAcceptsRow (int sourceRow, const QModelIndex &sourceParent) const {

View file

@ -24,12 +24,28 @@
#include <QSortFilterProxyModel>
// =============================================================================
#include "../chat/ChatModel.hpp"
class TimelineModel;
class TimelineProxyModel : public QSortFilterProxyModel {
Q_OBJECT;
Q_OBJECT
public:
TimelineProxyModel (QObject *parent = Q_NULLPTR);
Q_PROPERTY(std::shared_ptr<ChatModel> currentChatModel WRITE setCurrentChatModel READ getCurrentChatModel NOTIFY currentChatModelChanged)
void updateCurrentSelection();
Q_INVOKABLE void setCurrentChatModel(std::shared_ptr<ChatModel> data);
std::shared_ptr<ChatModel> getCurrentChatModel() const;
signals:
void currentChatModelChanged(std::shared_ptr<ChatModel> currentChatModel);
void currentTimelineChanged(TimelineModel * currentTimeline);
protected:
@ -39,6 +55,9 @@ protected:
QString getLocalAddress () const;
QString getCleanedLocalAddress () const;
void handleLocalAddressChanged (const QString &localAddress);
std::shared_ptr<ChatModel> mCurrentChatModel;
};

View file

@ -23,7 +23,7 @@ Rectangle {
signal entrySelected (TimelineModel entry)
// ---------------------------------------------------------------------------
/*
function setSelectedEntry (peerAddress, localAddress) {
Logic.setSelectedEntry(peerAddress, localAddress)
}
@ -31,7 +31,7 @@ Rectangle {
function resetSelectedEntry () {
Logic.resetSelectedEntry()
}
*/
// ---------------------------------------------------------------------------
color: TimelineStyle.color
@ -41,14 +41,20 @@ Rectangle {
spacing: 0
// -------------------------------------------------------------------------
Connections {
target: model
onCurrentTimelineChanged:entrySelected(currentTimeline)
}
/*
Connections {
target: model
onDataChanged: Logic.handleDataChanged(topLeft, bottomRight, roles)
onRowsAboutToBeRemoved: Logic.handleRowsAboutToBeRemoved(parent, first, last)
}
*/
// -------------------------------------------------------------------------
// Legend.
// -------------------------------------------------------------------------
@ -144,13 +150,15 @@ Rectangle {
anchors.fill: parent
onClicked: {
view.currentIndex = index
timeline.entrySelected(modelData)
//timeline.model.setCurrentChatModel(modelData.getChatModel())// using member doesn't work
timeline.model.currentChatModel = modelData.chatModel
//timeline.entrySelected(modelData)
//timeline.entrySelected($timelineEntry.sipAddress, $timelineEntry.isSecure)
}
}
}
onCountChanged: Logic.handleCountChanged(count)
// onCountChanged: Logic.handleCountChanged(count)
}
}
}

View file

@ -18,7 +18,7 @@ ColumnLayout {
property string fullPeerAddress
property string fullLocalAddress
property int isSecure
property var chatRoom
property var chatModel
readonly property var _sipAddressObserver: SipAddressesModel.getSipAddressObserver((fullPeerAddress?fullPeerAddress:peerAddress), (fullLocalAddress?fullLocalAddress:localAddress))
@ -173,7 +173,7 @@ ColumnLayout {
resetMessageCount()
}
isSecure: conversation.isSecure
chatRoom: conversation.chatRoom
chatModel: conversation.chatModel
peerAddress: conversation.peerAddress
fullPeerAddress: conversation.fullPeerAddress
fullLocalAddress: conversation.fullLocalAddress

View file

@ -117,12 +117,12 @@ function updateSelectedEntry (view, props) {
timeline.resetSelectedEntry()
} else {
menu.resetSelectedEntry()
/*
if (view === 'Conversation') {
timeline.setSelectedEntry(props.peerAddress, props.localAddress)
} else if (view === 'ContactEdit') {
timeline.resetSelectedEntry()
}
}*/
}
}

View file

@ -270,7 +270,7 @@ ApplicationWindow {
fullPeerAddress: entry.fullPeerAddress,
fullLocalAddress: AccountSettingsModel.fullSipAddress,
localAddress: AccountSettingsModel.sipAddress,
chatRoom:entry.chatRoom
chatModel:entry.chatModel
}):
setView('HistoryView', {})