public void SendChatMessage(string gameId, string username, string message, Action <StatusCode> completion) { DocumentReference chatRef = db.Collection("chats").Document(gameId); StatusCode transactionStatus = StatusCode.OK; db.RunTransactionAsync(async transaction => { DocumentSnapshot chat = await transaction.GetSnapshotAsync(chatRef); if (!chat.Exists) { transactionStatus = StatusCode.UNKNWON; return(false); } ChatState chatState = chat.ConvertTo <ChatState>(); chatState.AddMessage(username, message); transaction.Set(chatRef, chatState); return(true); }).ContinueWithOnMainThread(task => { completion(transactionStatus); }); }