track, and offer to display, comms-sent invites like others

I'm only keeping the most recent since they're sent every time a game
opens, app launches, etc.
This commit is contained in:
Eric House 2022-12-10 22:15:33 -08:00
parent b8a9e1715a
commit 53e1a68d6d
13 changed files with 204 additions and 85 deletions

View file

@ -1533,9 +1533,8 @@ public class BoardDelegate extends DelegateBase
} }
@Override @Override
public void onInfoClicked() public void onInfoClicked( SentInvitesInfo sentInfo )
{ {
SentInvitesInfo sentInfo = DBUtils.getInvitesFor( m_activity, m_rowid );
String msg = sentInfo.getAsText( m_activity ); String msg = sentInfo.getAsText( m_activity );
makeOkOnlyBuilder( msg ) makeOkOnlyBuilder( msg )
.setTitle( R.string.title_invite_history ) .setTitle( R.string.title_invite_history )
@ -2543,7 +2542,7 @@ public class BoardDelegate extends DelegateBase
private InvitesNeededAlert.Wrapper getINAWrapper() private InvitesNeededAlert.Wrapper getINAWrapper()
{ {
if ( null == mINAWrapper ) { if ( null == mINAWrapper ) {
mINAWrapper = new InvitesNeededAlert.Wrapper( this ); mINAWrapper = new InvitesNeededAlert.Wrapper( this, m_jniGamePtr );
showOrHide( mINAWrapper ); showOrHide( mINAWrapper );
} }
return mINAWrapper; return mINAWrapper;
@ -3055,6 +3054,9 @@ public class BoardDelegate extends DelegateBase
// recordInviteSent( InviteMeans.SMS_DATA, addr.sms_phone ); // recordInviteSent( InviteMeans.SMS_DATA, addr.sms_phone );
break; break;
case COMMS_CONN_NFC: // don't assert about this one
break;
default: default:
Log.d( TAG, "not inviting using addr type %s", typ ); Log.d( TAG, "not inviting using addr type %s", typ );
Assert.failDbg(); Assert.failDbg();
@ -3099,7 +3101,7 @@ public class BoardDelegate extends DelegateBase
invitesSent = nSent >= m_mySIS.nMissing; invitesSent = nSent >= m_mySIS.nMissing;
} }
DBUtils.recordInviteSent( m_activity, m_rowid, means, dev ); DBUtils.recordInviteSent( m_activity, m_rowid, means, dev, false );
if ( !invitesSent ) { if ( !invitesSent ) {
Log.d( TAG, "recordInviteSent(): redoing invite alert" ); Log.d( TAG, "recordInviteSent(): redoing invite alert" );

View file

@ -60,7 +60,7 @@ public class CommsTransport implements TransportProcs {
public boolean transportSendInvt( CommsAddrRec addr, NetLaunchInfo nli, public boolean transportSendInvt( CommsAddrRec addr, NetLaunchInfo nli,
int timestamp ) int timestamp )
{ {
return MultiMsgSink.sendInvite( m_context, addr, nli, timestamp ); return MultiMsgSink.sendInvite( m_context, m_rowid, addr, nli, timestamp );
} }
@Override @Override

View file

@ -450,12 +450,36 @@ public class DBUtils {
return result; return result;
} }
public static class SentInvite implements Serializable {
InviteMeans mMeans;
String mTarget;
Date mTimestamp;
public SentInvite( InviteMeans means, String target, Date ts )
{
mMeans = means;
mTarget = target;
mTimestamp = ts;
}
@Override
public boolean equals(Object otherObj)
{
boolean result = false;
if ( otherObj instanceof SentInvite ) {
SentInvite other = (SentInvite)otherObj;
result = mMeans == other.mMeans
&& mTarget.equals(other.mTarget)
&& mTimestamp.equals(other.mTimestamp);
}
return result;
}
}
public static class SentInvitesInfo public static class SentInvitesInfo
implements Serializable /* Serializable b/c passed as param to alerts */ { implements Serializable /* Serializable b/c passed as param to alerts */ {
public long m_rowid; public long m_rowid;
private ArrayList<InviteMeans> m_means; private ArrayList<SentInvite> mSents;
private ArrayList<String> m_targets;
private ArrayList<Date> m_timestamps;
private int m_cachedCount = 0; private int m_cachedCount = 0;
private boolean m_remotesRobots = false; private boolean m_remotesRobots = false;
@ -465,11 +489,13 @@ public class DBUtils {
boolean result = null != other && other instanceof SentInvitesInfo; boolean result = null != other && other instanceof SentInvitesInfo;
if ( result ) { if ( result ) {
SentInvitesInfo it = (SentInvitesInfo)other; SentInvitesInfo it = (SentInvitesInfo)other;
result = it.m_rowid == m_rowid if ( m_rowid == it.m_rowid
&& it.m_means.equals(m_means) && it.mSents.size() == mSents.size()
&& it.m_targets.equals(m_targets) && it.m_cachedCount == m_cachedCount ) {
&& it.m_timestamps.equals(m_timestamps) for ( int ii = 0; result && ii < mSents.size(); ++ii ) {
&& it.m_cachedCount == m_cachedCount; result = it.mSents.get(ii).equals(mSents.get(ii));
}
}
} }
// Log.d( TAG, "equals() => %b", result ); // Log.d( TAG, "equals() => %b", result );
return result; return result;
@ -478,30 +504,22 @@ public class DBUtils {
private SentInvitesInfo( long rowID ) private SentInvitesInfo( long rowID )
{ {
m_rowid = rowID; m_rowid = rowID;
m_means = new ArrayList<>(); mSents = new ArrayList<>();
m_targets = new ArrayList<>();
m_timestamps = new ArrayList<>();
} }
private void addEntry( InviteMeans means, String target, Date ts ) private void addEntry( InviteMeans means, String target, Date ts )
{ {
m_means.add( means ); mSents.add( new SentInvite( means, target, ts ) );
m_targets.add( target );
m_timestamps.add( ts );
m_cachedCount = -1; m_cachedCount = -1;
} }
public InviteMeans getLastMeans()
{
return 0 < m_means.size() ? m_means.get(0) : null;
}
public String getLastDev( InviteMeans means ) public String getLastDev( InviteMeans means )
{ {
String result = null; String result = null;
for ( int ii = 0; null == result && ii < m_means.size(); ++ii ) { for ( SentInvite si : mSents ) {
if ( means == m_means.get( ii ) ) { if ( means == si.mMeans ) {
result = m_targets.get( ii ); result = si.mTarget;
break;
} }
} }
return result; return result;
@ -514,19 +532,20 @@ public class DBUtils {
public int getMinPlayerCount() public int getMinPlayerCount()
{ {
if ( -1 == m_cachedCount ) { if ( -1 == m_cachedCount ) {
int count = m_timestamps.size(); int count = mSents.size();
Map<InviteMeans, Set<String>> hashes Map<InviteMeans, Set<String>> hashes
= new HashMap<InviteMeans, Set<String>>(); = new HashMap<InviteMeans, Set<String>>();
int fakeCount = 0; // make all null-targets count for one int fakeCount = 0; // make all null-targets count for one
for ( int ii = 0; ii < count; ++ii ) { for ( int ii = 0; ii < count; ++ii ) {
InviteMeans means = m_means.get(ii); SentInvite si = mSents.get(ii);
InviteMeans means = si.mMeans;
Set<String> devs; Set<String> devs;
if ( ! hashes.containsKey( means ) ) { if ( ! hashes.containsKey( means ) ) {
devs = new HashSet<>(); devs = new HashSet<>();
hashes.put( means, devs ); hashes.put( means, devs );
} }
devs = hashes.get( means ); devs = hashes.get( means );
String target = m_targets.get( ii ); String target = si.mTarget;
if ( null == target ) { if ( null == target ) {
target = String.format( "%d", ++fakeCount ); target = String.format( "%d", ++fakeCount );
} }
@ -548,15 +567,15 @@ public class DBUtils {
public String getAsText( Context context ) public String getAsText( Context context )
{ {
String result; String result;
int count = m_timestamps.size(); int count = mSents.size();
if ( 0 == count ) { if ( 0 == count ) {
result = LocUtils.getString( context, R.string.no_invites ); result = LocUtils.getString( context, R.string.no_invites );
} else { } else {
String[] strs = new String[count]; List<String> strs = new ArrayList<>();
for ( int ii = 0; ii < count; ++ii ) { for ( SentInvite si: mSents ) {
InviteMeans means = m_means.get(ii); InviteMeans means = si.mMeans;
String target = m_targets.get(ii); String target = si.mTarget;
String timestamp = m_timestamps.get(ii).toString(); String timestamp = si.mTimestamp.toString();
String msg = null; String msg = null;
switch ( means ) { switch ( means ) {
@ -590,8 +609,9 @@ public class DBUtils {
means.toString(), timestamp ); means.toString(), timestamp );
} }
strs[ii] = msg; strs.add( msg );
} }
result = TextUtils.join( "\n\n", strs ); result = TextUtils.join( "\n\n", strs );
} }
return result; return result;
@ -599,18 +619,20 @@ public class DBUtils {
public String getKPName( Context context ) public String getKPName( Context context )
{ {
String result = null; String mqttID = null;
for ( int ii = 0; ii < m_means.size(); ++ii ) { for ( SentInvite si : mSents ) {
InviteMeans means = m_means.get(ii); InviteMeans means = si.mMeans;
if ( means == InviteMeans.MQTT ) { if ( means == InviteMeans.MQTT ) {
String player = XwJNI.kplr_nameForMqttDev( m_targets.get(ii) ); mqttID = si.mTarget;
if ( null != player ) { break;
result = player;
break; // ordered newest-first, so we're done
}
} }
} }
String result = null;
if ( null != mqttID ) {
result = XwJNI.kplr_nameForMqttDev( mqttID );
}
Log.d( TAG, "getKPName() => %s", result );
return result; return result;
} }
@ -655,7 +677,8 @@ public class DBUtils {
} }
public static void recordInviteSent( Context context, long rowid, public static void recordInviteSent( Context context, long rowid,
InviteMeans means, String target ) InviteMeans means, String target,
boolean dropDupes )
{ {
if ( BuildConfig.NON_RELEASE ) { if ( BuildConfig.NON_RELEASE ) {
switch ( means ) { switch ( means ) {
@ -665,15 +688,31 @@ public class DBUtils {
case WIFIDIRECT: case WIFIDIRECT:
case SMS_USER: case SMS_USER:
case QRCODE: case QRCODE:
break; case MQTT:
case SMS_DATA: case SMS_DATA:
case BLUETOOTH: case BLUETOOTH:
case MQTT: break;
case RELAY: case RELAY:
default: default:
Assert.failDbg(); Assert.failDbg();
} }
} }
String dropTest = null;
if ( dropDupes ) {
dropTest = String.format( "%s = %d AND %s = %d",
DBHelper.ROW, rowid,
DBHelper.MEANS, means.ordinal() );
if ( null != target ) {
dropTest += String.format( " AND %s = '%s'",
DBHelper.TARGET, target );
} else {
// If I'm seeing this, need to check above if a "target is
// null" test is needed to avoid nuking unintentinally.
Assert.failDbg();
}
}
ContentValues values = new ContentValues(); ContentValues values = new ContentValues();
values.put( DBHelper.ROW, rowid ); values.put( DBHelper.ROW, rowid );
values.put( DBHelper.MEANS, means.ordinal() ); values.put( DBHelper.MEANS, means.ordinal() );
@ -683,6 +722,9 @@ public class DBUtils {
initDB( context ); initDB( context );
synchronized( s_dbHelper ) { synchronized( s_dbHelper ) {
if ( null != dropTest ) {
delete( TABLE_NAMES.INVITES, dropTest );
}
insert( TABLE_NAMES.INVITES, values ); insert( TABLE_NAMES.INVITES, values );
} }
} }

View file

@ -32,6 +32,7 @@ import org.eehouse.android.xw4.Perms23.Perm;
import org.eehouse.android.xw4.jni.CommsAddrRec.CommsConnType; import org.eehouse.android.xw4.jni.CommsAddrRec.CommsConnType;
import org.eehouse.android.xw4.jni.CommsAddrRec; import org.eehouse.android.xw4.jni.CommsAddrRec;
import org.eehouse.android.xw4.jni.XwJNI; import org.eehouse.android.xw4.jni.XwJNI;
import org.eehouse.android.xw4.jni.XwJNI.GamePtr;
import org.eehouse.android.xw4.loc.LocUtils; import org.eehouse.android.xw4.loc.LocUtils;
class InvitesNeededAlert { class InvitesNeededAlert {
@ -45,8 +46,13 @@ class InvitesNeededAlert {
private Callbacks mCallbacks; private Callbacks mCallbacks;
private InvitesNeededAlert mSelf; private InvitesNeededAlert mSelf;
private CommsAddrRec mHostAddr; private CommsAddrRec mHostAddr;
private GamePtr mGamePtr;
Wrapper( Callbacks callbacks ) { mCallbacks = callbacks; } Wrapper( Callbacks callbacks, GamePtr gamePtr )
{
mCallbacks = callbacks;
mGamePtr = gamePtr;
}
void showOrHide( CommsAddrRec hostAddr, int nPlayersMissing, int nInvited, void showOrHide( CommsAddrRec hostAddr, int nPlayersMissing, int nInvited,
boolean isRematch ) boolean isRematch )
@ -75,7 +81,7 @@ class InvitesNeededAlert {
AlertDialog make( DBAlert alert, Object[] params ) AlertDialog make( DBAlert alert, Object[] params )
{ {
DbgUtils.assertOnUIThread(); DbgUtils.assertOnUIThread();
return mSelf.makeImpl( mCallbacks, alert, mHostAddr, params ); return mSelf.makeImpl( mCallbacks, alert, mHostAddr, mGamePtr, params );
} }
void dismiss() void dismiss()
@ -120,7 +126,7 @@ class InvitesNeededAlert {
long getRowID(); long getRowID();
void onCloseClicked(); void onCloseClicked();
void onInviteClicked(); void onInviteClicked();
void onInfoClicked(); void onInfoClicked( SentInvitesInfo sentInfo );
} }
private boolean close() private boolean close()
@ -146,7 +152,8 @@ class InvitesNeededAlert {
} }
private AlertDialog makeImpl( final Callbacks callbacks, DBAlert alert, private AlertDialog makeImpl( final Callbacks callbacks, DBAlert alert,
CommsAddrRec hostAddr, Object[] params ) CommsAddrRec hostAddr, GamePtr gamePtr,
Object[] params )
{ {
State state = (State)params[0]; State state = (State)params[0];
AlertDialog.Builder ab = mDelegate.makeAlertBuilder(); AlertDialog.Builder ab = mDelegate.makeAlertBuilder();
@ -154,7 +161,7 @@ class InvitesNeededAlert {
int[] closeLoc = { AlertDialog.BUTTON_NEGATIVE }; int[] closeLoc = { AlertDialog.BUTTON_NEGATIVE };
if ( state.mIsServer ) { if ( state.mIsServer ) {
makeImplHost( ab, callbacks, alert, state, closeLoc ); makeImplHost( ab, callbacks, alert, state, gamePtr, closeLoc );
} else { } else {
makeImplGuest( ab, state, hostAddr ); makeImplGuest( ab, state, hostAddr );
} }
@ -217,13 +224,15 @@ class InvitesNeededAlert {
} }
private void makeImplHost( AlertDialog.Builder ab, final Callbacks callbacks, private void makeImplHost( AlertDialog.Builder ab, final Callbacks callbacks,
DBAlert alert, State state, int[] closeLoc ) DBAlert alert, State state, GamePtr gamePtr,
int[] closeLoc )
{ {
Context context = mDelegate.getActivity(); Context context = mDelegate.getActivity();
final int nPlayersMissing = state.mNPlayersMissing; final int nPlayersMissing = state.mNPlayersMissing;
long rowid = callbacks.getRowID(); long rowid = callbacks.getRowID();
SentInvitesInfo sentInfo = DBUtils.getInvitesFor( context, rowid ); SentInvitesInfo sentInfo = DBUtils.getInvitesFor( context, rowid );
int nSent = state.mNInvited + sentInfo.getMinPlayerCount(); int nSent = state.mNInvited + sentInfo.getMinPlayerCount();
boolean invitesNeeded = nPlayersMissing > nSent; boolean invitesNeeded = nPlayersMissing > nSent;
@ -271,5 +280,15 @@ class InvitesNeededAlert {
alert.setNoDismissListenerNeg( ab, inviteButtonTxt, onInvite ); alert.setNoDismissListenerNeg( ab, inviteButtonTxt, onInvite );
closeLoc[0] = DialogInterface.BUTTON_POSITIVE; closeLoc[0] = DialogInterface.BUTTON_POSITIVE;
} }
if ( BuildConfig.NON_RELEASE && 0 < nSent ) {
alert.setNoDismissListenerNeut( ab, R.string.button_invite_history,
new OnClickListener() {
@Override
public void onClick( DialogInterface dlg, int item ) {
callbacks.onInfoClicked( sentInfo );
}
} );
}
} }
} }

View file

@ -22,9 +22,9 @@ package org.eehouse.android.xw4;
import android.content.Context; import android.content.Context;
import org.eehouse.android.xw4.DlgDelegate.DlgClickNotify.InviteMeans;
import org.eehouse.android.xw4.jni.CommsAddrRec;
import org.eehouse.android.xw4.jni.CommsAddrRec.CommsConnType; import org.eehouse.android.xw4.jni.CommsAddrRec.CommsConnType;
import org.eehouse.android.xw4.jni.CommsAddrRec;
import org.eehouse.android.xw4.jni.TransportProcs; import org.eehouse.android.xw4.jni.TransportProcs;
import java.util.HashSet; import java.util.HashSet;
@ -99,7 +99,7 @@ public class MultiMsgSink implements TransportProcs {
public boolean transportSendInvt( CommsAddrRec addr, NetLaunchInfo nli, public boolean transportSendInvt( CommsAddrRec addr, NetLaunchInfo nli,
int timestamp ) int timestamp )
{ {
return sendInvite( m_context, addr, nli, timestamp ); return sendInvite( m_context, m_rowid, addr, nli, timestamp );
} }
@Override @Override
@ -148,33 +148,49 @@ public class MultiMsgSink implements TransportProcs {
Log.d( TAG, "countChanged(new=%d); dropping", newCount ); Log.d( TAG, "countChanged(new=%d); dropping", newCount );
} }
public static boolean sendInvite( Context context, CommsAddrRec addr, public static boolean sendInvite( Context context, long rowid,
NetLaunchInfo nli, int timestamp ) CommsAddrRec addr, NetLaunchInfo nli,
int timestamp )
{ {
Log.d( TAG, "sendInvite(%s, %s)", addr, nli ); Log.d( TAG, "sendInvite(%s, %s)", addr, nli );
boolean success = false; boolean success = false;
for ( CommsConnType typ : addr.conTypes ) { for ( CommsConnType typ : addr.conTypes ) {
InviteMeans means = null;
String target = null;
switch ( typ ) { switch ( typ ) {
case COMMS_CONN_MQTT: case COMMS_CONN_MQTT:
target = addr.mqtt_devID;
means = InviteMeans.MQTT;
MQTTUtils.sendInvite( context, addr.mqtt_devID, nli ); MQTTUtils.sendInvite( context, addr.mqtt_devID, nli );
success = true; success = true;
break; break;
case COMMS_CONN_SMS: case COMMS_CONN_SMS:
if ( XWPrefs.getNBSEnabled( context ) ) { if ( XWPrefs.getNBSEnabled( context ) ) {
NBSProto.inviteRemote( context, addr.sms_phone, nli ); NBSProto.inviteRemote( context, addr.sms_phone, nli );
target = addr.sms_phone;
means = InviteMeans.SMS_DATA;
success = true; success = true;
} }
break; break;
case COMMS_CONN_BT: case COMMS_CONN_BT:
BTUtils.sendInvite( context, addr.bt_btAddr, nli ); BTUtils.sendInvite( context, addr.bt_btAddr, nli );
target = addr.bt_btAddr;
means = InviteMeans.BLUETOOTH;
success = true; success = true;
break; break;
case COMMS_CONN_NFC: // nothing to do
break;
default: default:
Log.d( TAG, "sendInvite(); not handling %s", typ ); Log.d( TAG, "sendInvite(); not handling %s", typ );
// Assert.failDbg(); Assert.failDbg();
break; break;
} }
if ( null != means ) {
DBUtils.recordInviteSent( context, rowid, means, target, true );
} }
}
Log.d( TAG, "sendInvite(%s) => %b", addr, success ); Log.d( TAG, "sendInvite(%s) => %b", addr, success );
return success; return success;
} }

View file

@ -964,7 +964,7 @@
launched to send your invitation. --> launched to send your invitation. -->
<string name="newgame_invite">Invite now</string> <string name="newgame_invite">Invite now</string>
<string name="newgame_reinvite">Invite again</string> <string name="newgame_reinvite">Invite again</string>
<!-- Button offering to invite Known Player to a new game --> <!-- Title of alert showing previous invitation sent -->
<string name="title_invite_history">Invitations Sent</string> <string name="title_invite_history">Invitations Sent</string>
<string name="newgame_drop_mqtt">Drop Internet</string> <string name="newgame_drop_mqtt">Drop Internet</string>
<!-- EXPLAIN ME --> <!-- EXPLAIN ME -->

View file

@ -9,4 +9,7 @@
message but not heard back --> message but not heard back -->
<string name="missing_host_fmt">FYI, the host is a Known Player called “%1$s”.</string> <string name="missing_host_fmt">FYI, the host is a Known Player called “%1$s”.</string>
<!-- Button offering to show info about invites already sent -->
<string name="button_invite_history">History</string>
</resources> </resources>

View file

@ -601,6 +601,20 @@ addrTypesToJ( JNIEnv* env, const CommsAddrRec* addr )
return result; return result;
} }
jobjectArray
makeAddrArray( JNIEnv* env, XP_U16 count, const CommsAddrRec* addrs )
{
jclass clas = (*env)->FindClass( env, PKG_PATH("jni/CommsAddrRec") );
jobjectArray result = (*env)->NewObjectArray( env, count, clas, NULL );
for ( int ii = 0; ii < count; ++ii ) {
jobject jaddr = makeJAddr( env, &addrs[ii] );
(*env)->SetObjectArrayElement( env, result, ii, jaddr );
deleteLocalRef( env, jaddr );
}
deleteLocalRef( env, clas );
return result;
}
/* Writes a java version of CommsAddrRec into a C one */ /* Writes a java version of CommsAddrRec into a C one */
void void
getJAddrRec( JNIEnv* env, CommsAddrRec* addr, jobject jaddr ) getJAddrRec( JNIEnv* env, CommsAddrRec* addr, jobject jaddr )

View file

@ -101,6 +101,8 @@ void getJAddrRec( JNIEnv* env, CommsAddrRec* addr, jobject jaddr );
void setTypeSetFieldIn( JNIEnv* env, const CommsAddrRec* addr, jobject jTarget, void setTypeSetFieldIn( JNIEnv* env, const CommsAddrRec* addr, jobject jTarget,
const char* fldName ); const char* fldName );
jobject addrTypesToJ( JNIEnv* env, const CommsAddrRec* addr ); jobject addrTypesToJ( JNIEnv* env, const CommsAddrRec* addr );
jobjectArray makeAddrArray( JNIEnv* env, XP_U16 count,
const CommsAddrRec* addrs );
jint jenumFieldToInt( JNIEnv* env, jobject jobj, const char* field, jint jenumFieldToInt( JNIEnv* env, jobject jobj, const char* field,
const char* fieldSig ); const char* fieldSig );
void intToJenumField( JNIEnv* env, jobject jobj, int val, const char* field, void intToJenumField( JNIEnv* env, jobject jobj, int val, const char* field,

View file

@ -2277,16 +2277,7 @@ Java_org_eehouse_android_xw4_jni_XwJNI_comms_1getAddrs
CommsAddrRec addrs[MAX_NUM_PLAYERS]; CommsAddrRec addrs[MAX_NUM_PLAYERS];
XP_U16 count = VSIZE(addrs); XP_U16 count = VSIZE(addrs);
comms_getAddrs( state->game.comms, env, addrs, &count ); comms_getAddrs( state->game.comms, env, addrs, &count );
result = makeAddrArray( env, count, addrs );
jclass clas = (*env)->FindClass( env, PKG_PATH("jni/CommsAddrRec") );
result = (*env)->NewObjectArray( env, count, clas, NULL );
for ( int ii = 0; ii < count; ++ii ) {
jobject jaddr = makeJAddr( env, &addrs[ii] );
(*env)->SetObjectArrayElement( env, result, ii, jaddr );
deleteLocalRef( env, jaddr );
}
deleteLocalRef( env, clas );
} }
XWJNI_END(); XWJNI_END();
return result; return result;
@ -2701,6 +2692,26 @@ Java_org_eehouse_android_xw4_jni_XwJNI_comms_1invite
} }
XWJNI_END(); XWJNI_END();
} }
# if 0
JNIEXPORT jobjectArray JNICALL
Java_org_eehouse_android_xw4_jni_XwJNI_comms_1getInvites
( JNIEnv* env, jclass C, GamePtrType gamePtr )
{
jobjectArray result = NULL;
XWJNI_START_GLOBALS(gamePtr);
CommsCtxt* comms = state->game.comms;
XP_ASSERT( NULL != comms );
if ( NULL != comms ) {
CommsAddrRec inviteRecs[4];
XP_U16 nInvites = VSIZE(inviteRecs);
comms_getInvited( comms, env, &nInvites, inviteRecs );
result = makeAddrArray( env, nInvites, inviteRecs );
}
XWJNI_END();
return result;
}
# endif
#endif #endif
JNIEXPORT void JNICALL JNIEXPORT void JNICALL

View file

@ -214,9 +214,9 @@ static void augmentChannelAddr( CommsCtxt* comms, AddressRecord* rec,
const CommsAddrRec* addr, XWHostID hostID ); const CommsAddrRec* addr, XWHostID hostID );
static XP_Bool augmentAddrIntrnl( CommsCtxt* comms, CommsAddrRec* dest, static XP_Bool augmentAddrIntrnl( CommsCtxt* comms, CommsAddrRec* dest,
const CommsAddrRec* src, XP_Bool isNewer ); const CommsAddrRec* src, XP_Bool isNewer );
static XP_Bool channelToAddress( CommsCtxt* comms, XWEnv xwe, XP_PlayerAddr channelNo, static XP_Bool channelToAddress( const CommsCtxt* comms, XWEnv xwe,
const CommsAddrRec** addr ); XP_PlayerAddr channelNo, const CommsAddrRec** addr );
static AddressRecord* getRecordFor( CommsCtxt* comms, XWEnv xwe, static AddressRecord* getRecordFor( const CommsCtxt* comms, XWEnv xwe,
const CommsAddrRec* addr, XP_PlayerAddr channelNo ); const CommsAddrRec* addr, XP_PlayerAddr channelNo );
static void augmentSelfAddr( CommsCtxt* comms, XWEnv xwe, const CommsAddrRec* addr ); static void augmentSelfAddr( CommsCtxt* comms, XWEnv xwe, const CommsAddrRec* addr );
static XP_S16 sendMsg( CommsCtxt* comms, XWEnv xwe, MsgQueueElem* elem, static XP_S16 sendMsg( CommsCtxt* comms, XWEnv xwe, MsgQueueElem* elem,
@ -1625,11 +1625,11 @@ comms_invite( CommsCtxt* comms, XWEnv xwe, const NetLaunchInfo* nli,
LOG_RETURN_VOID(); LOG_RETURN_VOID();
} }
XP_U16 void
comms_getInvited( const CommsCtxt* comms ) comms_getInvited( const CommsCtxt* comms, /*XWEnv xwe, */
XP_U16* nInvites, CommsAddrRec* inviteRecs )
{ {
LOG_FUNC(); XP_U16 count = 0;
XP_U16 result = 0;
XP_U16 allBits = 0; XP_U16 allBits = 0;
for ( const MsgQueueElem* elem = comms->msgQueueHead; !!elem; for ( const MsgQueueElem* elem = comms->msgQueueHead; !!elem;
@ -1640,14 +1640,23 @@ comms_getInvited( const CommsCtxt* comms )
XP_U16 thisBit = 1 << channelNo; XP_U16 thisBit = 1 << channelNo;
XP_ASSERT( 0 == (thisBit & allBits) ); /* should be no dupes */ XP_ASSERT( 0 == (thisBit & allBits) ); /* should be no dupes */
if ( 0 == (thisBit & allBits) ) { if ( 0 == (thisBit & allBits) ) {
++result; XP_ASSERT( !inviteRecs );
/* if ( !!inviteRecs && count < *nInvites ) { */
/* const CommsAddrRec* rec; */
/* if ( channelToAddress( comms, xwe, channelNo, &rec ) ) { */
/* inviteRecs[count] = *rec; */
/* } else { */
/* XP_ASSERT(0); /\* what to do? Fail the whole thing? *\/ */
/* } */
/* } */
++count;
} }
allBits |= thisBit; allBits |= thisBit;
} }
} }
LOG_RETURNF( "%d", result ); *nInvites = count;
return result; // LOG_RETURNF( "%d", *nInvites );
} }
#endif #endif
@ -2525,7 +2534,7 @@ preProcess(
} /* preProcess */ } /* preProcess */
static AddressRecord* static AddressRecord*
getRecordFor( CommsCtxt* comms, XWEnv xwe, const CommsAddrRec* addr, getRecordFor( const CommsCtxt* comms, XWEnv xwe, const CommsAddrRec* addr,
const XP_PlayerAddr channelNo ) const XP_PlayerAddr channelNo )
{ {
AddressRecord* rec; AddressRecord* rec;
@ -3634,7 +3643,7 @@ augmentAddr( CommsAddrRec* addr, const CommsAddrRec* newer, XP_Bool isNewer )
} }
static XP_Bool static XP_Bool
channelToAddress( CommsCtxt* comms, XWEnv xwe, XP_PlayerAddr channelNo, channelToAddress( const CommsCtxt* comms, XWEnv xwe, XP_PlayerAddr channelNo,
const CommsAddrRec** addr ) const CommsAddrRec** addr )
{ {
AddressRecord* recs = getRecordFor( comms, xwe, NULL, channelNo ); AddressRecord* recs = getRecordFor( comms, xwe, NULL, channelNo );

View file

@ -212,7 +212,8 @@ void addrToStream( XWStreamCtxt* stream, const CommsAddrRec* addr );
#ifdef XWFEATURE_COMMS_INVITE #ifdef XWFEATURE_COMMS_INVITE
void comms_invite( CommsCtxt* comms, XWEnv xwe, const NetLaunchInfo* nli, void comms_invite( CommsCtxt* comms, XWEnv xwe, const NetLaunchInfo* nli,
const CommsAddrRec* destAddr ); const CommsAddrRec* destAddr );
XP_U16 comms_getInvited( const CommsCtxt* comms ); void comms_getInvited( const CommsCtxt* comms, /*XWEnv xwe, */
XP_U16* nInvites, CommsAddrRec* inviteRecs );
#endif #endif
XP_S16 comms_send( CommsCtxt* comms, XWEnv xwe, XWStreamCtxt* stream ); XP_S16 comms_send( CommsCtxt* comms, XWEnv xwe, XWStreamCtxt* stream );
XP_S16 comms_resendAll( CommsCtxt* comms, XWEnv xwe, CommsConnType filter, XP_S16 comms_resendAll( CommsCtxt* comms, XWEnv xwe, CommsConnType filter,

View file

@ -518,7 +518,7 @@ informMissing( const ServerCtxt* server, XWEnv xwe )
nPending = server->nv.pendingRegistrations; nPending = server->nv.pendingRegistrations;
nDevs = server->nv.nDevices - 1; nDevs = server->nv.nDevices - 1;
if ( 0 < nPending ) { if ( 0 < nPending ) {
nInvited = comms_getInvited( comms ); comms_getInvited( comms, &nInvited, NULL );
if ( nPending < nInvited ) { if ( nPending < nInvited ) {
nInvited = nPending; nInvited = nPending;
} }