Skip to content

Commit

Permalink
Continued work on MUC
Browse files Browse the repository at this point in the history
  • Loading branch information
robbiehanson committed Dec 15, 2011
1 parent d422e28 commit 9bc1b16
Show file tree
Hide file tree
Showing 33 changed files with 1,969 additions and 190 deletions.
2 changes: 2 additions & 0 deletions Extensions/CoreDataStorage/XMPPCoreDataStorage.m
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ - (id)initWithDatabaseFilename:(NSString *)aDatabaseFileName
}

[self commonInit];
NSAssert(storageQueue != NULL, @"Subclass forgot to invoke [super commonInit]");
}
return self;
}
Expand All @@ -234,6 +235,7 @@ - (id)initWithInMemoryStore
if ((self = [super init]))
{
[self commonInit];
NSAssert(storageQueue != NULL, @"Subclass forgot to invoke [super commonInit]");
}
return self;
}
Expand Down
2 changes: 2 additions & 0 deletions Extensions/CoreDataStorage/XMPPCoreDataStorageProtected.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
/**
* If your subclass needs to do anything for init, it can do so easily by overriding this method.
* All public init methods will invoke this method at the end of their implementation.
*
* Important: If overriden you must invoke [super commonInit] at some point.
**/
- (void)commonInit;

Expand Down
3 changes: 3 additions & 0 deletions Extensions/Roster/CoreDataStorage/XMPPRosterCoreDataStorage.m
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ + (XMPPRosterCoreDataStorage *)sharedInstance

- (void)commonInit
{
XMPPLogTrace();
[super commonInit];

// This method is invoked by all public init methods of the superclass

rosterPopulationSet = [[NSMutableSet alloc] init];
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>_XCCurrentVersionName</key>
<string>XMPPRoom.xcdatamodel</string>
</dict>
</plist>
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<model name="" userDefinedModelVersionIdentifier="" type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="875" systemVersion="11C74" minimumToolsVersion="Automatic" macOSVersion="Automatic" iOSVersion="Automatic">
<entity name="XMPPRoomMessageCoreDataStorageObject" representedClassName="XMPPRoomMessageCoreDataStorageObject" syncable="YES">
<attribute name="body" optional="YES" attributeType="String" indexed="YES" syncable="YES"/>
<attribute name="fromMe" attributeType="Boolean" defaultValueString="NO" syncable="YES"/>
<attribute name="jid" optional="YES" transient="YES" syncable="YES"/>
<attribute name="jidStr" optional="YES" attributeType="String" syncable="YES"/>
<attribute name="localTimestamp" attributeType="Date" indexed="YES" syncable="YES"/>
<attribute name="message" optional="YES" transient="YES" syncable="YES"/>
<attribute name="messageStr" optional="YES" attributeType="String" syncable="YES"/>
<attribute name="nickname" optional="YES" attributeType="String" syncable="YES"/>
<attribute name="remoteTimestamp" optional="YES" attributeType="Date" indexed="YES" syncable="YES"/>
<attribute name="roomJID" optional="YES" transient="YES" syncable="YES"/>
<attribute name="roomJIDStr" attributeType="String" indexed="YES" syncable="YES"/>
<attribute name="streamBareJidStr" attributeType="String" indexed="YES" syncable="YES"/>
</entity>
<entity name="XMPPRoomOccupantCoreDataStorageObject" representedClassName="XMPPRoomOccupantCoreDataStorageObject" syncable="YES">
<attribute name="affiliation" optional="YES" attributeType="String" syncable="YES"/>
<attribute name="jid" optional="YES" transient="YES" syncable="YES"/>
<attribute name="jidStr" attributeType="String" indexed="YES" syncable="YES"/>
<attribute name="nickname" optional="YES" attributeType="String" indexed="YES" syncable="YES"/>
<attribute name="presence" optional="YES" transient="YES" syncable="YES"/>
<attribute name="presenceStr" optional="YES" attributeType="String" syncable="YES"/>
<attribute name="realJID" optional="YES" transient="YES" syncable="YES"/>
<attribute name="realJIDStr" optional="YES" attributeType="String" syncable="YES"/>
<attribute name="role" optional="YES" attributeType="String" syncable="YES"/>
<attribute name="roomJID" optional="YES" transient="YES" syncable="YES"/>
<attribute name="roomJIDStr" attributeType="String" indexed="YES" syncable="YES"/>
<attribute name="streamBareJidStr" attributeType="String" indexed="YES" syncable="YES"/>
</entity>
<elements>
<element name="XMPPRoomMessageCoreDataStorageObject" positionX="160" positionY="192" width="128" height="225"/>
<element name="XMPPRoomOccupantCoreDataStorageObject" positionX="160" positionY="192" width="128" height="225"/>
</elements>
</model>
84 changes: 84 additions & 0 deletions Extensions/XEP-0045/CoreDataStorage/XMPPRoomCoreDataStorage.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
#import <Foundation/Foundation.h>
#import <CoreData/CoreData.h>

#import "XMPP.h"
#import "XMPPRoom.h"
#import "XMPPRoomMessageCoreDataStorageObject.h"
#import "XMPPRoomOccupantCoreDataStorageObject.h"
#import "XMPPCoreDataStorage.h"


@interface XMPPRoomCoreDataStorage : XMPPCoreDataStorage <XMPPRoomStorage>

/**
* Convenience method to get an instance with the default database name.
*
* IMPORTANT:
* You are NOT required to use the sharedInstance.
*
* If your application makes extensive use of MUC, and you use a sharedInstance of this class,
* then all of your MUC rooms share the same database store. You might get better performance if you create
* multiple instances of this class instead (using different database filenames), as this way you can have
* concurrent writes to multiple databases.
**/
+ (XMPPRoomCoreDataStorage *)sharedInstance;


/* Inherited from XMPPCoreDataStorage
* Please see the XMPPCoreDataStorage header file for extensive documentation.
- (id)initWithDatabaseFilename:(NSString *)databaseFileName;
- (id)initWithInMemoryStore;
@property (readonly) NSString *databaseFileName;
@property (readwrite) NSUInteger saveThreshold;
@property (readonly) NSManagedObjectModel *managedObjectModel;
@property (readonly) NSPersistentStoreCoordinator *persistentStoreCoordinator;
*/

/**
* It is likely you don't want the message history to persist forever.
* Doing so would allow the database to grow infinitely large over time.
*
* The maxMessageAge property provides a way to specify how old a message can get
* before it should get deleted from the database.
*
* The deleteInterval specifies how often to sweep for old messages.
* Since deleting is an expensive operation (disk io) it is done on a fixed interval.
*
* You can optionally disable the maxMessageAge by setting it to zero (or a negative value).
* If you disable the maxMessageAge then old messages are not deleted.
*
* You can optionally disable the deleteInterval by setting it to zero (or a negative value).
*
* The default maxAge is 7 days.
* The default deleteInterval is 5 minutes.
**/
@property (assign, readwrite) NSTimeInterval maxMessageAge;
@property (assign, readwrite) NSTimeInterval deleteInterval;

/**
* You may optionally prevent old message deletion for particular rooms.
**/
- (void)pauseOldMessageDeletionForRoom:(XMPPJID *)roomJID;
- (void)resumeOldMessageDeletionForRoom:(XMPPJID *)roomJID;

/**
* Returns the timestamp of the most recent message stored in the database for the given room.
* This may be used when requesting the message history from the server,
* to prevent redownloading messages you already have.
*
* Keep in mind that the
**/
- (NSDate *)mostRecentMessageTimestampForRoom:(XMPPJID *)roomJID;
- (NSDate *)mostRecentMessageTimestampForRoom:(XMPPJID *)roomJID stream:(XMPPStream *)stream;

/**
* Returns the occupant for the given jid.
**/
- (XMPPRoomOccupantCoreDataStorageObject *)occupantForJID:(XMPPJID *)jid inContext:(NSManagedObjectContext *)moc;

@end
Loading

0 comments on commit 9bc1b16

Please sign in to comment.