show incoming caller name if possible

This commit is contained in:
liamcottle 2025-11-24 12:50:17 +13:00
commit 9ad28d60a4
3 changed files with 50 additions and 18 deletions

View file

@ -360,9 +360,11 @@ class ReticulumMeshChat:
# get remote identity hash
remote_identity_hash = None
remote_identity_name = None
remote_identity = telephone_active_call.get_remote_identity()
if remote_identity is not None:
remote_identity_hash = remote_identity.hash.hex()
remote_identity_name = self.get_name_for_identity_hash(remote_identity_hash)
active_call = {
"hash": telephone_active_call.hash.hex(),
@ -370,6 +372,7 @@ class ReticulumMeshChat:
"is_incoming": telephone_active_call.is_incoming,
"is_outgoing": telephone_active_call.is_outgoing,
"remote_identity_hash": remote_identity_hash,
"remote_identity_name": remote_identity_name,
}
return web.json_response({
@ -3338,6 +3341,30 @@ class ReticulumMeshChat:
"announce": self.convert_db_announce_to_dict(announce),
})))
# try and get a name for the provided identity hash
def get_name_for_identity_hash(self, identity_hash: str):
# recall identity
identity = RNS.Identity.recall(bytes.fromhex(identity_hash), from_identity_hash=True)
if identity is None:
return None
# get lxmf.delivery destination hash
lxmf_destination_hash = RNS.Destination.hash(identity, "lxmf", "delivery").hex()
# use custom name if available
custom_name = self.get_custom_destination_display_name(lxmf_destination_hash)
if custom_name is not None:
return custom_name
# use lxmf name if available
lxmf_name = self.get_lxmf_conversation_name(lxmf_destination_hash, default_name=None)
if lxmf_name is not None:
return lxmf_name
# couldn't find a name for this identity
return None
# gets the custom display name a user has set for the provided destination hash
def get_custom_destination_display_name(self, destination_hash: str):
@ -3351,7 +3378,7 @@ class ReticulumMeshChat:
# get name to show for an lxmf conversation
# currently, this will use the app data from the most recent announce
# TODO: we should fetch this from our contacts database, when it gets implemented, and if not found, fallback to app data
def get_lxmf_conversation_name(self, destination_hash):
def get_lxmf_conversation_name(self, destination_hash, default_name:str|None="Anonymous Peer"):
# get lxmf.delivery announce from database for the provided destination hash
lxmf_announce = (database.Announce.select()
@ -3365,7 +3392,7 @@ class ReticulumMeshChat:
return self.parse_lxmf_display_name(app_data_base64=lxmf_announce.app_data)
# announce did not have app data, so provide a fallback name
return "Anonymous Peer"
return default_name
# reads the lxmf display name from the provided base64 app data
def parse_lxmf_display_name(self, app_data_base64: str, default_value: str | None = "Anonymous Peer"):

View file

@ -264,24 +264,18 @@ dark:bg-zinc-800 dark:text-white dark:hover:bg-zinc-700 dark:focus-visible:outli
<div class="p-1 flex dark:border-zinc-900 dark:text-white">
<div>
<div>
<span v-if="activeCall && activeCall.is_incoming">Incoming Call</span>
<span v-else-if="activeCall && activeCall.is_outgoing">Outgoing Call</span>
<span v-if="activeCall && activeCall.status === 6">Active Call</span>
<span v-else-if="activeCall && activeCall.is_incoming">Incoming Call {{ activeCall.status }}</span>
<span v-else-if="activeCall && activeCall.is_outgoing">Outgoing Call {{ activeCall.status }}</span>
<span v-else-if="activeCall">Status {{ activeCall.status }}</span>
<span v-else>Status</span>
</div>
<div class="text-sm text-gray-700 dark:text-white">
<div v-if="activeCall">
<span v-if="activeCall.is_incoming">
<span v-if="activeCall.status === 5">Connecting...</span>
<span v-else-if="activeCall.status === 6">Active</span>
<span v-else>
<span v-if="activeCall.remote_identity_hash">{{ Utils.formatDestinationHash(activeCall.remote_identity_hash) }}</span>
<span v-else>Ringing...</span>
</span>
</span>
<span v-if="activeCall.is_outgoing">
<span v-if="activeCall.status === 5">Connecting...</span>
<span v-else-if="activeCall.status === 6">Active</span>
<span v-else>Calling...</span>
<span>
<span v-if="activeCall.remote_identity_name != null">{{ activeCall.remote_identity_name }}</span>
<span v-else-if="activeCall.remote_identity_hash != null">{{ Utils.formatDestinationHash(activeCall.remote_identity_hash) }}</span>
<span v-else>Unknown Caller</span>
</span>
</div>
<div v-else>Hung up, waiting for call...</div>

View file

@ -71,7 +71,11 @@
</div>
</div>
<div>
<div>{{ activeCall.remote_identity_hash || "Unknown" }}</div>
<div>
<span v-if="activeCall.remote_identity_name != null">{{ activeCall.remote_identity_name }}</span>
<span v-else-if="activeCall.remote_identity_hash != null">{{ Utils.formatDestinationHash(activeCall.remote_identity_hash) }}</span>
<span v-else>Unknown</span>
</div>
<div class="text-sm text-gray-500 dark:text-zinc-100">
<span>
<span v-if="activeCall.status === 0">Busy...</span>
@ -80,7 +84,7 @@
<span v-else-if="activeCall.status === 3">Available...</span>
<span v-else-if="activeCall.status === 4">Ringing...</span>
<span v-else-if="activeCall.status === 5">Connecting...</span>
<span v-else-if="activeCall.status === 6">Established...</span>
<span v-else-if="activeCall.status === 6">Connected</span>
<span v-else>Status: {{ activeCall.status }}</span>
</span>
</div>
@ -113,8 +117,15 @@
</template>
<script>
import Utils from "../../js/Utils";
export default {
name: 'TelephonePage',
computed: {
Utils() {
return Utils;
}
},
data() {
return {