list known player in invite info where known

(for mqtt only)
This commit is contained in:
Eric House 2020-09-30 10:10:43 -07:00
parent 2bfeedceb3
commit dbde9c87ae
5 changed files with 55 additions and 0 deletions

View file

@ -603,6 +603,15 @@ public class DBUtils {
msg = LocUtils.getString( context, R.string.invit_expl_relay_fmt,
timestamp );
break;
case MQTT:
String player = XwJNI.kplr_nameForMqttDev( target );
if ( null != player ) {
msg = LocUtils.getString( context,
R.string.invit_expl_player_fmt,
player, timestamp );
break;
}
// else FALLTHRU
default:
msg = LocUtils.getString( context, R.string.invit_expl_notarget_fmt,
means.toString(), timestamp );

View file

@ -204,6 +204,13 @@ public class XwJNI {
: null;
}
public static String kplr_nameForMqttDev( String mqttID )
{
return BuildConfig.HAVE_KNOWN_PLAYERS
? kplr_nameForMqttDev( getJNI().m_ptrGlobals, mqttID )
: null;
}
private static void cleanGlobals()
{
synchronized( XwJNI.class ) { // let's be safe here
@ -724,6 +731,7 @@ public class XwJNI {
String newName );
private static native void kplr_deletePlayer( long jniState, String player );
private static native CommsAddrRec kplr_getAddr( long jniState, String name );
public static native String kplr_nameForMqttDev( long jniState, String mqttID );
private static native void cleanGlobals( long jniState );
private static native byte[] gi_to_stream( long jniState, CurGameInfo gi );

View file

@ -833,6 +833,20 @@ Java_org_eehouse_android_xw4_jni_XwJNI_kplr_1getAddr
DVC_HEADER_END();
return jaddr;
}
JNIEXPORT jstring JNICALL
Java_org_eehouse_android_xw4_jni_XwJNI_kplr_1nameForMqttDev
( JNIEnv* env, jclass C, jlong jniGlobalPtr, jstring jDevID )
{
jstring result = NULL;
DVC_HEADER(jniGlobalPtr);
const char* devid = (*env)->GetStringUTFChars( env, jDevID, NULL );
const XP_UCHAR* name = kplr_nameForMqttDev( globalState->dutil, env, devid );
result = (*env)->NewStringUTF( env, name );
(*env)->ReleaseStringUTFChars( env, jDevID, devid );
DVC_HEADER_END();
return result;
}
#endif
JNIEXPORT jbyteArray JNICALL

View file

@ -292,6 +292,27 @@ kplr_getAddr( XW_DUtilCtxt* dutil, XWEnv xwe, const XP_UCHAR* name,
return found;
}
const XP_UCHAR*
kplr_nameForMqttDev( XW_DUtilCtxt* dutil, XWEnv xwe, const XP_UCHAR* mqttDevID )
{
const XP_UCHAR* name = NULL;
MQTTDevID devID;
if ( strToMQTTCDevID( mqttDevID, &devID ) ) {
KPState* state = loadState( dutil, xwe );
for ( KnownPlayer* kp = state->players; !!kp && !name; kp = kp->next ) {
const CommsAddrRec* addr = &kp->addr;
if ( addr_hasType( addr, COMMS_CONN_MQTT ) ) {
if ( 0 == XP_MEMCMP( &addr->u.mqtt.devID, &devID, sizeof(devID) ) ) {
name = kp->name;
}
}
}
releaseState( dutil, xwe, state );
}
LOG_RETURNF( "%s", name );
return name;
}
static void
freeKP( XW_DUtilCtxt* dutil, KnownPlayer* kp )
{

View file

@ -43,6 +43,9 @@ void kplr_getNames( XW_DUtilCtxt* dutil, XWEnv xwe, const XP_UCHAR** players,
XP_U16* nFound );
XP_Bool kplr_getAddr( XW_DUtilCtxt* dutil, XWEnv xwe, const XP_UCHAR* name,
CommsAddrRec* addr );
const XP_UCHAR* kplr_nameForMqttDev( XW_DUtilCtxt* dutil, XWEnv xwe,
const XP_UCHAR* mqttDevID );
KP_Rslt kplr_renamePlayer( XW_DUtilCtxt* dutil, XWEnv xwe, const XP_UCHAR* oldName,
const XP_UCHAR* newName );
KP_Rslt kplr_deletePlayer( XW_DUtilCtxt* dutil, XWEnv xwe, const XP_UCHAR* name );