package com.zulip.android.util;

import android.content.Context;
import android.text.TextPaint;
import android.text.style.ClickableSpan;
import android.view.View;

import com.zulip.android.ZulipApp;
import com.zulip.android.filters.NarrowFilterPM;
import com.zulip.android.models.Person;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class ProfileSpan extends ClickableSpan {
    private String email;
    private int userMentionColor;

    public ProfileSpan(String email, int color) {
        this.email = email;
        userMentionColor = color;
    }

    @Override
    public void onClick(View widget) {
        Context context = widget.getContext().getApplicationContext();
        List<Person> people = new ArrayList<Person>();
        if (email.equals("*")) { //This is for "@all"
            try {
                people = Person.getAllPeople(ZulipApp.get());
            } catch (SQLException e) {
                ZLog.logException(e);
                return;
            }
        } else {
            for (String email : this.email.split(",")) {
                people.add(Person.getByEmail(ZulipApp.get(), email));
            }
            people.add(ZulipApp.get().getYou());
        }
        (((ZulipApp) context).getZulipActivity()).doNarrow(new NarrowFilterPM(people));
    }

    @Override
    public void updateDrawState(TextPaint ds) {
        ds.setColor(userMentionColor);
    }
}
@@ -1111,27 +1111,32 @@
         
-people.add(
+Person person = 
 Person.g
@@ -1167,18 +1167,113 @@
 , email)
-)
 ;
+%0A                if (person != null) %7B%0A                    people.add(person);%0A                %7D
 %0A       

Check for person null in ProfileSpan.onClick().