From 0c0b8c4f1a0cc014dd1bbc5ea37bb7726ad4683d Mon Sep 17 00:00:00 2001 From: Wescoeur Date: Mon, 26 Jun 2017 21:10:09 +0200 Subject: [PATCH] feat(LinphoneUtils): `getContactUsername` is now magic, it supports sipAddressObserver --- ui/modules/Linphone/Chat/Chat.js | 2 +- ui/modules/Linphone/Chat/FileMessage.qml | 2 +- ui/modules/Linphone/Chat/IncomingMessage.qml | 2 +- ui/scripts/LinphoneUtils/linphone-utils.js | 15 +++++++++++---- ui/views/App/Calls/AbstractStartingCall.qml | 2 +- ui/views/App/Calls/Conference.qml | 2 +- ui/views/App/Calls/EndedCall.qml | 2 +- ui/views/App/Calls/Incall.qml | 2 +- ui/views/App/Calls/IncallAvatar.qml | 2 +- ui/views/App/Main/Conversation.js | 5 +---- 10 files changed, 20 insertions(+), 16 deletions(-) diff --git a/ui/modules/Linphone/Chat/Chat.js b/ui/modules/Linphone/Chat/Chat.js index 23194335d..97a8585d2 100644 --- a/ui/modules/Linphone/Chat/Chat.js +++ b/ui/modules/Linphone/Chat/Chat.js @@ -41,7 +41,7 @@ function getIsComposingMessage () { var sipAddressObserver = chat.sipAddressObserver return qsTr('isComposing').replace( '%1', - LinphoneUtils.getContactUsername(sipAddressObserver.contact || sipAddressObserver.sipAddress) + LinphoneUtils.getContactUsername(sipAddressObserver) ) } diff --git a/ui/modules/Linphone/Chat/FileMessage.qml b/ui/modules/Linphone/Chat/FileMessage.qml index bb742a84e..043fd6245 100644 --- a/ui/modules/Linphone/Chat/FileMessage.qml +++ b/ui/modules/Linphone/Chat/FileMessage.qml @@ -27,7 +27,7 @@ Row { width: ChatStyle.entry.message.incoming.avatarSize image: chat.sipAddressObserver.contact ? chat.sipAddressObserver.contact.avatar : '' - username: LinphoneUtils.getContactUsername(chat.sipAddressObserver.contact || proxyModel.sipAddress) + username: LinphoneUtils.getContactUsername(chat.sipAddressObserver) } } diff --git a/ui/modules/Linphone/Chat/IncomingMessage.qml b/ui/modules/Linphone/Chat/IncomingMessage.qml index 21f2141bb..38df2f19e 100644 --- a/ui/modules/Linphone/Chat/IncomingMessage.qml +++ b/ui/modules/Linphone/Chat/IncomingMessage.qml @@ -21,7 +21,7 @@ RowLayout { anchors.centerIn: parent height: ChatStyle.entry.message.incoming.avatarSize image: chat.sipAddressObserver.contact ? chat.sipAddressObserver.contact.vcard.avatar : '' - username: LinphoneUtils.getContactUsername(chat.sipAddressObserver.contact || proxyModel.sipAddress) + username: LinphoneUtils.getContactUsername(chat.sipAddressObserver) width: ChatStyle.entry.message.incoming.avatarSize // The avatar is only visible for the first message of a incoming messages sequence. diff --git a/ui/scripts/LinphoneUtils/linphone-utils.js b/ui/scripts/LinphoneUtils/linphone-utils.js index 732f6d404..9b68cd83f 100644 --- a/ui/scripts/LinphoneUtils/linphone-utils.js +++ b/ui/scripts/LinphoneUtils/linphone-utils.js @@ -8,9 +8,16 @@ // ============================================================================= -// Returns the username of a contact object or URI string. +// Returns the username of a contact/sipAddressObserver object or URI string. function getContactUsername (contact) { - return Utils.isString(contact) - ? contact.substring(4, contact.indexOf('@')) // 4 = length('sip:') - : contact.vcard.username + var object = contact.contact || // Contact object from `SipAddressObserver`. + (contact.vcard && contact) || // Contact object. + (contact.sipAddress) || // String from `SipAddressObserver`. + contact // String. + + if (Utils.isString(object)) { + return object.substring(4, object.indexOf('@')) // 4 = length('sip:') + } + + return object.vcard.username } diff --git a/ui/views/App/Calls/AbstractStartingCall.qml b/ui/views/App/Calls/AbstractStartingCall.qml index 6e3318677..668ba690b 100644 --- a/ui/views/App/Calls/AbstractStartingCall.qml +++ b/ui/views/App/Calls/AbstractStartingCall.qml @@ -41,7 +41,7 @@ Rectangle { height: CallStyle.header.contactDescription.height horizontalTextAlignment: Text.AlignHCenter sipAddress: call.sipAddress - username: LinphoneUtils.getContactUsername(_sipAddressObserver.contact || call.sipAddress) + username: LinphoneUtils.getContactUsername(_sipAddressObserver) width: parent.width } diff --git a/ui/views/App/Calls/Conference.qml b/ui/views/App/Calls/Conference.qml index 8a0d9e9f3..5d3e380c2 100644 --- a/ui/views/App/Calls/Conference.qml +++ b/ui/views/App/Calls/Conference.qml @@ -132,7 +132,7 @@ Rectangle { horizontalTextAlignment: Text.AlignHCenter sipAddress: parent.sipAddressObserver.sipAddress - username: LinphoneUtils.getContactUsername(parent.sipAddressObserver.contact || parent.sipAddress) + username: LinphoneUtils.getContactUsername(parent.sipAddressObserver) } IncallAvatar { diff --git a/ui/views/App/Calls/EndedCall.qml b/ui/views/App/Calls/EndedCall.qml index 7861a8865..f31720a0c 100644 --- a/ui/views/App/Calls/EndedCall.qml +++ b/ui/views/App/Calls/EndedCall.qml @@ -38,7 +38,7 @@ Rectangle { horizontalTextAlignment: Text.AlignHCenter sipAddress: _sipAddressObserver.sipAddress - username: LinphoneUtils.getContactUsername(_sipAddressObserver.contact || sipAddress) + username: LinphoneUtils.getContactUsername(_sipAddressObserver) } Text { diff --git a/ui/views/App/Calls/Incall.qml b/ui/views/App/Calls/Incall.qml index 55fab1842..f509ea5ef 100644 --- a/ui/views/App/Calls/Incall.qml +++ b/ui/views/App/Calls/Incall.qml @@ -144,7 +144,7 @@ Rectangle { anchors.centerIn: parent horizontalTextAlignment: Text.AlignHCenter sipAddress: '' - username: LinphoneUtils.getContactUsername(_sipAddressObserver.contact || _sipAddressObserver.sipAddress) + username: LinphoneUtils.getContactUsername(_sipAddressObserver) height: parent.height width: parent.width - rightActions.width - leftActions.width - CallStyle.header.contactDescription.width diff --git a/ui/views/App/Calls/IncallAvatar.qml b/ui/views/App/Calls/IncallAvatar.qml index 404f6c1ae..a6ca4319c 100644 --- a/ui/views/App/Calls/IncallAvatar.qml +++ b/ui/views/App/Calls/IncallAvatar.qml @@ -11,7 +11,7 @@ Avatar { property var call readonly property var _sipAddressObserver: SipAddressesModel.getSipAddressObserver(call.sipAddress) - readonly property var _username: LinphoneUtils.getContactUsername(_sipAddressObserver.contact || call.sipAddress) + readonly property var _username: LinphoneUtils.getContactUsername(_sipAddressObserver) backgroundColor: CallStyle.container.avatar.backgroundColor foregroundColor: call.status === CallModel.CallStatusPaused diff --git a/ui/views/App/Main/Conversation.js b/ui/views/App/Main/Conversation.js index 9991db350..870ded9bd 100644 --- a/ui/views/App/Main/Conversation.js +++ b/ui/views/App/Main/Conversation.js @@ -29,10 +29,7 @@ function getEditIcon () { } function getUsername () { - return LinphoneUtils.getContactUsername( - conversation._sipAddressObserver.contact || - conversation.sipAddress - ) + return LinphoneUtils.getContactUsername(conversation._sipAddressObserver) } function updateChatFilter (button) {