001: package msn.messages.commands;
002:
003: import javax.swing.*;
004:
005: import msn.*;
006: import msn.messages.*;
007: import msn.util.*;
008:
009: /**
010: * (ADD) Adds a user to a list.
011: *
012: * @author mace
013: * @created June 22, 2003
014: * @modified $Date: 2003/07/18 16:09:12 $ by $Author: mikeatkinson $
015: * @version $Revision: 1.1 $ modified $Date: 2003/07/18 16:09:12 $ by $Author: mikeatkinson $
016: * @since MSNP2
017: */
018: public class JEditBug_746217 extends StatefulCommand {
019: private Contact contact;
020:
021: public JEditBug_746217(MessagingClient client, String list,
022: Contact contact) {
023: super (client, "ADD", list + " " + contact.getUserName() + " "
024: + contact.getNickName());
025: this .contact = contact;
026: }
027:
028: public void processResponse(String[] parts) {
029: String cmd = parts[0];
030: if (cmd.equals("ADD")) {
031: processAdd(parts);
032: } else if (cmd.equals("ILN")) {
033: processInitialStatus(parts);
034: } else {
035: unknown(parts);
036: }
037: }
038:
039: //{{{ processAdd()
040: /**
041: * (ADD) notice/confirmation that a user was added to a list.
042: *
043: * <code>ADD 21 {FL|RL|AL|BL} listVersion example@passport.com example@passport.com</code>
044: *
045: * @param parts Description of the Parameter
046: * @since MSNP2
047: */
048: protected void processAdd(String[] parts) {
049: String list = parts[2];
050: ContactList cl;
051: Contact contact = new Contact(parts[4], MSNUtilities
052: .decode(parts[5]));
053: if (list.equals("FL")) {
054: cl = MSN.getInstance().getContactList();
055: } else if (list.equals("RL")) {
056: if (MSN.getBooleanProperty(
057: PropertyManager.REVERSE_LIST_PROMPTING, false)) {
058: if (JOptionPane.YES_OPTION == JOptionPane
059: .showConfirmDialog(
060: null,
061: "Do you want to allow this user to send you messages?",
062: contact + " added you",
063: JOptionPane.YES_NO_OPTION,
064: JOptionPane.QUESTION_MESSAGE)) {
065: client.send(new AddUser(client, "AL", contact));
066: } else {
067: client.send(new AddUser(client, "BL", contact));
068: }
069: } else {
070: client.send(new AddUser(client, "AL", contact));
071: }
072: cl = MSN.getInstance().getReverseList();
073: } else if (list.equals("AL")) {
074: cl = MSN.getInstance().getAllowedList();
075: } else if (list.equals("BL")) {
076: cl = MSN.getInstance().getBlockedList();
077: } else {
078: unknown(parts);
079: return;
080: }
081: cl.addContact(contact);
082: cl.sort();
083: }//}}}
084:
085: //{{{ processInitialStatus()
086: /**
087: * (ILN) A notification of the state of contacts when you first sign on.
088: * One for each contact online is returned after your initial online status is set.
089: * <P>
090: * <code>ILN TrID {NLN|HDN|BSY|AWY|IDL|PHN|BRB|LUN} username nickname</code>
091: * ex: <code>ILN 7 NLN bemace@hotmail.com Brad</code>
092: *
093: * @param parts Description of the Parameter
094: * @since MSNP2
095: */
096: protected void processInitialStatus(String[] parts) {
097: Contact c = MSN.getInstance().getContactList().getContact(
098: parts[3]);
099: c.setStatus(parts[2]);
100: c.setNickName(MSNUtilities.decode(parts[4]));
101: c.notifyObservers();
102: }//}}}
103:
104: //{{{ processError()
105: protected void processError(int error, int transactionID) {
106: switch (error) {
107: case MSNConstants.ERR_INVALID_PARAMETER:
108: System.out.println("Invalid username: "
109: + contact.getUserName());
110: break;
111: default:
112: System.out.println("Error: " + error);
113: }
114: }//}}}
115: }
|