<commit_before>package com.github.tbporter.cypher_sydekick.chat;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.regex.Pattern;

import org.apache.http.protocol.HTTP;

import android.app.Notification;
import android.app.NotificationManager;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.res.Resources;
import android.os.AsyncTask;
import android.preference.PreferenceManager;
import android.util.Base64;
import android.util.Log;

import com.github.tbporter.cypher_sydekick.R;
import com.github.tbporter.cypher_sydekick.crypt.Crypt;

public class ChatTask extends AsyncTask<String, Void, String> {
	private final String WHITESPACE = "+/+";
	private ArrayList<ConversationItem> activityConversationItems_;
	private String sender_;
	private String recipient_;
	private ConversationAdapter convAdapter_;

	private Context context_;

	// Might have to add an instance of the Crypt class if we want to do
	// encryption and decription in this class
	public ChatTask() {
		activityConversationItems_ = null;
	}

	// Only need to make one instance of this class since the conversation items
	// list array ref remains the same
	public ChatTask(ConversationAdapter adapter,
			ArrayList<ConversationItem> convItems, Context c) {
		convAdapter_ = adapter;
		activityConversationItems_ = convItems;
		context_ = c;
	}

	// The two following methods are called when chatting with a new user is
	// initiated
	public void setSender(String sender) {
		sender_ = sender;
	}

	public void setRecipient(String recipient) {
		recipient_ = recipient;
	}

	@Override
	protected void onPreExecute() {

	}

	@Override
	protected String doInBackground(String... params) {
		// TODO Auto-generated method stub
		String url;
		try {
			if (params[0].equals("send-message")) { // send
				String message = params[4];
				if (message.contains(" "))
					message = params[4].replaceAll("\\s", WHITESPACE);
				// Encryption is done here
				byte[] encryptedBytes = Crypt.encrypt(message.getBytes(),
						Base64.decode(params[3], Base64.DEFAULT));
				message = Base64.encodeToString(encryptedBytes, Base64.DEFAULT);
				url = getServerAddress() + "/messages?action=send&sender="
						+ params[1].trim() + "&recipient=" + params[2].trim()
						+ "&message=" + URLEncoder.encode(message, HTTP.UTF_8);
				Log.d("URL", url);
				HttpURLConnection connection = (HttpURLConnection) (new URL(url)
						.openConnection());
				connection.setRequestMethod("GET");
				connection
						.setRequestProperty("Accept",
								"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8");
				connection
						.setRequestProperty(
								"User-Agent",
								"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.114 Safari/537.36");
				connection.connect();
				String content = getContents(connection);
				connection.disconnect();
			} else if (params[0].equals("receive-message")) { // receive
				if (!params[1].equals("") && !params[2].equals("")) {
					sender_ = params[2].trim();
					url = getServerAddress()
							+ "/messages?action=receive&sender="
							+ params[2].trim() + "&recipient="
							+ params[1].trim();
					Log.d("URL", url);
					HttpURLConnection connection = (HttpURLConnection) (new URL(
							url).openConnection());
					connection.setRequestMethod("GET");
					connection
							.setRequestProperty("Accept",
									"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8");
					connection
							.setRequestProperty(
									"User-Agent",
									"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.114 Safari/537.36");
					connection.connect();
					String messageEnc = getContents(connection);
					connection.disconnect();
					if (messageEnc.contains("Error")) {
						return null;
					} else {
						messageEnc = messageEnc.substring(messageEnc
								.indexOf(".") + 1);
						byte[] messageByte = Crypt.decrypt(Base64.decode(
								messageEnc, Base64.DEFAULT));
						String messageDec = new String(messageByte);
						if (messageDec.contains(WHITESPACE))
							;
						messageDec = messageDec.replaceAll(
								Pattern.quote(WHITESPACE), " ");
						return messageDec;
					}
				}
			} else { // add user
				url = getServerAddress() + "/users?username=" + params[0];
				Log.d("URL", url);
				HttpURLConnection connection = (HttpURLConnection) (new URL(url)
						.openConnection());
				connection.setRequestMethod("GET");
				connection
						.setRequestProperty("Accept",
								"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8");
				connection
						.setRequestProperty(
								"User-Agent",<commit_msg>Removed URL log messages.<commit_after>package com.github.tbporter.cypher_sydekick.chat;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.regex.Pattern;

import org.apache.http.protocol.HTTP;

import android.app.Notification;
import android.app.NotificationManager;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.res.Resources;
import android.os.AsyncTask;
import android.preference.PreferenceManager;
import android.util.Base64;
import android.util.Log;

import com.github.tbporter.cypher_sydekick.R;
import com.github.tbporter.cypher_sydekick.crypt.Crypt;

public class ChatTask extends AsyncTask<String, Void, String> {
	private final String WHITESPACE = "+/+";
	private ArrayList<ConversationItem> activityConversationItems_;
	private String sender_;
	private String recipient_;
	private ConversationAdapter convAdapter_;

	private Context context_;

	// Might have to add an instance of the Crypt class if we want to do
	// encryption and decription in this class
	public ChatTask() {
		activityConversationItems_ = null;
	}

	// Only need to make one instance of this class since the conversation items
	// list array ref remains the same
	public ChatTask(ConversationAdapter adapter,
			ArrayList<ConversationItem> convItems, Context c) {
		convAdapter_ = adapter;
		activityConversationItems_ = convItems;
		context_ = c;
	}

	// The two following methods are called when chatting with a new user is
	// initiated
	public void setSender(String sender) {
		sender_ = sender;
	}

	public void setRecipient(String recipient) {
		recipient_ = recipient;
	}

	@Override
	protected void onPreExecute() {

	}

	@Override
	protected String doInBackground(String... params) {
		// TODO Auto-generated method stub
		String url;
		try {
			if (params[0].equals("send-message")) { // send
				String message = params[4];
				if (message.contains(" "))
					message = params[4].replaceAll("\\s", WHITESPACE);
				// Encryption is done here
				byte[] encryptedBytes = Crypt.encrypt(message.getBytes(),
						Base64.decode(params[3], Base64.DEFAULT));
				message = Base64.encodeToString(encryptedBytes, Base64.DEFAULT);
				url = getServerAddress() + "/messages?action=send&sender="
						+ params[1].trim() + "&recipient=" + params[2].trim()
						+ "&message=" + URLEncoder.encode(message, HTTP.UTF_8);
				HttpURLConnection connection = (HttpURLConnection) (new URL(url)
						.openConnection());
				connection.setRequestMethod("GET");
				connection
						.setRequestProperty("Accept",
								"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8");
				connection
						.setRequestProperty(
								"User-Agent",
								"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.114 Safari/537.36");
				connection.connect();
				String content = getContents(connection);
				connection.disconnect();
			} else if (params[0].equals("receive-message")) { // receive
				if (!params[1].equals("") && !params[2].equals("")) {
					sender_ = params[2].trim();
					url = getServerAddress()
							+ "/messages?action=receive&sender="
							+ params[2].trim() + "&recipient="
							+ params[1].trim();
					HttpURLConnection connection = (HttpURLConnection) (new URL(
							url).openConnection());
					connection.setRequestMethod("GET");
					connection
							.setRequestProperty("Accept",
									"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8");
					connection
							.setRequestProperty(
									"User-Agent",
									"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.114 Safari/537.36");
					connection.connect();
					String messageEnc = getContents(connection);
					connection.disconnect();
					if (messageEnc.contains("Error")) {
						return null;
					} else {
						messageEnc = messageEnc.substring(messageEnc
								.indexOf(".") + 1);
						byte[] messageByte = Crypt.decrypt(Base64.decode(
								messageEnc, Base64.DEFAULT));
						String messageDec = new String(messageByte);
						if (messageDec.contains(WHITESPACE))
							;
						messageDec = messageDec.replaceAll(
								Pattern.quote(WHITESPACE), " ");
						return messageDec;
					}
				}
			} else { // add user
				url = getServerAddress() + "/users?username=" + params[0];
				HttpURLConnection connection = (HttpURLConnection) (new URL(url)
						.openConnection());
				connection.setRequestMethod("GET");
				connection
						.setRequestProperty("Accept",
								"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8");
				connection
						.setRequestProperty(
								"User-Agent",
{'fraction_non_alphanumeric': 0.1296942335317053, 'fraction_numerical': 0.019905602298378823, 'mean_word_length': 3.7292576419213974, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 12}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2563221', 'n_tokens_mistral': 3719, 'n_tokens_neox': 2892, 'n_words': 638}