Skip to content

Commit b0340d7

Browse files
authored
Merge pull request #161 from cybex-dev/fix_name_parameter_resolution
Fix name resolution priority and parameters
2 parents 49dab9b + f040b55 commit b0340d7

File tree

3 files changed

+73
-52
lines changed

3 files changed

+73
-52
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
* Fix: [Android] Inconsistent caller/recipient names for inbound calls between ringing & connected states.
3939
* Fix: [Android] Incorrect call direction for incoming calls
4040
* Fix: call ringing event always showing `CallDirection.outgoing`
41+
* Fix: [Android] Updated CallKit incoming/outgoing name parameter resolution
4142

4243
## 0.0.9
4344
* Feat: forwarded callInvite custom parameters to flutter

README.md

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -332,12 +332,23 @@ Caller is usually referred to as `call.from` or `callInvite.from`. This can eith
332332

333333
The following rules are applied to determine the caller/recipient name, which is shown in the call screen and heads-up notification:
334334

335-
- If the caller is empty/not provided, the default caller name is shown e.g. "Unknown Caller", else
336-
- if the caller is a number, the plugin will show the number as is, else
337-
- if the caller is a string, the plugin will interpret the string as follows:
338-
- if the `__TWI_CALLER_NAME` parameter is provided, the plugin will show the value of `__TWI_CALLER_NAME` as is, else
339-
- if the `__TWI_CALLER_ID` parameter is provided, the plugin will search for a registered client with the same id and show the client name, else
340-
- if not found or not provided, the plugin will search for a registered client with the `call.from` value and show the client name, as a last resort
335+
##### Incoming Calls:
336+
337+
`__TWI_CALLER_NAME` -> `resolve(__TWI_CALLER_ID)` -> (phone number) -> `registered client (from)` -> `defaultCaller name` -> `"Unknown Caller"`
338+
339+
340+
##### Outgoing Calls:
341+
342+
`__TWI_RECIPIENT_NAME` -> `resolve(__TWI_RECIPIENT_ID)` -> (phone number) -> `registered client (to)` -> `defaultCaller name` -> `"Unknown Caller"`
343+
344+
**Details explaination:**
345+
346+
- if the call is an CallInvite (incoming), the plugin will interpret the string as follows or if the call is outgoing, the twilio `To` parameter field is used to:
347+
- if the `__TWI_CALLER_NAME` (or `__TWI_RECIPIENT_NAME`) parameter is provided, the plugin will show the value of `__TWI_CALLER_NAME` (or `__TWI_RECIPIENT_NAME`) as is, else
348+
- if the `__TWI_CALLER_ID` (or `__TWI_RECIPIENT_ID`) parameter is provided, the plugin will search for a registered client with the same id and show the client name,
349+
- if the caller (`from` or `to` fields) is empty/not provided, the default caller name is shown e.g. "Unknown Caller", else
350+
- else if the caller (`from` or `to` fields) is a number, the plugin will show the number as is, else
351+
- else the plugin will search for a registered client with the `callInvite.from` (or call.to) value and show the client name, as a last resort
341352
- the default caller name is shown e.g. "Unknown Caller"
342353

343354
*Please note: the same approach applies to both caller and recipient name resolution.*

android/src/main/kotlin/com/twilio/twilio_voice/call/TVParametersImpl.kt

Lines changed: 55 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -18,34 +18,39 @@ class TVCallInviteParametersImpl(storage: Storage, callInvite: CallInvite) : TVP
1818

1919
override val from: String
2020
get() {
21-
val mFrom = mCallInvite.from ?: ""
22-
if (mFrom.isEmpty()) {
23-
return mStorage.defaultCaller
24-
}
25-
26-
if (!mFrom.startsWith("client:")) {
27-
// we have a number, return as is
28-
return mFrom
29-
}
30-
31-
val mToName = mFrom.replace("client:", "")
32-
return customParameters[PARAM_RECIPIENT_NAME]
33-
?: customParameters[PARAM_RECIPIENT_ID]?.let { resolveHumanReadableName(it) }
34-
?: resolveHumanReadableName(mToName)
21+
return customParameters[PARAM_CALLER_NAME]
22+
?: customParameters[PARAM_CALLER_ID]?.let { resolveHumanReadableName(it) }
23+
?: run {
24+
val mFrom = mCallInvite.from ?: ""
25+
if (mFrom.isEmpty()) {
26+
return mStorage.defaultCaller
27+
}
28+
29+
if (!mFrom.startsWith("client:")) {
30+
// we have a number, return as is
31+
return mFrom
32+
}
33+
34+
val mToName = mFrom.replace("client:", "")
35+
return resolveHumanReadableName(mToName)
36+
}
3537
}
3638

3739
override val to: String
3840
get() {
39-
val mTo = mCallInvite.to
40-
if (!mTo.startsWith("client:")) {
41-
// we have a number, return as is
42-
return mTo
43-
}
44-
45-
val mToName = mTo.replace("client:", "")
4641
return customParameters[PARAM_RECIPIENT_NAME]
4742
?: customParameters[PARAM_RECIPIENT_ID]?.let { resolveHumanReadableName(it) }
48-
?: resolveHumanReadableName(mToName)
43+
?: run {
44+
val mTo = mCallInvite.to
45+
46+
if (!mTo.startsWith("client:")) {
47+
// we have a number, return as is
48+
return mTo
49+
}
50+
51+
val mToName = mTo.replace("client:", "")
52+
return resolveHumanReadableName(mToName)
53+
}
4954
}
5055

5156
override val fromRaw: String
@@ -83,36 +88,40 @@ class TVCallParametersImpl(storage: Storage, call: Call, callTo: String, callFro
8388

8489
override val from: String
8590
get() {
86-
if (mFrom.isEmpty()) {
87-
return mStorage.defaultCaller
88-
}
89-
90-
if (!mFrom.startsWith("client:")) {
91-
// we have a number, return as is
92-
return mFrom
93-
}
94-
95-
val mFromName = mFrom.replace("client:", "")
96-
return customParameters[PARAM_RECIPIENT_NAME]
97-
?: customParameters[PARAM_RECIPIENT_ID]?.let { resolveHumanReadableName(it) }
98-
?: resolveHumanReadableName(mFromName)
91+
return customParameters[PARAM_CALLER_NAME]
92+
?: customParameters[PARAM_CALLER_ID]?.let { resolveHumanReadableName(it) }
93+
?: run {
94+
if (mFrom.isEmpty()) {
95+
return mStorage.defaultCaller
96+
}
97+
98+
if (!mFrom.startsWith("client:")) {
99+
// we have a number, return as is
100+
return mFrom
101+
}
102+
103+
val mFromName = mFrom.replace("client:", "")
104+
return resolveHumanReadableName(mFromName)
105+
}
99106
}
100107

101108
override val to: String
102109
get() {
103-
if (mTo.isEmpty()) {
104-
return mStorage.defaultCaller
105-
}
106-
107-
if (!mTo.startsWith("client:")) {
108-
// we have a number, return as is
109-
return mTo
110-
}
111-
112-
val mToName = mTo.replace("client:", "")
113110
return customParameters[PARAM_RECIPIENT_NAME]
114111
?: customParameters[PARAM_RECIPIENT_ID]?.let { resolveHumanReadableName(it) }
115-
?: resolveHumanReadableName(mToName)
112+
?: run {
113+
if (mTo.isEmpty()) {
114+
return mStorage.defaultCaller
115+
}
116+
117+
if (!mTo.startsWith("client:")) {
118+
// we have a number, return as is
119+
return mTo
120+
}
121+
122+
val mToName = mTo.replace("client:", "")
123+
return resolveHumanReadableName(mToName)
124+
}
116125
}
117126

118127
override val fromRaw: String

0 commit comments

Comments
 (0)