Show displayname in chat room messages (group messages if same author in the same day)

Fix contact search for display name (clean address from gruu)
This commit is contained in:
Julien Wadel 2021-08-16 20:21:05 +02:00
parent 40d7ae4e92
commit c10d50f88f
5 changed files with 75 additions and 52 deletions

View file

@ -56,7 +56,6 @@ protected:
return true;
QModelIndex index = sourceModel()->index(sourceRow, 0, QModelIndex());
const QVariantMap data = index.data().toMap();
auto eventModel = sourceModel()->data(index);
@ -228,21 +227,6 @@ void ChatRoomProxyModel::setFullLocalAddress (const QString &localAddress) {
emit fullLocalAddressChanged(mFullLocalAddress);
//reload();
}
/*
bool ChatRoomProxyModel::isSecure () const {
return mChatRoomModel ? mChatRoomModel->isSecure() : false;
}
void ChatRoomProxyModel::setIsSecure (const int &secure) {
mIsSecure = secure;
emit isSecureChanged(mIsSecure);
}
*/
/*
bool ChatRoomProxyModel::getIsRemoteComposing () const {
return mChatRoomModel ? mChatRoomModel->getIsRemoteComposing() : false;
}*/
QList<QString> ChatRoomProxyModel::getComposers() const{
return (mChatRoomModel?mChatRoomModel->getComposers():QList<QString>());
@ -252,6 +236,11 @@ QString ChatRoomProxyModel::getDisplayNameComposers()const{
return getComposers().join(", ");
}
QVariant ChatRoomProxyModel::getAt(int row){
QModelIndex sourceIndex = mapToSource(this->index(row, 0));
return sourceModel()->data(sourceIndex);
}
QString ChatRoomProxyModel::getCachedText() const{
return gCachedText;
}

View file

@ -50,6 +50,7 @@ public:
ChatRoomProxyModel (QObject *parent = Q_NULLPTR);
Q_INVOKABLE QString getDisplayNameComposers()const;
Q_INVOKABLE QVariant getAt(int row);
Q_INVOKABLE void loadMoreEntries ();
Q_INVOKABLE void setEntryTypeFilter (int type);

View file

@ -463,7 +463,9 @@ void Utils::copyDir(QString from, QString to) {
QString Utils::getDisplayName(const std::shared_ptr<const linphone::Address>& address){
QString displayName;
if(address){
QString qtAddress = Utils::coreStringToAppString(address->asString());
std::shared_ptr<linphone::Address> cleanAddress = address->clone();
cleanAddress->clean();
QString qtAddress = Utils::coreStringToAppString(cleanAddress->asStringUriOnly());
ContactModel * model = CoreManager::getInstance()->getContactsListModel()->findContactModelFromSipAddress(qtAddress);
if(model && model->getVcardModel())
displayName = model->getVcardModel()->getUsername();

View file

@ -121,6 +121,8 @@ Rectangle {
delegate: Rectangle {
id: entry
property bool isNotice : $chatEntry.type === ChatRoomModel.NoticeEntry
property bool isCall : $chatEntry.type === ChatRoomModel.CallEntry
property bool isMessage : $chatEntry.type === ChatRoomModel.MessageEntry
function isHoverEntry () {
return mouseArea.containsMouse
@ -155,41 +157,67 @@ Rectangle {
implicitHeight: layout.height
width: parent.width + parent.anchors.rightMargin
acceptedButtons: Qt.NoButton
RowLayout {
id: layout
spacing: 0
width: entry.width
// Display time.
Text {
Layout.alignment: Qt.AlignTop
Layout.preferredHeight: ChatStyle.entry.lineHeight
Layout.preferredWidth: ChatStyle.entry.time.width
color: '#B1B1B1'
font.pointSize: ChatStyle.entry.time.pointSize
text: $chatEntry.timestamp.toLocaleString(
Qt.locale(App.locale),
'hh:mm'
)
verticalAlignment: Text.AlignVCenter
TooltipArea {
text: $chatEntry.timestamp.toLocaleString(Qt.locale(App.locale))
}
visible:!isNotice
}
// Display content.
Loader {
Layout.fillWidth: true
source: Logic.getComponentFromEntry($chatEntry)
}
}
ColumnLayout{
id: layout
spacing: 0
width: entry.width
Text{
id:authorName
Layout.leftMargin: timeDisplay.width + 10
Layout.fillWidth: true
text : $chatEntry.fromDisplayName ? $chatEntry.fromDisplayName : ''
property var previousItem : {
if(index >0)
return proxyModel.getAt(index-1)
else
return null
}
color: '#B1B1B1'
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)
)
}
RowLayout {
spacing: 0
width: entry.width
// Display time.
Text {
id:timeDisplay
Layout.alignment: Qt.AlignTop
Layout.preferredHeight: ChatStyle.entry.lineHeight
Layout.preferredWidth: ChatStyle.entry.time.width
color: '#B1B1B1'
font.pointSize: ChatStyle.entry.time.pointSize
text: $chatEntry.timestamp.toLocaleString(
Qt.locale(App.locale),
'hh:mm'
)
verticalAlignment: Text.AlignVCenter
TooltipArea {
text: $chatEntry.timestamp.toLocaleString(Qt.locale(App.locale))
}
visible:!isNotice
}
// Display content.
Loader {
Layout.fillWidth: true
source: Logic.getComponentFromEntry($chatEntry)
}
}
}
}
}

View file

@ -34,6 +34,7 @@ Item {
+ (ephemeralTimerRow.visible? message.padding * 4 : message.padding * 2)
+ (deliveryLayout.visible? deliveryLayout.height : 0)
Rectangle {
id: rectangle
@ -73,6 +74,8 @@ Item {
}
}
// ---------------------------------------------------------------------------
// Message.
// ---------------------------------------------------------------------------