Page 1 of 1

Trying to get status string of AIListContact

Posted: Thu Sep 08, 2005 9:05 pm
by Ludge
Hey everyone,

I posted this on the IRC channel, and it was suggested I posted it here too. I've been making an Adium plugin to interface with the contact list widget, and have got a bit stuck.

The link below is an excerpt of the code from the plugin. The contactDisplayName method works OK, but contactStatusList doesn't. I want to get the status of each AIListContact in the "contactList" array. Even getting the generic flags for Available/Idle/Away/Offline would be acceptable.

I have also tried to get the statusObjectForKey from it's containingObject, but no joy.
Once this is done, I will make a similar function to get the UID of each ListContact. Feel free to mock and/or suggest changes to this code. It's my first foray into objective-c.


http://paste.lisp.org/display/11478

Posted: Fri Sep 09, 2005 1:58 am
by evands
You need to take a look at the AIListContact and AIListObject headers... -[AIListObject statusType] and -[AIListObject statusMessage] are relevant :)

Side note: If you're re-creating the contact list, you might want to use -[AIListContact contactListStatusMessage], which returns an NSAttributedString (you can get the plain string with -[NSAttributedString string]).

Posted: Fri Sep 09, 2005 6:52 am
by Ludge
Thanks for replying Evan,

The thing is, I can see where the methods I need to use are, I just can't seem to get at them. Either nothing gets returned, or I get a log message saying "Selector not recognised" for the statusName/Type functions.

Posted: Fri Sep 09, 2005 7:00 am
by evands
What is contactList? Where are you getting it? What are the objects within it?

Use NSLog() within your methods to determine what you're messaging before you message it; look at what you're about to message, then check the code to see if that's reasonable.

Code: Select all

NSLog(@"This object is %@",[contactList objectAtIndex:i]);
within your loop, for example

Posted: Fri Sep 09, 2005 10:38 am
by Ludge
contactList is an array containing AIListContact objects. NSLog output confirms this.

I'm still not seeing why I can't send some messages to these objects.

For example:

Code: Select all

[contacts addObject:[NSString stringWithString:[[contactList objectAtIndex:i] displayName]]];
and
[contacts addObject:[NSString stringWithString:[[contactList objectAtIndex:i] UID]]];
both work OK (where "[contactList objectAtIndex:i]" is an AIListContact object). The displayName method comes from the AIListContact object, and UID comes from AIListObject.


But...

Code: Select all

[contacts addObject:[NSString stringWithString:[[contactList objectAtIndex:i] statusName]]];
and
[contacts addObject:[NSString stringWithString:[[contactList objectAtIndex:i] statusMessage]]];
don't work. Both cause the log messages to read "(null)".
I realise I'm sending these messages to a ListContact and not ListObject, but the UID message above works OK like this. I don't understand what I'm doing wrong. Do the AIListContacts need to somehow be turned into AIListObjects or something?

Posted: Fri Sep 09, 2005 5:59 pm
by evands
Please svn update and check the documentation I've added to AIListObject.m related to the status methods; hopefully it was clear up some confusion. The methods were previously undocumented, which is Wrong.

And in answer to your last question: AIListContacts are AIListObjects. If you look at the AIListContact.h header file, you see

Code: Select all

@interface AIListContact : AIListObject
which indicates that AIListContact inherits from its superclass AIListObject.

Posted: Thu Sep 15, 2005 6:48 am
by Ludge
Thanks for clearing up the docs Evan.

I've got the plugin to return an array of strings for statusType by using:

Code: Select all

[NSString stringWithString:[[adium statusController] defaultStatusNameForType:[[contactList objectAtIndex:i] statusType]]]
(where contactList is an array of AIListContacts)
I've not yet spent much time finding out why, but this always returns "Generic Available" for offline contacts. I'm probably doing something funny though, so will have a proper look later.

Thanks again for updating the documentation for those methods.

Posted: Thu Sep 15, 2005 11:49 am
by evands
Hmph, statusType hadn't been used that way elsewhere, to see about offline vs. online... you revealed a small bug. svn up and it'll return AIOfflineStatusType (and therefore Offline if you want to use it that way) for offline contacts.

Posted: Thu Sep 15, 2005 12:05 pm
by Ludge
:oops: I seem to be creating more and more work for you!

I'd changed the code to use the "online" method as in your bug fix, but will change it to use statusType now that's fixed.

Thanks again.