Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
L
linphone-desktop
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
linphone-desktop
Commits
7ae543dd
Commit
7ae543dd
authored
Aug 09, 2017
by
Ronan Abhamon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(ui/scripts/LinphoneUtils): `getContactUsername` supports now display name and `sips:` pattern
parent
7d22bbce
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
62 additions
and
2 deletions
+62
-2
linphone-utils.js
ui/scripts/LinphoneUtils/linphone-utils.js
+62
-2
No files found.
ui/scripts/LinphoneUtils/linphone-utils.js
View file @
7ae543dd
...
...
@@ -8,19 +8,79 @@
// =============================================================================
function
_getDisplayNameFromQuotedString
(
str
)
{
var
start
=
str
.
indexOf
(
'
"
'
)
if
(
start
===
-
1
)
{
return
}
var
end
=
str
.
lastIndexOf
(
'
"
'
)
if
(
end
===
-
1
||
start
===
end
)
{
return
}
return
str
.
substring
(
start
+
1
,
end
)
}
function
_getDisplayNameFromString
(
str
)
{
var
end
=
str
.
indexOf
(
'
<
'
)
if
(
end
===
-
1
)
{
return
}
return
str
.
substring
(
0
,
end
).
trim
()
}
function
_getDisplayName
(
str
)
{
var
name
=
_getDisplayNameFromQuotedString
(
str
)
if
(
name
!=
null
)
{
return
name
}
return
_getDisplayNameFromString
(
str
)
}
// -----------------------------------------------------------------------------
function
_getUsername
(
str
)
{
var
start
=
str
.
indexOf
(
'
sip
'
)
if
(
start
===
-
1
)
{
return
}
start
+=
4
+
Number
(
str
.
charAt
(
start
+
4
)
===
'
:
'
)
// Deal with `sip:` and `sips:`
var
end
=
str
.
indexOf
(
'
@
'
,
start
+
1
)
if
(
end
===
-
1
)
{
return
}
return
str
.
substring
(
start
,
end
)
}
// -----------------------------------------------------------------------------
// Returns the username of a contact/sipAddressObserver object or URI string.
function
getContactUsername
(
contact
)
{
var
object
=
contact
.
contact
||
// Contact object from `SipAddressObserver`.
(
contact
.
vcard
&&
contact
)
// Contact object.
// 1. `object` is a contact.
if
(
object
)
{
return
object
.
vcard
.
username
}
// 2. `object` is just a string.
object
=
Utils
.
isString
(
contact
.
sipAddress
)
?
contact
.
sipAddress
// String from `SipAddressObserver`.
:
contact
// Just a String.
var
index
=
object
.
indexOf
(
'
@
'
)
return
object
.
substring
(
4
,
index
!==
-
1
?
index
:
undefined
)
// 4 = length('sip:')
// Use display name.
var
name
=
_getDisplayName
(
object
)
if
(
name
!=
null
)
{
return
name
}
// Use username.
name
=
_getUsername
(
object
)
return
name
==
null
?
'
Bad EGG
'
:
name
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment