Upgrade data synchronization on chat room managment

Fix synchro between smartsearchbar and participant list
Fix showing avatar on first message burst
Fix SDK missusing on addresses
Fix Popup Menu location
This commit is contained in:
Julien Wadel 2021-08-17 16:18:06 +02:00
parent 3436589f21
commit 13e677b4b2
13 changed files with 66 additions and 50 deletions

View file

@ -347,10 +347,7 @@ void ChatRoomModel::removeEntry(ChatEvent* entry){
//--------------------------------------------------------------------------------------------
QString ChatRoomModel::getPeerAddress () const {
if(haveEncryption() || isGroupEnabled()){
return getParticipants()->addressesToString();
}else
return mChatRoom ? Utils::coreStringToAppString(mChatRoom->getPeerAddress()->asStringUriOnly()) : "";
return mChatRoom ? Utils::coreStringToAppString(mChatRoom->getPeerAddress()->asStringUriOnly()) : "";
}
QString ChatRoomModel::getLocalAddress () const {
@ -367,10 +364,7 @@ QString ChatRoomModel::getLocalAddress () const {
}
QString ChatRoomModel::getFullPeerAddress () const {
if(haveEncryption() || isGroupEnabled()){
return getParticipants()->addressesToString();
}else
return mChatRoom ? Utils::coreStringToAppString(mChatRoom->getPeerAddress()->asString()) : "";
return mChatRoom ? Utils::coreStringToAppString(mChatRoom->getPeerAddress()->asString()) : "";
}
QString ChatRoomModel::getFullLocalAddress () const {
@ -674,7 +668,7 @@ public:
QList<EntrySorterHelper>::iterator itEntries = entries.begin();
int spotted = 0;
auto lastEntry = itEntries;
while(itEntries != entries.end() && (spotted != 7 || (entries.end()-itEntries > minEntries)) ) {
while(itEntries != entries.end() && (spotted != 7 && (entries.end()-itEntries > minEntries)) ) {
if( itEntries->mType == ChatRoomModel::EntryType::MessageEntry) {
if( (spotted & 1) == 0) {
lastEntry = itEntries;

View file

@ -218,6 +218,7 @@ void ParticipantListModel::updateParticipants () {
changed = true;
}else if(!(*itParticipant)->getParticipant()){
(*itParticipant)->setParticipant(dbParticipant);
changed = true;
}
}
if( changed){
@ -229,10 +230,12 @@ void ParticipantListModel::updateParticipants () {
void ParticipantListModel::add (std::shared_ptr<ParticipantModel> participant){
int row = mParticipants.count();
connect(this, &ParticipantListModel::deviceSecurityLevelChanged, participant.get(), &ParticipantModel::onDeviceSecurityLevelChanged);
connect(this, &ParticipantListModel::securityLevelChanged, participant.get(), &ParticipantModel::onSecurityLevelChanged);
connect(participant.get(),&ParticipantModel::updateAdminStatus, this, &ParticipantListModel::setAdminStatus);
beginInsertRows(QModelIndex(), row, row);
mParticipants << participant;
endInsertRows();
resetInternalData();
emit participantsChanged();
emit countChanged();
}

View file

@ -35,6 +35,9 @@ public:
Q_PROPERTY(ChatRoomModel* chatRoomModel READ getChatRoomModel CONSTANT)
Q_PROPERTY(int count READ getCount NOTIFY countChanged)
Q_PROPERTY(QString addressesToString READ addressesToString NOTIFY participantsChanged)
Q_PROPERTY(QString displayNamesToString READ displayNamesToString NOTIFY participantsChanged)
Q_PROPERTY(QString usernamesToString READ usernamesToString NOTIFY participantsChanged)
void reset();
void update();

View file

@ -49,7 +49,7 @@ QStringList ParticipantProxyModel::getSipAddresses() const{
QStringList participants;
ParticipantListModel * list = dynamic_cast<ParticipantListModel*>(sourceModel());
for(int i = 0 ; i < list->rowCount() ; ++i)
participants << list->getAt(i)->getSipAddress();
participants << list->getAt(i)->getSipAddress();
return participants;
}
@ -57,7 +57,7 @@ QVariantList ParticipantProxyModel::getParticipants() const{
QVariantList participants;
ParticipantListModel * list = dynamic_cast<ParticipantListModel*>(sourceModel());
for(int i = 0 ; i < list->rowCount() ; ++i)
participants << QVariant::fromValue(list->getAt(i));
participants << QVariant::fromValue(list->getAt(i));
return participants;
}
@ -70,9 +70,12 @@ int ParticipantProxyModel::getCount() const{
void ParticipantProxyModel::setChatRoomModel(ChatRoomModel * chatRoomModel){
if(!mChatRoomModel || mChatRoomModel != chatRoomModel){
mChatRoomModel = chatRoomModel;
if(mChatRoomModel)
setSourceModel(mChatRoomModel->getParticipants());
else {
if(mChatRoomModel) {
auto participants = mChatRoomModel->getParticipants();
setSourceModel(participants);
for(int i = 0 ; i < participants->getCount() ; ++i)
emit addressAdded(participants->getAt(i)->getSipAddress());
}else {
setSourceModel(new ParticipantListModel(nullptr, this));
}
sort(0);
@ -83,12 +86,13 @@ void ParticipantProxyModel::setChatRoomModel(ChatRoomModel * chatRoomModel){
void ParticipantProxyModel::add(const QString& address){
ParticipantListModel * participantsModel = dynamic_cast<ParticipantListModel*>(sourceModel());
if(!participantsModel->contains(address)){
std::shared_ptr<ParticipantModel> participant = std::make_shared<ParticipantModel>(nullptr);
std::shared_ptr<ParticipantModel> participant = std::make_shared<ParticipantModel>(nullptr);
participant->setSipAddress(address);
participantsModel->add(participant);
if(mChatRoomModel && mChatRoomModel->getChatRoom())// Invite and wait for its creation
mChatRoomModel->getChatRoom()->addParticipant(Utils::interpretUrl(address));
emit countChanged();
emit addressAdded(address);
}
}
@ -101,19 +105,20 @@ void ParticipantProxyModel::remove(ParticipantModel * participant){
mChatRoomModel->getChatRoom()->removeParticipant(participant->getParticipant());
//dynamic_cast<ParticipantListModel*>(sourceModel())->remove(participant);
emit countChanged();
emit addressRemoved(participant->getSipAddress());
}
}
// -----------------------------------------------------------------------------
bool ParticipantProxyModel::filterAcceptsRow (int sourceRow, const QModelIndex &sourceParent) const {
//const QModelIndex index = sourceModel()->index(sourceRow, 0, sourceParent);
return true;
//const QModelIndex index = sourceModel()->index(sourceRow, 0, sourceParent);
return true;
}
bool ParticipantProxyModel::lessThan (const QModelIndex &left, const QModelIndex &right) const {
const ParticipantModel* a = sourceModel()->data(left).value<ParticipantModel*>();
const ParticipantModel* b = sourceModel()->data(right).value<ParticipantModel*>();
return a->getCreationTime() >= b->getCreationTime();
const ParticipantModel* a = sourceModel()->data(left).value<ParticipantModel*>();
const ParticipantModel* b = sourceModel()->data(right).value<ParticipantModel*>();
return a->getCreationTime() >= b->getCreationTime();
}

View file

@ -60,6 +60,8 @@ public:
signals:
void chatRoomModelChanged();
void countChanged();
void addressAdded(QString sipAddress);
void addressRemoved(QString sipAddress);
private:
/*

View file

@ -1,5 +1,5 @@
import QtQuick 2.7
import QtQuick.Controls 2.2 as Controls
import QtQuick.Controls 2.3 as Controls
import Common 1.0
import Common.Styles 1.0

View file

@ -177,10 +177,11 @@ Rectangle {
font.pointSize: ChatStyle.entry.time.pointSize
visible: isMessage
&& $chatEntry != undefined
&& !$chatEntry.isOutgoing
&& (!previousItem
|| previousItem.fromSipAddress != $chatEntry.fromSipAddress
|| (new Date(previousItem.timestamp)).setHours(0, 0, 0, 0) != (new Date($chatEntry.timestamp)).setHours(0, 0, 0, 0)
&& !$chatEntry.isOutgoing // Only outgoing
&& (!previousItem //No previous entry
|| previousItem.type != ChatRoomModel.MessageEntry // Previous entry is a message
|| previousItem.fromSipAddress != $chatEntry.fromSipAddress // Different user
|| (new Date(previousItem.timestamp)).setHours(0, 0, 0, 0) != (new Date($chatEntry.timestamp)).setHours(0, 0, 0, 0) // Same day == section
)
}
RowLayout {

View file

@ -32,18 +32,13 @@ RowLayout {
if (index <= 0) {
return true // 1. First message, so visible.
}
var previousEntry = proxyModel.data(proxyModel.index(index - 1, 0))
if (!previousEntry) {
return true
}
// 2. Previous entry is a call event. => Visible.
// 3. I have sent a message before my contact. => Visible.
// 4. One hour between two incoming messages. => Visible.
return previousEntry.type !== ChatRoomModel.MessageEntry ||
previousEntry.isOutgoing ||
$chatEntry.timestamp.getTime() - previousEntry.timestamp.getTime() > 3600
var previousEntry = proxyModel.getAt(index - 1)
return !$chatEntry.isOutgoing && (// Only outgoing
!previousEntry //No previous entry
|| previousEntry.type != ChatRoomModel.MessageEntry // Previous entry is a message
|| previousEntry.fromSipAddress != $chatEntry.fromSipAddress // Different user
|| (new Date(previousEntry.timestamp)).setHours(0, 0, 0, 0) != (new Date($chatEntry.timestamp)).setHours(0, 0, 0, 0) // Same day == section
)
}
TooltipArea{
delay:0

View file

@ -109,9 +109,10 @@ Rectangle {
? (entry.groupEnabled != undefined && entry.groupEnabled
? ''
: (entry.haveEncryption != undefined && entry.haveEncryption
? entry.participants.addressesToString()
? ''
: entry.sipAddress || entry.fullPeerAddress || entry.peerAddress || ''))
: '')
participants: entry && showContactAddress && entry.groupEnabled != undefined && !entry.groupEnabled && entry.haveEncryption != undefined && entry.haveEncryption ? entry.participants.addressesToString : ''
/*
sipAddress: (entry && showContactAddress?

View file

@ -10,6 +10,8 @@ Column {
id:mainItem
property alias username: username.text
property string sipAddress
property string participants
property alias statusText : status.text
property var contactDescriptionStyle : ContactDescriptionStyle
@ -67,7 +69,7 @@ Column {
Text {
id:address
anchors.horizontalCenter: (horizontalTextAlignment == Text.AlignHCenter ? parent.horizontalCenter : undefined)
text: SipAddressesModel.cleanSipAddress(sipAddress)
text: sipAddress?SipAddressesModel.cleanSipAddress(sipAddress):participants
color: sipAddressColor
elide: Text.ElideRight
font.weight: contactDescriptionStyle.sipAddress.weight

View file

@ -132,12 +132,21 @@ ColumnLayout {
contactDescriptionStyle: ConversationStyle.bar.contactDescription
username: avatar.username
usernameClickable: chatRoomModel.isMeAdmin
participants: if(chatRoomModel) {
if(chatRoomModel.groupEnabled) {
return chatRoomModel.participants.displayNamesToString;
}else if(chatRoomModel.isSecure()) {
return chatRoomModel.participants.addressesToString;
}else
return ''
}else
return ''
sipAddress: {
if(chatRoomModel) {
if(chatRoomModel.groupEnabled) {
return chatRoomModel.participants.displayNamesToString();
return '';
}else if(chatRoomModel.isSecure()) {
return chatRoomModel.participants.addressesToString();
return '';
}else {
return chatRoomModel.sipAddress;
}

View file

@ -88,13 +88,11 @@ DialogPlus {
secure:0,
handler: function (entry) {
selectedParticipants.add(entry.sipAddress)
smartSearchBar.addAddressToIgnore(entry.sipAddress);
},
}]
onEntryClicked: {
selectedParticipants.add(entry)
smartSearchBar.addAddressToIgnore(entry);
}
}
@ -153,7 +151,6 @@ DialogPlus {
icon: 'remove_participant',
tooltipText: 'Remove this participant from the selection',
handler: function (entry) {
smartSearchBar.removeAddressToIgnore(entry.sipAddress)
selectedParticipants.remove(entry)
// ++lastContacts.reloadCount
}
@ -165,6 +162,8 @@ DialogPlus {
model: ParticipantProxyModel {
id:selectedParticipants
chatRoomModel:dialog.chatRoomModel
onAddressAdded: smartSearchBar.addAddressToIgnore(sipAddress)
onAddressRemoved: smartSearchBar.removeAddressToIgnore(sipAddress)
}

View file

@ -1,14 +1,16 @@
import QtQuick 2.7
import QtQuick.Controls 2.3
import Qt.labs.platform 1.0
//import QtQuick.Controls 2.3
//import Qt.labs.platform 1.0
import Linphone 1.0
import Common 1.0
import Utils 1.0
// =============================================================================
Item {
id:menuParent
function open () {
menu.open()
menu.popup()
}
// ---------------------------------------------------------------------------