<commit_before>package org.lantern.ui;

import org.apache.commons.lang3.StringUtils;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.lantern.LanternUtils;
import org.lantern.state.Friend;
import org.lantern.state.Friend.Status;
import org.lantern.state.Friends;

public class FriendNotificationDialog extends NotificationDialog {

    private final Friends friends;
    private final Friend friend;

    public FriendNotificationDialog(NotificationManager manager, Friends friends, Friend friend) {
        super(manager);
        this.friends = friends;
        this.friend = friend;
        layout();
    }

    protected void layout() {
        if (LanternUtils.isTesting()) {
            return;
        }
        final Display display = Display.getDefault();

        display.syncExec(new Runnable() {
            @Override
            public void run() {
                doLayout();
            }
        });
    }

    protected void doLayout() {
        // accept/decline/ask again later

        shell.setSize(300, 100);
        shell.setLayout(new GridLayout(3, false));

        Label titleLabel = new Label(shell, SWT.WRAP);
        GridData gd = new GridData(GridData.FILL_HORIZONTAL
                | GridData.VERTICAL_ALIGN_CENTER);
        gd.horizontalSpan = 3;
        titleLabel.setLayoutData(gd);

        final String name = friend.getName();
        final String email = friend.getEmail();
        final String text = "%s is running Lantern.  Do you want to be %s's friend?";
        final String displayName;
        final String displayEmail;
        if (StringUtils.isEmpty(name)) {
            displayName = email;
            displayEmail = email;
        } else {
            displayName = name;
            displayEmail = name + " <" + email + ">";
        }
        final String label = String.format(text, displayEmail, displayName);
        titleLabel.setText(label);

        Button yesButton = new Button(shell, SWT.NONE);
        yesButton.setText("Yes");
        yesButton.addSelectionListener(new SelectionListener() {
            @Override
            public void widgetSelected(SelectionEvent e) {
                yes();
            }

            @Override
            public void widgetDefaultSelected(SelectionEvent e) {
                yes();
            }
        });
        Button noButton = new Button(shell, SWT.NONE);
        noButton.setText("No");
        noButton.addSelectionListener(new SelectionListener() {
            @Override
            public void widgetSelected(SelectionEvent e) {
                no();
            }

            @Override
            public void widgetDefaultSelected(SelectionEvent e) {
                no();
            }
        });

        Button laterButton = new Button(shell, SWT.NONE);
        laterButton.setText("Later");
        laterButton.addSelectionListener(new SelectionListener() {
            @Override
            public void widgetSelected(SelectionEvent e) {
                later();
            }

            @Override
            public void widgetDefaultSelected(SelectionEvent e) {
                later();
            }
        });
    }

    protected void later() {
        long tomorrow = System.currentTimeMillis() + 1000 * 86400;
        friend.setNextQuery(tomorrow);
        friend.setStatus(Status.requested);
        friends.add(friend);
        friends.setNeedsSync(true);
        shell.dispose();
    }

    protected void no() {
        friend.setStatus(Status.rejected);
        friends.add(friend);
        friends.setNeedsSync(true);
        shell.dispose();
    }

    protected void yes() {
        friend.setStatus(Status.friend);
        friends.add(friend);
        friends.setNeedsSync(true);
        shell.dispose();
    }

    @Override<commit_msg>sync friends when notifications are handled<commit_after>package org.lantern.ui;

import org.apache.commons.lang3.StringUtils;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.lantern.LanternUtils;
import org.lantern.event.Events;
import org.lantern.state.Friend;
import org.lantern.state.Friend.Status;
import org.lantern.state.Friends;
import org.lantern.state.SyncPath;

public class FriendNotificationDialog extends NotificationDialog {

    private final Friends friends;
    private final Friend friend;

    public FriendNotificationDialog(NotificationManager manager, Friends friends, Friend friend) {
        super(manager);
        this.friends = friends;
        this.friend = friend;
        layout();
    }

    protected void layout() {
        if (LanternUtils.isTesting()) {
            return;
        }
        final Display display = Display.getDefault();

        display.syncExec(new Runnable() {
            @Override
            public void run() {
                doLayout();
            }
        });
    }

    protected void doLayout() {
        // accept/decline/ask again later

        shell.setSize(300, 100);
        shell.setLayout(new GridLayout(3, false));

        Label titleLabel = new Label(shell, SWT.WRAP);
        GridData gd = new GridData(GridData.FILL_HORIZONTAL
                | GridData.VERTICAL_ALIGN_CENTER);
        gd.horizontalSpan = 3;
        titleLabel.setLayoutData(gd);

        final String name = friend.getName();
        final String email = friend.getEmail();
        final String text = "%s is running Lantern.  Do you want to be %s's friend?";
        final String displayName;
        final String displayEmail;
        if (StringUtils.isEmpty(name)) {
            displayName = email;
            displayEmail = email;
        } else {
            displayName = name;
            displayEmail = name + " <" + email + ">";
        }
        final String label = String.format(text, displayEmail, displayName);
        titleLabel.setText(label);

        Button yesButton = new Button(shell, SWT.NONE);
        yesButton.setText("Yes");
        yesButton.addSelectionListener(new SelectionListener() {
            @Override
            public void widgetSelected(SelectionEvent e) {
                yes();
            }

            @Override
            public void widgetDefaultSelected(SelectionEvent e) {
                yes();
            }
        });
        Button noButton = new Button(shell, SWT.NONE);
        noButton.setText("No");
        noButton.addSelectionListener(new SelectionListener() {
            @Override
            public void widgetSelected(SelectionEvent e) {
                no();
            }

            @Override
            public void widgetDefaultSelected(SelectionEvent e) {
                no();
            }
        });

        Button laterButton = new Button(shell, SWT.NONE);
        laterButton.setText("Later");
        laterButton.addSelectionListener(new SelectionListener() {
            @Override
            public void widgetSelected(SelectionEvent e) {
                later();
            }

            @Override
            public void widgetDefaultSelected(SelectionEvent e) {
                later();
            }
        });
    }

    protected void later() {
        long tomorrow = System.currentTimeMillis() + 1000 * 86400;
        friend.setNextQuery(tomorrow);
        friend.setStatus(Status.requested);
        friends.add(friend);
        friends.setNeedsSync(true);
        Events.sync(SyncPath.FRIENDS, friends.getFriends());
        shell.dispose();
    }

    protected void no() {
        setFriendStatus(Status.rejected);
    }

    protected void yes() {
        setFriendStatus(Status.friend);
    }

    private void setFriendStatus(Status status) {
        friend.setStatus(status);
        friends.add(friend);
        friends.setNeedsSync(true);
        Events.sync(SyncPath.FRIENDS, friends.getFriends());
        shell.dispose();
    }

    @Override
{'fraction_non_alphanumeric': 0.09845490477901545, 'fraction_numerical': 0.004311893639956881, 'mean_word_length': 2.0960326288468667, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '675440', 'n_tokens_mistral': 2239, 'n_tokens_neox': 2148, 'n_words': 474}