<commit_before>package net.yasme.android.asyncTasks;

import android.content.Context;
import android.os.AsyncTask;
import android.util.Log;

import net.yasme.android.connection.ChatTask;
import net.yasme.android.entities.Chat;
import net.yasme.android.entities.User;
import net.yasme.android.exception.RestServiceException;
import net.yasme.android.storage.DatabaseManager;
import net.yasme.android.ui.InviteToChatFragment;

import java.util.Date;
import java.util.List;

/**
 * Created by bene on 22.06.14.
 */
public class CreateChatTask extends AsyncTask<String, Void, Boolean> {

    private DatabaseManager databaseManager = DatabaseManager.getInstance();
    protected Context context;
    protected InviteToChatFragment fragment;
    private List<User> selectedUsers;
    private long userId;
    private String accessToken;
    private long newChatId = -1;
    private Chat newChat;

    public CreateChatTask(Context context, InviteToChatFragment fragment, List<User> selectedUsers) {
        this.context = context;
        this.fragment = fragment;
        this.selectedUsers = selectedUsers;
    }


    /**
     * @param params
     *              0 is userId
     *              1 is accessToken
     * @return Returns true if it was successful, otherwise false
     */
    @Override
    protected Boolean doInBackground(String... params) {
        userId = Long.parseLong(params[0]);
        accessToken = params[1];

        List<Chat> matchingChats = databaseManager.getChats(selectedUsers);
        if (null != matchingChats && matchingChats.size() > 0) {
            // Take first chat
            newChatId = matchingChats.get(0).getId();
        } else {
            // No chat found in database. Create a new one

            User owner = fragment.getAbstractYasmeActivity().getSelfUser();
            // Concatenate chat name according to the participant's names
            String name = "";
            for (int i=0; i<selectedUsers.size(); i++) {
                name += selectedUsers.get(i).getName();
                if (i != selectedUsers.size() - 1) {
                    name += ", ";
                }
            }

            newChat = new Chat(owner, "Created: " + new Date().toString(), name);
            newChat.setParticipants(selectedUsers);
            try {
                newChatId = ChatTask.getInstance().createChatWithPar(newChat, userId, accessToken);
            } catch (RestServiceException e) {
                // TODO
                e.printStackTrace();
                return false;<commit_msg>removed merge error<commit_after>package net.yasme.android.asyncTasks;

import android.content.Context;
import android.os.AsyncTask;
import android.util.Log;

import net.yasme.android.connection.ChatTask;
import net.yasme.android.entities.Chat;
import net.yasme.android.entities.User;
import net.yasme.android.exception.RestServiceException;
import net.yasme.android.storage.DatabaseManager;
import net.yasme.android.ui.InviteToChatFragment;

import java.util.Date;
import java.util.List;

/**
 * Created by bene on 22.06.14.
 */
public class CreateChatTask extends AsyncTask<String, Void, Boolean> {

    private DatabaseManager databaseManager = DatabaseManager.getInstance();
    protected Context context;
    protected InviteToChatFragment fragment;
    private List<User> selectedUsers;
    private long userId;
    private String accessToken;
    private long newChatId = -1;
    private Chat newChat;

    public CreateChatTask(Context context, InviteToChatFragment fragment, List<User> selectedUsers) {
        this.context = context;
        this.fragment = fragment;
        this.selectedUsers = selectedUsers;
    }


    /**
     * @param params
     *              0 is userId
     *              1 is accessToken
     * @return Returns true if it was successful, otherwise false
     */
    @Override
    protected Boolean doInBackground(String... params) {
        userId = Long.parseLong(params[0]);
        accessToken = params[1];

        List<Chat> matchingChats = databaseManager.getChats(selectedUsers);
        if (null != matchingChats && matchingChats.size() > 0) {
            // Take first chat
            newChatId = matchingChats.get(0).getId();
        } else {
            // No chat found in database. Create a new one

            User owner = fragment.getAbstractYasmeActivity().getSelfUser();
            // Concatenate chat name according to the participant's names
            String name = "";
            for (int i=0; i<selectedUsers.size(); i++) {
                name += selectedUsers.get(i).getName();
                if (i != selectedUsers.size() - 1) {
                    name += ", ";
                }
            }

            newChat = new Chat(owner, "Created: " + new Date().toString(), name);
            newChat.setParticipants(selectedUsers);
            try {
                newChatId = ChatTask.getInstance().createChatWithPar(newChat);
            } catch (RestServiceException e) {
                // TODO
                e.printStackTrace();
                return false;
{'fraction_non_alphanumeric': 0.10029498525073746, 'fraction_numerical': 0.0058997050147492625, 'mean_word_length': 2.3704440026507623, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '1373808', 'n_tokens_mistral': 1368, 'n_tokens_neox': 1330, 'n_words': 337}