StropheCappuccino API 1.0.0
/tmp/tempDoc.doc/TNStropheRosterBase.j
Go to the documentation of this file.
00001 /*
00002  * TNStropheRosterBase.j
00003  *
00004  * Copyright (C) 2010  Antoine Mercadal <antoine.mercadal@inframonde.eu>
00005  *
00006  * This library is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU Lesser General Public
00008  * License as published by the Free Software Foundation; either
00009  * version 3.0 of the License, or (at your option) any later version.
00010  *
00011  * This library is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  * Lesser General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU Lesser General Public
00017  * License along with this library; if not, write to the Free Software
00018  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00019  */
00020 
00021 
00022 
00023 
00027 @implementation TNStropheRosterBase : CPObject
00028 {
00029     CPArray                 _contactCache;
00030     CPArray                 _groupCache;
00031     CPArray                 _content;
00032     id                      _delegate;
00033     TNStropheConnection     _connection;
00034 }
00035 
00036 #pragma mark -
00037 #pragma mark Class methods
00038 
00039 + (id)rosterWithConnection:(TNStropheConnection)aConnection
00040 {
00041     return [[TNStropheRosterBase alloc] initWithConnection:aConnection];
00042 }
00043 
00044 #pragma mark -
00045 #pragma mark Initialization
00046 
00051 - (id)initWithConnection:(TNStropheConnection)aConnection
00052 {
00053     if (self = [super init])
00054     {
00055         _connection     = aConnection;
00056         _content        = [CPArray array];
00057         _contactCache   = [CPArray array];
00058         _groupCache     = [CPArray array];
00059     }
00060 
00061     return self;
00062 }
00063 
00066 - (void)disconnect
00067 {
00068     [_connection disconnect];
00069 }
00070 
00071 - (void)clear
00072 {
00073     [_content removeAllObjects];
00074     [_contactCache removeAllObjects];
00075     [_groupCache removeAllObjects];
00076 }
00077 
00078 
00079 #pragma mark -
00080 #pragma mark Contacts
00081 
00084 - (void)contacts
00085 {
00086     return _contactCache;
00087 }
00088 
00092 - (void)cacheContact:(TNStropheContact)aContact
00093 {
00094     if (![_contactCache containsObject:aContact])
00095         [_contactCache addObject:aContact];
00096 }
00097 
00101 - (void)uncacheContact:(TNStropheContact)aContact
00102 {
00103     [_contactCache removeObject:aContact];
00104 }
00105 
00106 
00107 
00112 - (TNStropheContact)contactWithJID:(TNStropheJID)aJID
00113 {
00114     return [self contactWithFullJID:aJID] || [self contactWithBareJID:aJID];
00115 }
00116 
00121 - (TNStropheContact)contactWithFullJID:(TNStropheJID)aJID
00122 {
00123     for (var i = 0; i < [_contactCache count]; i++)
00124         if ([[[_contactCache objectAtIndex:i] JID] fullEquals:aJID])
00125             return [_contactCache objectAtIndex:i];
00126     return nil;
00127 }
00128 
00133 - (TNStropheContact)contactWithBareJID:(TNStropheJID)aJID
00134 {
00135     for (var i = 0; i < [_contactCache count]; i++)
00136         if ([[[_contactCache objectAtIndex:i] JID] bareEquals:aJID])
00137             return [_contactCache objectAtIndex:i];
00138     return nil;
00139 }
00140 
00144 - (BOOL)containsJID:(TNStropheJID)aJID
00145 {
00146     return ([self contactWithBareJID:aJID] || [self contactWithFullJID:aJID]);
00147 }
00148 
00153 - (BOOL)containsFullJID:(TNStropheJID)aJID
00154 {
00155     return ([self contactWithFullJID:aJID]) ? YES : NO;
00156 }
00157 
00162 - (BOOL)containsBareJID:(TNStropheJID)aJID
00163 {
00164     return ([self contactWithBareJID:aJID]) ? YES : NO;
00165 }
00166 
00171 - (void)changeNickname:(CPString)aName ofContact:(TNStropheContact)aContact
00172 {
00173     [aContact setNickname:aName];
00174 }
00175 
00180 - (void)changeNickname:(CPString)aName ofContactWithJID:(TNStropheJID)aJID
00181 {
00182     [self changeNickname:aName ofContact:[self contactWithJID:aJID]];
00183 }
00184 
00185 @end
00186 
00187 @implementation TNStropheRosterBase (CPSynthesizedAccessors)
00188 
00192 - (CPArray)contactCache
00193 {
00194     return _contactCache;
00195 }
00196 
00200 - (CPArray)groupCache
00201 {
00202     return _groupCache;
00203 }
00204 
00208 - (CPArray)content
00209 {
00210     return _content;
00211 }
00212 
00216 - (id)delegate
00217 {
00218     return _delegate;
00219 }
00220 
00224 - (void)setDelegate:(id)aValue
00225 {
00226     _delegate = aValue;
00227 }
00228 
00232 - (TNStropheConnection)connection
00233 {
00234     return _connection;
00235 }
00236 
00237 @end
 All Classes Namespaces Files Functions Variables