feat(LinphoneUtils): getContactUsername is now magic, it supports sipAddressObserver

This commit is contained in:
Wescoeur 2017-06-26 21:10:09 +02:00
parent b74f36a770
commit 0c0b8c4f1a
10 changed files with 20 additions and 16 deletions

View file

@ -41,7 +41,7 @@ function getIsComposingMessage () {
var sipAddressObserver = chat.sipAddressObserver
return qsTr('isComposing').replace(
'%1',
LinphoneUtils.getContactUsername(sipAddressObserver.contact || sipAddressObserver.sipAddress)
LinphoneUtils.getContactUsername(sipAddressObserver)
)
}

View file

@ -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)
}
}

View file

@ -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.

View file

@ -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
}

View file

@ -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
}

View file

@ -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 {

View file

@ -38,7 +38,7 @@ Rectangle {
horizontalTextAlignment: Text.AlignHCenter
sipAddress: _sipAddressObserver.sipAddress
username: LinphoneUtils.getContactUsername(_sipAddressObserver.contact || sipAddress)
username: LinphoneUtils.getContactUsername(_sipAddressObserver)
}
Text {

View file

@ -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

View file

@ -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

View file

@ -29,10 +29,7 @@ function getEditIcon () {
}
function getUsername () {
return LinphoneUtils.getContactUsername(
conversation._sipAddressObserver.contact ||
conversation.sipAddress
)
return LinphoneUtils.getContactUsername(conversation._sipAddressObserver)
}
function updateChatFilter (button) {