Feature : Adding missing call count with the unread messages in timeline

Fix : Force refresh Registers when clicking on Account status, without testing registration state.
- add a timer synchronization to show the registration status by proxy
This commit is contained in:
Julien Wadel 2020-05-28 17:23:48 +02:00
parent 5a6c7b08f5
commit c41f337907
11 changed files with 51 additions and 29 deletions

View file

@ -628,7 +628,7 @@ void ChatModel::compose () {
}
void ChatModel::resetMessageCount () {
if (mChatRoom->getUnreadMessagesCount() > 0) {
if (mChatRoom->getUnreadMessagesCount() > 0 || CoreManager::getInstance()->getMissedCallCount(getPeerAddress(), getLocalAddress())>0) {
mChatRoom->markAsRead();
emit messageCountReset();
}

View file

@ -307,7 +307,9 @@ QString CoreManager::getVersion () const {
int CoreManager::getEventCount () const {
return mEventCountNotifier ? mEventCountNotifier->getEventCount() : 0;
}
int CoreManager::getMissedCallCount(const QString &peerAddress, const QString &localAddress)const{
return mEventCountNotifier ? mEventCountNotifier->getMissedCallCount(peerAddress, localAddress) : 0;
}
// -----------------------------------------------------------------------------
void CoreManager::iterate () {

View file

@ -130,6 +130,8 @@ public:
Q_INVOKABLE void sendLogs () const;
Q_INVOKABLE void cleanLogs () const;
int getMissedCallCount(const QString &peerAddress, const QString &localAddress) const;// Get missed call count from a chat (useful for showing bubbles on Timelines)
signals:
void coreCreated ();
void coreStarted ();

View file

@ -69,6 +69,14 @@ void AbstractEventCountNotifier::internalnotifyEventCount () {
emit eventCountChanged(n);
}
// Get missed call from a chat (useful for showing bubbles on Timelines)
int AbstractEventCountNotifier::getMissedCallCount(const QString &peerAddress, const QString &localAddress) const{
auto it = mMissedCalls.find({ peerAddress, localAddress });
if (it != mMissedCalls.cend())
return *it;
else
return 0;
}
// -----------------------------------------------------------------------------
void AbstractEventCountNotifier::handleChatModelCreated (const shared_ptr<ChatModel> &chatModel) {

View file

@ -52,6 +52,7 @@ public:
}
int getEventCount () const { return mUnreadMessageCount + getMissedCallCount(); }
int getMissedCallCount(const QString &peerAddress, const QString &localAddress) const;// Get missed call count from a chat (useful for showing bubbles on Timelines)
signals:
void eventCountChanged (int count);

View file

@ -128,7 +128,7 @@ SipAddressObserver *SipAddressesModel::getSipAddressObserver (const QString &pee
auto it2 = it->localAddressToConferenceEntry.find(cleanedLocalAddress);
if (it2 != it->localAddressToConferenceEntry.end())
model->setUnreadMessageCount(it2->unreadMessageCount);
model->setUnreadMessageCount(it2->unreadMessageCount+it2->missedCallCount);
}
mObservers.insert(cleanedPeerAddress, model);
@ -399,12 +399,13 @@ void SipAddressesModel::handleMessageCountReset (ChatModel *chatModel) {
return;
it2->unreadMessageCount = 0;
it2->missedCallCount = 0;
int row = mRefs.indexOf(&(*it));
Q_ASSERT(row != -1);
emit dataChanged(index(row, 0), index(row, 0));
updateObservers(peerAddress, localAddress, 0);
updateObservers(peerAddress, localAddress, 0, 0);
}
void SipAddressesModel::handleMessageSent (const shared_ptr<linphone::ChatMessage> &message) {
@ -447,19 +448,19 @@ void SipAddressesModel::addOrUpdateSipAddress (SipAddressEntry &sipAddressEntry,
void SipAddressesModel::addOrUpdateSipAddress (SipAddressEntry &sipAddressEntry, const shared_ptr<linphone::Call> &call) {
const shared_ptr<linphone::CallLog> callLog = call->getCallLog();
sipAddressEntry.localAddressToConferenceEntry[
Utils::coreStringToAppString(callLog->getLocalAddress()->asStringUriOnly())
].timestamp = callLog->getStatus() == linphone::Call::Status::Success
QString localAddress(Utils::coreStringToAppString(callLog->getLocalAddress()->asStringUriOnly()));
QString peerAddress(Utils::coreStringToAppString(callLog->getRemoteAddress()->asStringUriOnly()));
ConferenceEntry &conferenceEntry = sipAddressEntry.localAddressToConferenceEntry[
localAddress
];
qInfo() << QStringLiteral("Update (`%1`, `%2`) from chat call.").arg(sipAddressEntry.sipAddress, localAddress);
conferenceEntry.timestamp = callLog->getStatus() == linphone::Call::Status::Success
? QDateTime::fromMSecsSinceEpoch((callLog->getStartDate() + callLog->getDuration()) * 1000)
: QDateTime::fromMSecsSinceEpoch(callLog->getStartDate() * 1000);
if (callLog->getStatus() == linphone::Call::Status::Missed) {
for (auto &observer : mObservers.values(Utils::coreStringToAppString((callLog->getRemoteAddress()->asStringUriOnly())))) {
if (observer->getLocalAddress() == Utils::coreStringToAppString(callLog->getLocalAddress()->asStringUriOnly())) {
observer->setUnreadMessageCount(1);
}
}
}
conferenceEntry.missedCallCount = CoreManager::getInstance()->getMissedCallCount(peerAddress, localAddress);
updateObservers(sipAddressEntry.sipAddress, localAddress, conferenceEntry.unreadMessageCount,conferenceEntry.missedCallCount);
}
void SipAddressesModel::addOrUpdateSipAddress (SipAddressEntry &sipAddressEntry, const shared_ptr<linphone::ChatMessage> &message) {
@ -467,13 +468,14 @@ void SipAddressesModel::addOrUpdateSipAddress (SipAddressEntry &sipAddressEntry,
int count = chatRoom->getUnreadMessagesCount();
QString localAddress(Utils::coreStringToAppString(chatRoom->getLocalAddress()->asStringUriOnly()));
QString peerAddress(Utils::coreStringToAppString(chatRoom->getPeerAddress()->asStringUriOnly()));
qInfo() << QStringLiteral("Update (`%1`, `%2`) from chat message.").arg(sipAddressEntry.sipAddress, localAddress);
ConferenceEntry &conferenceEntry = sipAddressEntry.localAddressToConferenceEntry[localAddress];
conferenceEntry.timestamp = QDateTime::fromMSecsSinceEpoch(message->getTime() * 1000);
conferenceEntry.unreadMessageCount = count;
updateObservers(sipAddressEntry.sipAddress, localAddress, count);
conferenceEntry.unreadMessageCount = count ;
conferenceEntry.missedCallCount = CoreManager::getInstance()->getMissedCallCount(peerAddress, localAddress);
updateObservers(sipAddressEntry.sipAddress, localAddress, count,conferenceEntry.missedCallCount);
}
template<typename T>
@ -556,6 +558,7 @@ void SipAddressesModel::initSipAddressesFromChat () {
getSipAddressEntry(peerAddress)->localAddressToConferenceEntry[localAddress] = {
chatRoom->getUnreadMessagesCount(),
CoreManager::getInstance()->getMissedCallCount(peerAddress, localAddress),
false,
QDateTime::fromMSecsSinceEpoch(history.back()->getTime() * 1000)
};
@ -596,7 +599,7 @@ void SipAddressesModel::initSipAddressesFromCalls () {
auto &localToConferenceEntry = getSipAddressEntry(peerAddress)->localAddressToConferenceEntry;
auto it = localToConferenceEntry.find(localAddress);
if (it == localToConferenceEntry.end())
localToConferenceEntry[localAddress] = { 0, false, move(timestamp) };
localToConferenceEntry[localAddress] = { 0,0, false, move(timestamp) };
else if (it->timestamp.isNull() || timestamp > it->timestamp)
it->timestamp = move(timestamp);
}
@ -624,10 +627,10 @@ void SipAddressesModel::updateObservers (const QString &sipAddress, const Presen
observer->setPresenceStatus(presenceStatus);
}
void SipAddressesModel::updateObservers (const QString &peerAddress, const QString &localAddress, int messageCount) {
void SipAddressesModel::updateObservers (const QString &peerAddress, const QString &localAddress, int messageCount, int missedCallCount) {
for (auto &observer : mObservers.values(peerAddress)) {
if (observer->getLocalAddress() == localAddress) {
observer->setUnreadMessageCount(messageCount);
observer->setUnreadMessageCount(messageCount+missedCallCount);
return;
}
}

View file

@ -39,6 +39,7 @@ class SipAddressesModel : public QAbstractListModel {
public:
struct ConferenceEntry {
int unreadMessageCount;
int missedCallCount;
bool isComposing;
QDateTime timestamp;
};
@ -132,7 +133,7 @@ private:
void updateObservers (const QString &sipAddress, ContactModel *contact);
void updateObservers (const QString &sipAddress, const Presence::PresenceStatus &presenceStatus);
void updateObservers (const QString &peerAddress, const QString &localAddress, int messageCount);
void updateObservers (const QString &peerAddress, const QString &localAddress, int messageCount, int missedCallCount);
// ---------------------------------------------------------------------------

View file

@ -60,6 +60,7 @@ QVariant TimelineModel::data (const QModelIndex &index, int role) const {
map["timestamp"] = it->timestamp;
map["isComposing"] = it->isComposing;
map["unreadMessageCount"] = it->unreadMessageCount;
map["missedCallCount"] = it->missedCallCount;
}
return map;

View file

@ -64,7 +64,7 @@ Rectangle {
ContactMessageCounter {
Layout.alignment: Qt.AlignTop
count: Number(entry.unreadMessageCount)
count: Number(entry.unreadMessageCount) + Number(entry.missedCallCount)
isComposing: Boolean(entry.isComposing)
visible: item.displayUnreadMessageCount

View file

@ -75,19 +75,23 @@ DialogPlus {
delegate: CommonItemDelegate {
id: item
container: view
flattenedModel: modelData
itemIcon: Logic.getItemIcon(flattenedModel)
itemIcon: ''//Start with no error and let some time before getting status with the below timer
width: parent.width
ActionButton {
Timer{// This timer is used to synchronize registration state by proxy, without having to deal with change signals
interval: 1000; running: item.visible; repeat: true
onTriggered:itemIcon= Logic.getItemIcon(flattenedModel)
}
ActionButton {
icon: 'options'
iconSize: 30
anchors.fill: parent
visible:false
//TODO handle click and jump to proxy config settings
}
}
onClicked: {
container.currentIndex = index

View file

@ -112,8 +112,8 @@ ApplicationWindow {
text: AccountSettingsModel.sipAddress
}
onClicked: {if(AccountSettingsModel.registrationState !== AccountSettingsModel.RegistrationStateRegistered && AccountSettingsModel.registrationState !== AccountSettingsModel.RegistrationStateNoProxy)
CoreManager.forceRefreshRegisters()
onClicked: {
CoreManager.forceRefreshRegisters()
Logic.manageAccounts()
}
}