mirror of
https://gitlab.linphone.org/BC/public/linphone-desktop.git
synced 2026-01-29 01:39:19 +00:00
Use Linphone optimization on Chat room events loading by using range histories
This commit is contained in:
parent
adffd91b14
commit
ed13cc174b
3 changed files with 306 additions and 178 deletions
|
|
@ -637,33 +637,108 @@ void ChatRoomModel::resetMessageCount () {
|
|||
emit messageCountReset();
|
||||
}
|
||||
}
|
||||
//-------------------------------------------------
|
||||
// Entries Loading managment
|
||||
//-------------------------------------------------
|
||||
// For each type of events, a part of entries are loaded with a minimal count (=mLastEntriesStep). Like that, we have from 0 to 3*mLastEntriesStep events.
|
||||
// We store them in a list that will be sorted from oldest to newest.
|
||||
// From the oldest, we loop till having at least one type of event or if we hit the minimum limit.
|
||||
// As it was a request for each events, we ensure to get all available events after it.
|
||||
// Notations : M0 is the first Message event; N0, the first EventLog; C0, the first Call event. After '|', there are mLastEntriesStep events.
|
||||
// Available cases examples :
|
||||
// 'M0...N0....|...C0....' => '|...C0....'
|
||||
// 'M0C0N0|...' == 'C0N0|...' == '|N0....C0....' == '|N0....C0....' == '|.......' We suppose that we got all available events for the current scope.
|
||||
// 'N0...M0....C0...|...' => '|C0...'
|
||||
//
|
||||
// -------------------
|
||||
//
|
||||
// When requesting more entries, we count the number of events we got. Each numbers represent the index from what we can retrieve next events from linphone database.
|
||||
// Like that, we avoid to load all database. A bad point is about loading call events : There are no range to retrieve and we don't want to load the entire database. So for this case, this is not fully optimized (optimization is only about GUI and connections)
|
||||
//
|
||||
// Request more entries are coming from GUI. Like that, we don't have to manage if events are filtered or not (only messages, call, events).
|
||||
|
||||
void ChatRoomModel::initEntries(){
|
||||
if(!mIsInitialized){
|
||||
QList<std::shared_ptr<ChatEvent> > entries;
|
||||
// Get chat messages
|
||||
for (auto &message : mChatRoom->getHistory(mLastEntriesCount))
|
||||
entries << ChatMessageModel::create(message, this);
|
||||
// Get events
|
||||
for(auto &eventLog : mChatRoom->getHistoryEvents(mLastEntriesCount)){
|
||||
auto entry = ChatNoticeModel::create(eventLog, this);
|
||||
if(entry)
|
||||
entries << entry;
|
||||
}
|
||||
// Get calls.
|
||||
if(!isSecure() )
|
||||
for (auto &callLog : CoreManager::getInstance()->getCore()->getCallHistory(mChatRoom->getPeerAddress(), mChatRoom->getLocalAddress())){
|
||||
auto entry = ChatCallModel::create(callLog, true, this);
|
||||
if(entry) {
|
||||
entries << entry;
|
||||
if (callLog->getStatus() == linphone::Call::Status::Success) {
|
||||
entry = ChatCallModel::create(callLog, false, this);
|
||||
if(entry)
|
||||
entries << entry;
|
||||
}
|
||||
class EntrySorterHelper{
|
||||
public:
|
||||
EntrySorterHelper(time_t pTime, ChatRoomModel::EntryType pType,std::shared_ptr<linphone::Object> obj) : mTime(pTime), mType(pType), mObject(obj) {}
|
||||
time_t mTime;
|
||||
ChatRoomModel::EntryType mType;
|
||||
std::shared_ptr<linphone::Object> mObject;
|
||||
|
||||
static void getLimitedSelection(QList<std::shared_ptr<ChatEvent> > *resultEntries, QList<EntrySorterHelper>& entries, const int& minEntries, ChatRoomModel * chatRoomModel) {// Sort and return a selection with at least 'minEntries'
|
||||
// Sort list
|
||||
std::sort(entries.begin(), entries.end(), [](const EntrySorterHelper& a, const EntrySorterHelper& b) {
|
||||
return a.mTime < b.mTime;
|
||||
});
|
||||
// Keep max( minEntries, last(messages, events, calls) )
|
||||
QList<EntrySorterHelper>::iterator itEntries = entries.begin();
|
||||
int spotted = 0;
|
||||
auto lastEntry = itEntries;
|
||||
while(itEntries != entries.end() && (spotted != 7 || (entries.end()-itEntries > minEntries)) ) {
|
||||
if( itEntries->mType == ChatRoomModel::EntryType::MessageEntry) {
|
||||
if( (spotted & 1) == 0) {
|
||||
lastEntry = itEntries;
|
||||
spotted |= 1;
|
||||
}
|
||||
}else if( itEntries->mType == ChatRoomModel::EntryType::CallEntry){
|
||||
if( (spotted & 2) == 0){
|
||||
lastEntry = itEntries;
|
||||
spotted |= 2;
|
||||
}
|
||||
}else {
|
||||
if( (spotted & 4) == 0){
|
||||
lastEntry = itEntries;
|
||||
spotted |= 4;
|
||||
}
|
||||
}
|
||||
mIsInitialized = true;
|
||||
++itEntries;
|
||||
}
|
||||
itEntries = lastEntry;
|
||||
if(itEntries - entries.begin() < 3)
|
||||
itEntries = entries.begin();
|
||||
for(; itEntries != entries.end() ; ++itEntries){
|
||||
if( (*itEntries).mType== ChatRoomModel::EntryType::MessageEntry)
|
||||
*resultEntries << ChatMessageModel::create(std::dynamic_pointer_cast<linphone::ChatMessage>(itEntries->mObject), chatRoomModel);
|
||||
else if( (*itEntries).mType == ChatRoomModel::EntryType::CallEntry) {
|
||||
auto entry = ChatCallModel::create(std::dynamic_pointer_cast<linphone::CallLog>(itEntries->mObject), true, chatRoomModel);
|
||||
if(entry) {
|
||||
*resultEntries << entry;
|
||||
if (entry->mStatus == LinphoneEnums::CallStatusSuccess) {
|
||||
entry = ChatCallModel::create(entry->getCallLog(), false, chatRoomModel);
|
||||
if(entry)
|
||||
*resultEntries << entry;
|
||||
}
|
||||
}
|
||||
}else{
|
||||
auto entry = ChatNoticeModel::create(std::dynamic_pointer_cast<linphone::EventLog>(itEntries->mObject), chatRoomModel);
|
||||
if(entry)
|
||||
*resultEntries << entry;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
void ChatRoomModel::initEntries(){
|
||||
// On call : reinitialize all entries. This allow to free up memory
|
||||
QList<std::shared_ptr<ChatEvent> > entries;
|
||||
QList<EntrySorterHelper> prepareEntries;
|
||||
// Get chat messages
|
||||
for (auto &message : mChatRoom->getHistory(mLastEntriesStep))
|
||||
prepareEntries << EntrySorterHelper(message->getTime() ,MessageEntry, message);
|
||||
// Get events
|
||||
for(auto &eventLog : mChatRoom->getHistoryEvents(mLastEntriesStep))
|
||||
prepareEntries << EntrySorterHelper(eventLog->getCreationTime() , NoticeEntry, eventLog);
|
||||
// Get calls.
|
||||
if(!isSecure() ) {
|
||||
auto callHistory = CoreManager::getInstance()->getCore()->getCallHistory(mChatRoom->getPeerAddress(), mChatRoom->getLocalAddress());
|
||||
// callhistory is sorted from newest to oldest
|
||||
int count = 0;
|
||||
for (auto callLog = callHistory.begin() ; count < mLastEntriesStep && callLog != callHistory.end() ; ++callLog, ++count ){
|
||||
prepareEntries << EntrySorterHelper((*callLog)->getStartDate(), CallEntry, *callLog);
|
||||
}
|
||||
}
|
||||
EntrySorterHelper::getLimitedSelection(&entries, prepareEntries, mLastEntriesStep, this);
|
||||
|
||||
mIsInitialized = true;
|
||||
if(entries.size() >0){
|
||||
beginInsertRows(QModelIndex(), 0, entries.size()-1);
|
||||
mEntries = entries;
|
||||
endInsertRows();
|
||||
|
|
@ -671,10 +746,23 @@ void ChatRoomModel::initEntries(){
|
|||
}
|
||||
|
||||
void ChatRoomModel::loadMoreEntries(){
|
||||
mLastEntriesCount += mLastEntriesStep;
|
||||
QList<std::shared_ptr<ChatEvent> > entries;
|
||||
QList<EntrySorterHelper> prepareEntries;
|
||||
// Get current event count for each type
|
||||
QVector<int> entriesCounts;
|
||||
entriesCounts.resize(3);
|
||||
for(auto itEntries = mEntries.begin() ; itEntries != mEntries.end() ; ++itEntries){
|
||||
if( (*itEntries)->mType == MessageEntry)
|
||||
++entriesCounts[0];
|
||||
else if( (*itEntries)->mType == CallEntry){
|
||||
if(dynamic_cast<ChatCallModel*>((*itEntries).get())->mIsStart)
|
||||
++entriesCounts[1];
|
||||
} else
|
||||
++entriesCounts[2];
|
||||
}
|
||||
|
||||
// Messages
|
||||
QList<std::shared_ptr<linphone::ChatMessage>> messagesToAdd;
|
||||
for (auto &message : mChatRoom->getHistory(mLastEntriesCount)){
|
||||
for (auto &message : mChatRoom->getHistoryRange(entriesCounts[0], entriesCounts[0]+mLastEntriesStep)){
|
||||
auto itEntries = mEntries.begin();
|
||||
bool haveEntry = false;
|
||||
while(!haveEntry && itEntries != mEntries.end()){
|
||||
|
|
@ -683,12 +771,26 @@ void ChatRoomModel::loadMoreEntries(){
|
|||
++itEntries;
|
||||
}
|
||||
if(!haveEntry)
|
||||
messagesToAdd << message;
|
||||
prepareEntries << EntrySorterHelper(message->getTime() ,MessageEntry, message);
|
||||
}
|
||||
|
||||
// Calls
|
||||
if(!isSecure() ) {
|
||||
auto callHistory = CoreManager::getInstance()->getCore()->getCallHistory(mChatRoom->getPeerAddress(), mChatRoom->getLocalAddress());
|
||||
int count = 0;
|
||||
auto itCallHistory = callHistory.begin();
|
||||
while(count < entriesCounts[1] && itCallHistory != callHistory.end()){
|
||||
++itCallHistory;
|
||||
++count;
|
||||
}
|
||||
count = 0;
|
||||
while( count < mLastEntriesStep && itCallHistory != callHistory.end()){
|
||||
prepareEntries << EntrySorterHelper((*itCallHistory)->getStartDate(), CallEntry, *itCallHistory);
|
||||
++itCallHistory;
|
||||
}
|
||||
}
|
||||
|
||||
// Notices
|
||||
QList<std::shared_ptr<linphone::EventLog>> noticesToAdd;
|
||||
for (auto &eventLog : mChatRoom->getHistoryEvents(mLastEntriesCount)){
|
||||
for (auto &eventLog : mChatRoom->getHistoryRangeEvents(entriesCounts[2], entriesCounts[2]+mLastEntriesStep)){
|
||||
auto itEntries = mEntries.begin();
|
||||
bool haveEntry = false;
|
||||
while(!haveEntry && itEntries != mEntries.end()){
|
||||
|
|
@ -697,25 +799,27 @@ void ChatRoomModel::loadMoreEntries(){
|
|||
++itEntries;
|
||||
}
|
||||
if(!haveEntry)
|
||||
noticesToAdd << eventLog;
|
||||
prepareEntries << EntrySorterHelper(eventLog->getCreationTime() , NoticeEntry, eventLog);
|
||||
}
|
||||
EntrySorterHelper::getLimitedSelection(&entries, prepareEntries, mLastEntriesStep, this);
|
||||
if(entries.size() >0){
|
||||
beginInsertRows(QModelIndex(), 0, entries.size()-1);
|
||||
for(auto entry : entries)
|
||||
mEntries.prepend(entry);
|
||||
endInsertRows();
|
||||
}
|
||||
if(messagesToAdd.size() > 0)
|
||||
insertMessages(messagesToAdd);
|
||||
if(noticesToAdd.size() > 0)
|
||||
insertNotices(noticesToAdd);
|
||||
if( messagesToAdd.size() == 0 && noticesToAdd.size() == 0)
|
||||
mLastEntriesCount = mEntries.size(); // We reset last antries count to current events size to avoid overflow count
|
||||
}
|
||||
|
||||
//-------------------------------------------------
|
||||
//-------------------------------------------------
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
void ChatRoomModel::insertCall (const shared_ptr<linphone::CallLog> &callLog) {
|
||||
void ChatRoomModel::insertCall (const std::shared_ptr<linphone::CallLog> &callLog) {
|
||||
if(mIsInitialized){
|
||||
std::shared_ptr<ChatCallModel> model = ChatCallModel::create(callLog, true, this);
|
||||
if(model){
|
||||
int row = mEntries.count();
|
||||
|
||||
beginInsertRows(QModelIndex(), row, row);
|
||||
mEntries << model;
|
||||
endInsertRows();
|
||||
|
|
@ -732,7 +836,31 @@ void ChatRoomModel::insertCall (const shared_ptr<linphone::CallLog> &callLog) {
|
|||
}
|
||||
}
|
||||
|
||||
void ChatRoomModel::insertMessageAtEnd (const shared_ptr<linphone::ChatMessage> &message) {
|
||||
void ChatRoomModel::insertCalls (const QList<std::shared_ptr<linphone::CallLog> > &calls) {
|
||||
if(mIsInitialized){
|
||||
QList<std::shared_ptr<ChatEvent> > entries;
|
||||
for(auto callLog : calls) {
|
||||
std::shared_ptr<ChatCallModel> model = ChatCallModel::create(callLog, true, this);
|
||||
if(model){
|
||||
entries << model;
|
||||
if (callLog->getStatus() == linphone::Call::Status::Success) {
|
||||
model = ChatCallModel::create(callLog, false, this);
|
||||
if(model){
|
||||
entries << model;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if(entries.size() > 0){
|
||||
beginInsertRows(QModelIndex(), 0, entries.size()-1);
|
||||
entries << mEntries;
|
||||
mEntries = entries;
|
||||
endInsertRows();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ChatRoomModel::insertMessageAtEnd (const std::shared_ptr<linphone::ChatMessage> &message) {
|
||||
if(mIsInitialized){
|
||||
std::shared_ptr<ChatMessageModel> model = ChatMessageModel::create(message, this);
|
||||
if(model){
|
||||
|
|
@ -745,7 +873,7 @@ void ChatRoomModel::insertMessageAtEnd (const shared_ptr<linphone::ChatMessage>
|
|||
}
|
||||
}
|
||||
|
||||
void ChatRoomModel::insertMessages (const QList<shared_ptr<linphone::ChatMessage> > &messages) {
|
||||
void ChatRoomModel::insertMessages (const QList<std::shared_ptr<linphone::ChatMessage> > &messages) {
|
||||
if(mIsInitialized){
|
||||
QList<std::shared_ptr<ChatEvent> > entries;
|
||||
for(auto message : messages) {
|
||||
|
|
@ -795,7 +923,7 @@ void ChatRoomModel::insertNotices (const QList<std::shared_ptr<linphone::EventLo
|
|||
}
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
void ChatRoomModel::handleCallStateChanged (const shared_ptr<linphone::Call> &call, linphone::Call::State state) {
|
||||
void ChatRoomModel::handleCallStateChanged (const std::shared_ptr<linphone::Call> &call, linphone::Call::State state) {
|
||||
if (state == linphone::Call::State::End || state == linphone::Call::State::Error){
|
||||
shared_ptr<linphone::Core> core = CoreManager::getInstance()->getCore();
|
||||
std::shared_ptr<linphone::ChatRoomParams> params = core->createDefaultChatRoomParams();
|
||||
|
|
|
|||
|
|
@ -220,8 +220,7 @@ public:
|
|||
bool mIsInitialized = false;
|
||||
|
||||
bool mDeleteChatRoom = false; // Use as workaround because of core->deleteChatRoom() that call destructor without takking account of count ref : call it in ChatRoomModel destructor
|
||||
int mLastEntriesCount = 50; // Retrieve a part of the history to avoid too much processing
|
||||
int mLastEntriesStep = 50; // Message loading Step
|
||||
int mLastEntriesStep = 50; // Retrieve a part of the history to avoid too much processing
|
||||
|
||||
|
||||
//-------------------- CHAT ROOM HANDLER
|
||||
|
|
@ -304,6 +303,7 @@ signals:
|
|||
|
||||
private:
|
||||
void insertCall (const std::shared_ptr<linphone::CallLog> &callLog);
|
||||
void insertCalls (const QList<std::shared_ptr<linphone::CallLog> > &calls);
|
||||
void insertMessageAtEnd (const std::shared_ptr<linphone::ChatMessage> &message);
|
||||
void insertMessages (const QList<std::shared_ptr<linphone::ChatMessage> > &messages);
|
||||
void insertNotice (const std::shared_ptr<linphone::EventLog> &enventLog);
|
||||
|
|
|
|||
|
|
@ -39,83 +39,83 @@ QString ChatRoomProxyModel::gCachedText;
|
|||
// Fetch the L last filtered chat entries.
|
||||
class ChatRoomProxyModel::ChatRoomModelFilter : public QSortFilterProxyModel {
|
||||
public:
|
||||
ChatRoomModelFilter (QObject *parent) : QSortFilterProxyModel(parent) {}
|
||||
|
||||
int getEntryTypeFilter () {
|
||||
return mEntryTypeFilter;
|
||||
}
|
||||
|
||||
void setEntryTypeFilter (int type) {
|
||||
mEntryTypeFilter = type;
|
||||
invalidate();
|
||||
}
|
||||
|
||||
ChatRoomModelFilter (QObject *parent) : QSortFilterProxyModel(parent) {}
|
||||
|
||||
int getEntryTypeFilter () {
|
||||
return mEntryTypeFilter;
|
||||
}
|
||||
|
||||
void setEntryTypeFilter (int type) {
|
||||
mEntryTypeFilter = type;
|
||||
invalidate();
|
||||
}
|
||||
|
||||
protected:
|
||||
bool filterAcceptsRow (int sourceRow, const QModelIndex &) const override {
|
||||
if (mEntryTypeFilter == ChatRoomModel::EntryType::GenericEntry)
|
||||
return true;
|
||||
|
||||
QModelIndex index = sourceModel()->index(sourceRow, 0, QModelIndex());
|
||||
const QVariantMap data = index.data().toMap();
|
||||
|
||||
auto eventModel = sourceModel()->data(index);
|
||||
|
||||
if( mEntryTypeFilter == ChatRoomModel::EntryType::CallEntry && eventModel.value<ChatCallModel*>() != nullptr)
|
||||
return true;
|
||||
if( mEntryTypeFilter == ChatRoomModel::EntryType::MessageEntry && eventModel.value<ChatMessageModel*>() != nullptr)
|
||||
return true;
|
||||
if( mEntryTypeFilter == ChatRoomModel::EntryType::NoticeEntry && eventModel.value<ChatNoticeModel*>() != nullptr)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool filterAcceptsRow (int sourceRow, const QModelIndex &) const override {
|
||||
if (mEntryTypeFilter == ChatRoomModel::EntryType::GenericEntry)
|
||||
return true;
|
||||
|
||||
QModelIndex index = sourceModel()->index(sourceRow, 0, QModelIndex());
|
||||
const QVariantMap data = index.data().toMap();
|
||||
|
||||
auto eventModel = sourceModel()->data(index);
|
||||
|
||||
if( mEntryTypeFilter == ChatRoomModel::EntryType::CallEntry && eventModel.value<ChatCallModel*>() != nullptr)
|
||||
return true;
|
||||
if( mEntryTypeFilter == ChatRoomModel::EntryType::MessageEntry && eventModel.value<ChatMessageModel*>() != nullptr)
|
||||
return true;
|
||||
if( mEntryTypeFilter == ChatRoomModel::EntryType::NoticeEntry && eventModel.value<ChatNoticeModel*>() != nullptr)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
private:
|
||||
int mEntryTypeFilter = ChatRoomModel::EntryType::GenericEntry;
|
||||
int mEntryTypeFilter = ChatRoomModel::EntryType::GenericEntry;
|
||||
};
|
||||
|
||||
// =============================================================================
|
||||
|
||||
ChatRoomProxyModel::ChatRoomProxyModel (QObject *parent) : QSortFilterProxyModel(parent) {
|
||||
setSourceModel(new ChatRoomModelFilter(this));
|
||||
//mIsSecure = false;
|
||||
|
||||
App *app = App::getInstance();
|
||||
QObject::connect(app->getMainWindow(), &QWindow::activeChanged, this, [this]() {
|
||||
handleIsActiveChanged(App::getInstance()->getMainWindow());
|
||||
});
|
||||
|
||||
QQuickWindow *callsWindow = app->getCallsWindow();
|
||||
if (callsWindow)
|
||||
QObject::connect(callsWindow, &QWindow::activeChanged, this, [this, callsWindow]() {
|
||||
handleIsActiveChanged(callsWindow);
|
||||
});
|
||||
sort(0);
|
||||
setSourceModel(new ChatRoomModelFilter(this));
|
||||
//mIsSecure = false;
|
||||
|
||||
App *app = App::getInstance();
|
||||
QObject::connect(app->getMainWindow(), &QWindow::activeChanged, this, [this]() {
|
||||
handleIsActiveChanged(App::getInstance()->getMainWindow());
|
||||
});
|
||||
|
||||
QQuickWindow *callsWindow = app->getCallsWindow();
|
||||
if (callsWindow)
|
||||
QObject::connect(callsWindow, &QWindow::activeChanged, this, [this, callsWindow]() {
|
||||
handleIsActiveChanged(callsWindow);
|
||||
});
|
||||
sort(0);
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
#define GET_CHAT_MODEL() \
|
||||
if (!mChatRoomModel) \
|
||||
return; \
|
||||
mChatRoomModel
|
||||
if (!mChatRoomModel) \
|
||||
return; \
|
||||
mChatRoomModel
|
||||
|
||||
#define CREATE_PARENT_MODEL_FUNCTION(METHOD) \
|
||||
void ChatRoomProxyModel::METHOD () { \
|
||||
GET_CHAT_MODEL()->METHOD(); \
|
||||
}
|
||||
void ChatRoomProxyModel::METHOD () { \
|
||||
GET_CHAT_MODEL()->METHOD(); \
|
||||
}
|
||||
|
||||
#define CREATE_PARENT_MODEL_FUNCTION_WITH_PARAM(METHOD, ARG_TYPE) \
|
||||
void ChatRoomProxyModel::METHOD (ARG_TYPE value) { \
|
||||
GET_CHAT_MODEL()->METHOD(value); \
|
||||
}
|
||||
void ChatRoomProxyModel::METHOD (ARG_TYPE value) { \
|
||||
GET_CHAT_MODEL()->METHOD(value); \
|
||||
}
|
||||
|
||||
#define CREATE_PARENT_MODEL_FUNCTION_WITH_ID(METHOD) \
|
||||
void ChatRoomProxyModel::METHOD (int id) { \
|
||||
QModelIndex sourceIndex = mapToSource(index(id, 0)); \
|
||||
GET_CHAT_MODEL()->METHOD( \
|
||||
static_cast<ChatRoomModelFilter *>(sourceModel())->mapToSource(sourceIndex).row() \
|
||||
); \
|
||||
}
|
||||
void ChatRoomProxyModel::METHOD (int id) { \
|
||||
QModelIndex sourceIndex = mapToSource(index(id, 0)); \
|
||||
GET_CHAT_MODEL()->METHOD( \
|
||||
static_cast<ChatRoomModelFilter *>(sourceModel())->mapToSource(sourceIndex).row() \
|
||||
); \
|
||||
}
|
||||
|
||||
CREATE_PARENT_MODEL_FUNCTION(removeAllEntries)
|
||||
|
||||
|
|
@ -132,40 +132,40 @@ CREATE_PARENT_MODEL_FUNCTION_WITH_ID(removeRow)
|
|||
|
||||
|
||||
void ChatRoomProxyModel::compose (const QString& text) {
|
||||
if (mChatRoomModel)
|
||||
mChatRoomModel->compose();
|
||||
gCachedText = text;
|
||||
if (mChatRoomModel)
|
||||
mChatRoomModel->compose();
|
||||
gCachedText = text;
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
void ChatRoomProxyModel::loadMoreEntries () {
|
||||
int count = rowCount();
|
||||
int parentCount = sourceModel()->rowCount();
|
||||
if (count == mMaxDisplayedEntries)
|
||||
mMaxDisplayedEntries += EntriesChunkSize;
|
||||
|
||||
if (count + 10 >= parentCount) // Magic number : try to load more entries if near to max event count
|
||||
int count = rowCount();
|
||||
int parentCount = sourceModel()->rowCount();
|
||||
if (count == mMaxDisplayedEntries)
|
||||
mMaxDisplayedEntries += EntriesChunkSize;
|
||||
|
||||
if (count + 10 >= parentCount) // Magic number : try to load more entries if near to max event count
|
||||
mChatRoomModel->loadMoreEntries();
|
||||
invalidateFilter();
|
||||
count = rowCount() - count;
|
||||
if (count > 0)
|
||||
emit moreEntriesLoaded(count);
|
||||
if (count > 0)
|
||||
emit moreEntriesLoaded(count);
|
||||
}
|
||||
|
||||
void ChatRoomProxyModel::setEntryTypeFilter (int type) {
|
||||
ChatRoomModelFilter *ChatRoomModelFilter = static_cast<ChatRoomProxyModel::ChatRoomModelFilter *>(sourceModel());
|
||||
|
||||
if (ChatRoomModelFilter->getEntryTypeFilter() != type) {
|
||||
ChatRoomModelFilter->setEntryTypeFilter(type);
|
||||
emit entryTypeFilterChanged(type);
|
||||
}
|
||||
ChatRoomModelFilter *ChatRoomModelFilter = static_cast<ChatRoomProxyModel::ChatRoomModelFilter *>(sourceModel());
|
||||
|
||||
if (ChatRoomModelFilter->getEntryTypeFilter() != type) {
|
||||
ChatRoomModelFilter->setEntryTypeFilter(type);
|
||||
emit entryTypeFilterChanged(type);
|
||||
}
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
bool ChatRoomProxyModel::filterAcceptsRow (int sourceRow, const QModelIndex &) const {
|
||||
return sourceModel()->rowCount() - sourceRow <= mMaxDisplayedEntries;
|
||||
return true;
|
||||
}
|
||||
bool ChatRoomProxyModel::lessThan (const QModelIndex &left, const QModelIndex &right) const {
|
||||
auto l = sourceModel()->data(left);
|
||||
|
|
@ -187,43 +187,43 @@ bool ChatRoomProxyModel::lessThan (const QModelIndex &left, const QModelIndex &r
|
|||
// -----------------------------------------------------------------------------
|
||||
|
||||
QString ChatRoomProxyModel::getPeerAddress () const {
|
||||
return mChatRoomModel ? mChatRoomModel->getPeerAddress() : mPeerAddress;//QString("");
|
||||
return mChatRoomModel ? mChatRoomModel->getPeerAddress() : mPeerAddress;//QString("");
|
||||
}
|
||||
|
||||
void ChatRoomProxyModel::setPeerAddress (const QString &peerAddress) {
|
||||
mPeerAddress = peerAddress;
|
||||
emit peerAddressChanged(mPeerAddress);
|
||||
//reload();
|
||||
mPeerAddress = peerAddress;
|
||||
emit peerAddressChanged(mPeerAddress);
|
||||
//reload();
|
||||
}
|
||||
|
||||
QString ChatRoomProxyModel::getLocalAddress () const {
|
||||
return mChatRoomModel ? mChatRoomModel->getLocalAddress() : mLocalAddress;//QString("");
|
||||
return mChatRoomModel ? mChatRoomModel->getLocalAddress() : mLocalAddress;//QString("");
|
||||
}
|
||||
|
||||
void ChatRoomProxyModel::setLocalAddress (const QString &localAddress) {
|
||||
mLocalAddress = localAddress;
|
||||
emit localAddressChanged(mLocalAddress);
|
||||
//reload();
|
||||
mLocalAddress = localAddress;
|
||||
emit localAddressChanged(mLocalAddress);
|
||||
//reload();
|
||||
}
|
||||
|
||||
QString ChatRoomProxyModel::getFullPeerAddress () const {
|
||||
return mChatRoomModel ? mChatRoomModel->getFullPeerAddress() : mFullPeerAddress;//QString("");
|
||||
return mChatRoomModel ? mChatRoomModel->getFullPeerAddress() : mFullPeerAddress;//QString("");
|
||||
}
|
||||
|
||||
void ChatRoomProxyModel::setFullPeerAddress (const QString &peerAddress) {
|
||||
mFullPeerAddress = peerAddress;
|
||||
emit fullPeerAddressChanged(mFullPeerAddress);
|
||||
//reload();
|
||||
mFullPeerAddress = peerAddress;
|
||||
emit fullPeerAddressChanged(mFullPeerAddress);
|
||||
//reload();
|
||||
}
|
||||
|
||||
QString ChatRoomProxyModel::getFullLocalAddress () const {
|
||||
return mChatRoomModel ? mChatRoomModel->getFullLocalAddress() : mFullLocalAddress;//QString("");
|
||||
return mChatRoomModel ? mChatRoomModel->getFullLocalAddress() : mFullLocalAddress;//QString("");
|
||||
}
|
||||
|
||||
void ChatRoomProxyModel::setFullLocalAddress (const QString &localAddress) {
|
||||
mFullLocalAddress = localAddress;
|
||||
emit fullLocalAddressChanged(mFullLocalAddress);
|
||||
//reload();
|
||||
mFullLocalAddress = localAddress;
|
||||
emit fullLocalAddressChanged(mFullLocalAddress);
|
||||
//reload();
|
||||
}
|
||||
/*
|
||||
bool ChatRoomProxyModel::isSecure () const {
|
||||
|
|
@ -250,34 +250,34 @@ QString ChatRoomProxyModel::getDisplayNameComposers()const{
|
|||
}
|
||||
|
||||
QString ChatRoomProxyModel::getCachedText() const{
|
||||
return gCachedText;
|
||||
return gCachedText;
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
void ChatRoomProxyModel::reload (ChatRoomModel *chatRoomModel) {
|
||||
mMaxDisplayedEntries = EntriesChunkSize;
|
||||
|
||||
if (mChatRoomModel) {
|
||||
ChatRoomModel *ChatRoomModel = mChatRoomModel.get();
|
||||
QObject::disconnect(ChatRoomModel, &ChatRoomModel::isRemoteComposingChanged, this, &ChatRoomProxyModel::handleIsRemoteComposingChanged);
|
||||
QObject::disconnect(ChatRoomModel, &ChatRoomModel::messageReceived, this, &ChatRoomProxyModel::handleMessageReceived);
|
||||
QObject::disconnect(ChatRoomModel, &ChatRoomModel::messageSent, this, &ChatRoomProxyModel::handleMessageSent);
|
||||
}
|
||||
|
||||
|
||||
mMaxDisplayedEntries = EntriesChunkSize;
|
||||
|
||||
if (mChatRoomModel) {
|
||||
ChatRoomModel *ChatRoomModel = mChatRoomModel.get();
|
||||
QObject::disconnect(ChatRoomModel, &ChatRoomModel::isRemoteComposingChanged, this, &ChatRoomProxyModel::handleIsRemoteComposingChanged);
|
||||
QObject::disconnect(ChatRoomModel, &ChatRoomModel::messageReceived, this, &ChatRoomProxyModel::handleMessageReceived);
|
||||
QObject::disconnect(ChatRoomModel, &ChatRoomModel::messageSent, this, &ChatRoomProxyModel::handleMessageSent);
|
||||
}
|
||||
|
||||
|
||||
mChatRoomModel = CoreManager::getInstance()->getTimelineListModel()->getChatRoomModel(chatRoomModel);
|
||||
|
||||
if (mChatRoomModel) {
|
||||
|
||||
ChatRoomModel *ChatRoomModel = mChatRoomModel.get();
|
||||
QObject::connect(ChatRoomModel, &ChatRoomModel::isRemoteComposingChanged, this, &ChatRoomProxyModel::handleIsRemoteComposingChanged);
|
||||
QObject::connect(ChatRoomModel, &ChatRoomModel::messageReceived, this, &ChatRoomProxyModel::handleMessageReceived);
|
||||
QObject::connect(ChatRoomModel, &ChatRoomModel::messageSent, this, &ChatRoomProxyModel::handleMessageSent);
|
||||
}
|
||||
|
||||
static_cast<ChatRoomModelFilter *>(sourceModel())->setSourceModel(mChatRoomModel.get());
|
||||
invalidate();
|
||||
|
||||
if (mChatRoomModel) {
|
||||
|
||||
ChatRoomModel *ChatRoomModel = mChatRoomModel.get();
|
||||
QObject::connect(ChatRoomModel, &ChatRoomModel::isRemoteComposingChanged, this, &ChatRoomProxyModel::handleIsRemoteComposingChanged);
|
||||
QObject::connect(ChatRoomModel, &ChatRoomModel::messageReceived, this, &ChatRoomProxyModel::handleMessageReceived);
|
||||
QObject::connect(ChatRoomModel, &ChatRoomModel::messageSent, this, &ChatRoomProxyModel::handleMessageSent);
|
||||
}
|
||||
|
||||
static_cast<ChatRoomModelFilter *>(sourceModel())->setSourceModel(mChatRoomModel.get());
|
||||
invalidate();
|
||||
}
|
||||
void ChatRoomProxyModel::resetMessageCount(){
|
||||
if( mChatRoomModel){
|
||||
|
|
@ -298,34 +298,34 @@ void ChatRoomProxyModel::setChatRoomModel (ChatRoomModel *chatRoomModel){
|
|||
// -----------------------------------------------------------------------------
|
||||
|
||||
static inline QWindow *getParentWindow (QObject *object) {
|
||||
App *app = App::getInstance();
|
||||
const QWindow *mainWindow = app->getMainWindow();
|
||||
const QWindow *callsWindow = app->getCallsWindow();
|
||||
for (QObject *parent = object->parent(); parent; parent = parent->parent())
|
||||
if (parent == mainWindow || parent == callsWindow)
|
||||
return static_cast<QWindow *>(parent);
|
||||
return nullptr;
|
||||
App *app = App::getInstance();
|
||||
const QWindow *mainWindow = app->getMainWindow();
|
||||
const QWindow *callsWindow = app->getCallsWindow();
|
||||
for (QObject *parent = object->parent(); parent; parent = parent->parent())
|
||||
if (parent == mainWindow || parent == callsWindow)
|
||||
return static_cast<QWindow *>(parent);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void ChatRoomProxyModel::handleIsActiveChanged (QWindow *window) {
|
||||
if (mChatRoomModel && window->isActive() && getParentWindow(this) == window) {
|
||||
mChatRoomModel->resetMessageCount();
|
||||
mChatRoomModel->focused();
|
||||
}
|
||||
if (mChatRoomModel && window->isActive() && getParentWindow(this) == window) {
|
||||
mChatRoomModel->resetMessageCount();
|
||||
mChatRoomModel->focused();
|
||||
}
|
||||
}
|
||||
|
||||
void ChatRoomProxyModel::handleIsRemoteComposingChanged () {
|
||||
emit isRemoteComposingChanged();
|
||||
emit isRemoteComposingChanged();
|
||||
}
|
||||
|
||||
void ChatRoomProxyModel::handleMessageReceived (const shared_ptr<linphone::ChatMessage> &) {
|
||||
mMaxDisplayedEntries++;
|
||||
|
||||
QWindow *window = getParentWindow(this);
|
||||
if (window && window->isActive())
|
||||
mChatRoomModel->resetMessageCount();
|
||||
mMaxDisplayedEntries++;
|
||||
|
||||
QWindow *window = getParentWindow(this);
|
||||
if (window && window->isActive())
|
||||
mChatRoomModel->resetMessageCount();
|
||||
}
|
||||
|
||||
void ChatRoomProxyModel::handleMessageSent (const shared_ptr<linphone::ChatMessage> &) {
|
||||
mMaxDisplayedEntries++;
|
||||
mMaxDisplayedEntries++;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue