add index of sending player to chat transmission, and on receiving

side translate that into showing the sender's name in
notification. Not yet done: replacing silly "not me" in chat listing
with same, but now it should be easy.
This commit is contained in:
Eric House 2015-08-12 07:36:36 -07:00
parent be9b8977e5
commit 8f7267b3ec
19 changed files with 458 additions and 406 deletions

File diff suppressed because it is too large Load diff

View file

@ -501,12 +501,19 @@ and_util_warnIllegalWord( XW_UtilCtxt* uc, BadWordInfo* bwi,
#ifdef XWFEATURE_CHAT
static void
and_util_showChat( XW_UtilCtxt* uc, const XP_UCHAR const* msg )
and_util_showChat( XW_UtilCtxt* uc, const XP_UCHAR const* msg, XP_S16 from )
{
UTIL_CBK_HEADER("showChat", "(Ljava/lang/String;)V" );
UTIL_CBK_HEADER( "showChat", "(Ljava/lang/String;Ljava/lang/String;)V" );
jstring jname = NULL;
if ( 0 <= from ) {
LocalPlayer* lp = &uc->gameInfo->players[from];
XP_ASSERT( !lp->isLocal );
jname = (*env)->NewStringUTF( env, lp->name );
}
jstring jmsg = (*env)->NewStringUTF( env, msg );
(*env)->CallVoidMethod( env, util->jutil, mid, jmsg );
deleteLocalRef( env, jmsg );
(*env)->CallVoidMethod( env, util->jutil, mid, jmsg, jname );
deleteLocalRefs( env, jmsg, jname, DELETE_NO_REF );
UTIL_CBK_TAIL();
}
#endif

View file

@ -1760,13 +1760,13 @@ Java_org_eehouse_android_xw4_jni_XwJNI_server_1endGame
#ifdef XWFEATURE_CHAT
JNIEXPORT void JNICALL
Java_org_eehouse_android_xw4_jni_XwJNI_server_1sendChat
Java_org_eehouse_android_xw4_jni_XwJNI_board_1sendChat
( JNIEnv* env, jclass C, jint gamePtr, jstring jmsg )
{
XWJNI_START();
XP_ASSERT( !!state->game.server );
const char* msg = (*env)->GetStringUTFChars( env, jmsg, NULL );
server_sendChat( state->game.server, msg );
board_sendChat( state->game.board, msg );
(*env)->ReleaseStringUTFChars( env, jmsg, msg );
XWJNI_END();
}

View file

@ -1463,7 +1463,7 @@
down. -->
<string name="notify_title_fmt">Move in game %1$s</string>
<string name="notify_chat_title_fmt">Chat message in game %1$s</string>
<string name="notify_chat_body_fmt">%1$s: %2$s</string>
<!--
############################################################
# Dialogs

View file

@ -1256,6 +1256,7 @@
down. -->
<string name="notify_title_fmt">Evom ni emag %1$s</string>
<string name="notify_chat_title_fmt">Tahc egassem ni emag %1$s</string>
<string name="notify_chat_body_fmt">%1$s: %2$s</string>
<!--
############################################################
# Dialogs

View file

@ -1256,6 +1256,7 @@
down. -->
<string name="notify_title_fmt">MOVE IN GAME %1$s</string>
<string name="notify_chat_title_fmt">CHAT MESSAGE IN GAME %1$s</string>
<string name="notify_chat_body_fmt">%1$s: %2$s</string>
<!--
############################################################
# Dialogs

View file

@ -1899,7 +1899,7 @@ public class BoardDelegate extends DelegateBase
// and may stack dialogs on top of this one. Including later
// chat-messages.
@Override
public void showChat( final String msg )
public void showChat( final String msg, String fromPlayer )
{
if ( BuildConstants.CHAT_SUPPORTED ) {
post( new Runnable() {

View file

@ -73,6 +73,7 @@ public class GameUtils {
public static class BackMoveResult {
LastMoveInfo m_lmi; // instantiated on demand
String m_chat;
String m_chatFrom;
}
private static Object s_syncObj = new Object();
@ -819,6 +820,7 @@ public class GameUtils {
public String m_chat;
public boolean m_gotMsg;
public boolean m_gotChat;
public String m_chatFrom;
public boolean m_gameOver;
public FeedUtilsImpl( Context context, long rowid )
@ -829,10 +831,12 @@ public class GameUtils {
m_gotMsg = false;
m_gameOver = false;
}
public void showChat( String msg )
@Override
public void showChat( String msg, String fromName )
{
DBUtils.appendChatHistory( m_context, m_rowid, msg, false );
m_gotChat = true;
m_chatFrom = fromName;
m_chat = msg;
}
public void turnChanged( int newTurn )
@ -884,6 +888,7 @@ public class GameUtils {
if ( null != bmr ) {
if ( null != feedImpl.m_chat ) {
bmr.m_chat = feedImpl.m_chat;
bmr.m_chatFrom = feedImpl.m_chatFrom;
} else {
LastMoveInfo lmi = new LastMoveInfo();
XwJNI.model_getPlayersLastScore( gamePtr, -1, lmi );
@ -1062,7 +1067,13 @@ public class GameUtils {
int titleID;
if ( null != bmr.m_chat ) {
titleID = R.string.notify_chat_title_fmt;
msg = "\"" + bmr.m_chat + "\"";
if ( null != bmr.m_chatFrom ) {
msg = LocUtils
.getString( context, R.string.notify_chat_body_fmt,
bmr.m_chatFrom, bmr.m_chat );
} else {
msg = bmr.m_chat;
}
} else {
titleID = R.string.notify_title_fmt;
msg = bmr.m_lmi.format( context );

View file

@ -564,7 +564,7 @@ public class JNIThread extends Thread {
break;
case CMD_SENDCHAT:
XwJNI.server_sendChat( m_jniGamePtr, (String)args[0] );
XwJNI.board_sendChat( m_jniGamePtr, (String)args[0] );
break;
case CMD_NETSTATS:

View file

@ -146,7 +146,7 @@ public interface UtilCtxt {
boolean warnIllegalWord( String dict, String[] words, int turn,
boolean turnLost );
void showChat( String msg );
void showChat( String msg, String fromPlayer );
boolean phoneNumbersSame( String num1, String num2 );
}

View file

@ -293,7 +293,7 @@ public class UtilCtxtImpl implements UtilCtxt {
}
// These need to go into some sort of chat DB, not dropped.
public void showChat( String msg )
public void showChat( String msg, String fromPlayer )
{
subclassOverride( "showChat" );
}

View file

@ -262,6 +262,7 @@ public class XwJNI {
public static native boolean board_endTrade( int gamePtr );
public static native String board_formatRemainingTiles( int gamePtr );
public static native void board_sendChat( int gamePtr, String msg );
public enum XP_Key {
XP_KEY_NONE,
@ -304,7 +305,6 @@ public class XwJNI {
public static native String server_writeFinalScores( int gamePtr );
public static native boolean server_initClientConnection( int gamePtr );
public static native void server_endGame( int gamePtr );
public static native void server_sendChat( int gamePtr, String msg );
// hybrid to save work
public static native boolean board_server_prefsChanged( int gamePtr,

View file

@ -796,6 +796,12 @@ board_canHint( const BoardCtxt* board )
return canHint;
}
void
board_sendChat( const BoardCtxt* board, const XP_UCHAR const* msg )
{
server_sendChat( board->server, msg, board->selPlayer );
}
static XP_U16
adjustOffset( XP_U16 curOffset, XP_S16 zoomBy )
{

View file

@ -129,6 +129,7 @@ XP_Bool board_canHideRack( const BoardCtxt* board );
XP_Bool board_canTrade( BoardCtxt* board );
XP_Bool board_canTogglePending( const BoardCtxt* board );
XP_Bool board_canHint( const BoardCtxt* board );
void board_sendChat( const BoardCtxt* board, const XP_UCHAR const* msg );
/* zoomBy: >0: zoom in; < 0: zoom out; 0: query only */
XP_Bool board_zoom( BoardCtxt* board, XP_S16 zoomBy, XP_Bool* canInOut );

View file

@ -636,12 +636,14 @@ server_initClientConnection( ServerCtxt* server, XWStreamCtxt* stream )
#ifdef XWFEATURE_CHAT
static void
sendChatTo( ServerCtxt* server, XP_U16 devIndex, const XP_UCHAR const* msg )
sendChatTo( ServerCtxt* server, XP_U16 devIndex, const XP_UCHAR const* msg,
XP_S8 from )
{
if ( comms_canChat( server->vol.comms ) ) {
XWStreamCtxt* stream = messageStreamWithHeader( server, devIndex,
XWPROTO_CHAT );
stringToStream( stream, msg );
stream_putU8( stream, from );
stream_destroy( stream );
} else {
XP_LOGF( "%s: dropping chat %s; queue too full?", __func__, msg );
@ -650,23 +652,23 @@ sendChatTo( ServerCtxt* server, XP_U16 devIndex, const XP_UCHAR const* msg )
static void
sendChatToClientsExcept( ServerCtxt* server, XP_U16 skip,
const XP_UCHAR const* msg )
const XP_UCHAR const* msg, XP_S8 from )
{
XP_U16 devIndex;
for ( devIndex = 1; devIndex < server->nv.nDevices; ++devIndex ) {
if ( devIndex != skip ) {
sendChatTo( server, devIndex, msg );
sendChatTo( server, devIndex, msg, from );
}
}
}
void
server_sendChat( ServerCtxt* server, const XP_UCHAR const* msg )
server_sendChat( ServerCtxt* server, const XP_UCHAR const* msg, XP_S16 from )
{
if ( server->vol.gi->serverRole == SERVER_ISCLIENT ) {
sendChatTo( server, SERVER_DEVICE, msg );
sendChatTo( server, SERVER_DEVICE, msg, from );
} else {
sendChatToClientsExcept( server, SERVER_DEVICE, msg );
sendChatToClientsExcept( server, SERVER_DEVICE, msg, from );
}
}
#endif
@ -2813,12 +2815,14 @@ server_receiveMessage( ServerCtxt* server, XWStreamCtxt* incoming )
#ifdef XWFEATURE_CHAT
} else if ( code == XWPROTO_CHAT ) {
XP_UCHAR* msg = stringFromStream( server->mpool, incoming );
XP_S16 from = 1 <= stream_getSize( incoming )
? stream_getU8( incoming ) : -1;
if ( isServer ) {
XP_U16 sourceClientIndex =
getIndexForDevice( server, stream_getAddress( incoming ) );
sendChatToClientsExcept( server, sourceClientIndex, msg );
sendChatToClientsExcept( server, sourceClientIndex, msg, from );
}
util_showChat( server->vol.util, msg );
util_showChat( server->vol.util, msg, from );
XP_FREE( server->mpool, msg );
#endif
} else if ( readStreamHeader( server, incoming ) ) {

View file

@ -122,7 +122,8 @@ XP_Bool server_initClientConnection( ServerCtxt* server, XWStreamCtxt* stream );
#endif
#ifdef XWFEATURE_CHAT
void server_sendChat( ServerCtxt* server, const XP_UCHAR const* msg );
void server_sendChat( ServerCtxt* server, const XP_UCHAR const* msg,
XP_S16 from );
#endif
void server_formatDictCounts( ServerCtxt* server, XWStreamCtxt* stream,

View file

@ -199,7 +199,8 @@ typedef struct UtilVtable {
#endif
#ifdef XWFEATURE_CHAT
void (*m_util_showChat)( XW_UtilCtxt* uc, const XP_UCHAR* const msg );
void (*m_util_showChat)( XW_UtilCtxt* uc, const XP_UCHAR* const msg,
XP_S16 from );
#endif
#ifdef SHOW_PROGRESS
@ -346,7 +347,7 @@ struct XW_UtilCtxt {
#endif
#ifdef XWFEATURE_CHAT
# define util_showChat( uc, m ) (uc)->vtable->m_util_showChat((uc),(m))
# define util_showChat( uc, m, f ) (uc)->vtable->m_util_showChat((uc),(m),(f))
#endif
# ifdef SHOW_PROGRESS

View file

@ -1428,15 +1428,22 @@ curses_util_makeStreamFromAddr(XW_UtilCtxt* uc, XP_PlayerAddr channelNo )
#ifdef XWFEATURE_CHAT
static void
curses_util_showChat( XW_UtilCtxt* uc,
const XP_UCHAR* const XP_UNUSED_DBG(msg) )
const XP_UCHAR* const XP_UNUSED_DBG(msg),
XP_S16 XP_UNUSED_DBG(from) )
{
CursesAppGlobals* globals = (CursesAppGlobals*)uc->closure;
globals->nChatsSent = 0;
XP_LOGF( "%s: got \"%s\"", __func__, msg );
# ifdef DEBUG
const XP_UCHAR* name = "<unknown>";
if ( 0 <= from ) {
CommonGlobals* cGlobals = &globals->cGlobals;
name = cGlobals->gi->players[from].name;
}
XP_LOGF( "%s: got \"%s\" from %s", __func__, msg, name );
# endif
}
#endif
static void
setupCursesUtilCallbacks( CursesAppGlobals* globals, XW_UtilCtxt* util )
{
@ -1770,7 +1777,7 @@ chatsTimerFired( gpointer data )
comms_getChannelSeed( game->comms ),
timp->tm_hour, timp->tm_min, timp->tm_sec );
XP_LOGF( "%s: sending \"%s\"", __func__, msg );
server_sendChat( game->server, msg );
board_sendChat( game->board, msg );
++globals->nChatsSent;
}

View file

@ -1492,7 +1492,7 @@ handle_chat_button( GtkWidget* XP_UNUSED(widget), GtkGameGlobals* globals )
{
gchar* msg = gtkGetChatMessage( globals );
if ( NULL != msg ) {
server_sendChat( globals->cGlobals.game.server, msg );
board_sendChat( globals->cGlobals.game.board, msg );
g_free( msg );
}
}
@ -2093,10 +2093,16 @@ gtk_util_makeStreamFromAddr(XW_UtilCtxt* uc, XP_PlayerAddr channelNo )
#ifdef XWFEATURE_CHAT
static void
gtk_util_showChat( XW_UtilCtxt* uc, const XP_UCHAR* const msg )
gtk_util_showChat( XW_UtilCtxt* uc, const XP_UCHAR* const msg, XP_S16 from )
{
GtkGameGlobals* globals = (GtkGameGlobals*)uc->closure;
(void)gtkask( globals->window, msg, GTK_BUTTONS_OK, NULL );
XP_UCHAR buf[1024];
XP_UCHAR* name = "<unknown>";
if ( 0 <= from ) {
name = globals->cGlobals.gi->players[from].name;
}
XP_SNPRINTF( buf, VSIZE(buf), "quoth %s: %s", name, msg );
(void)gtkask( globals->window, buf, GTK_BUTTONS_OK, NULL );
}
#endif
#endif