Core Service - Methods connected with the current user
// Push the user's profile data to the server
ChatSDK.core().pushUser().subscribe(() -> {
}, throwable -> {
});
// Get the current user
User user = ChatSDK.core().currentUser();
// Get a user and update their proifle from the server
ChatSDK.core().getUserForEntityID("User Entity ID").subscribe(otherUser -> {
}, throwable -> {
});
// Push the user's profile data to the server
BChatSDK.core().pushUser()?.thenOnMain({ success in
return success
}, { error in
return error
})
// Get the current user
let user: PUser = BChatSDK.currentUser();
// Get a user and update their proifle from the server
let otherUser: PUser = BChatSDK.core().user(forEntityID: "User Entity ID")
// Push the user's profile data to the server
[BChatSDK.core pushUser].thenOnMain(^id(id success) {
return nil;
}, ^id(NSError * error) {
return nil;
});
// Get the current user
id<PUser> user = BChatSDK.currentUser;
// Get a user and update their proifle from the server
id<PUser> otherUser = [BChatSDK.core userForEntityID:@"User Entity ID"];
Auth Service - Methods for Authentication
// Login
ChatSDK.auth().authenticate(AccountDetails.username("Username", "Password")).subscribe(() -> {
}, throwable -> {
});
// Check if user is logged in
boolean isLoggedIn = ChatSDK.auth().isAuthenticated();
// Log out
ChatSDK.auth().logout().subscribe();
// Login
BChatSDK.auth().authenticate(BAccountDetails.username("username", password: "password"))?.thenOnMain({ success in
return success
}, { error in
return error
})
// Check if user is logged in
let isLoggedIn = BChatSDK.auth().isAuthenticated()
// Log out
BChatSDK.auth().logout()
// Login
[BChatSDK.auth authenticate:[BAccountDetails username:@"username" password:@"password"]].thenOnMain(^id(id success) {
return nil;
}, ^id(NSError * error) {
return nil;
});
// Check if user is logged in
bool isLoggedIn = BChatSDK.auth.isAuthenticated;
// Log out
[BChatSDK.auth logout];
Thread Service - Methods related to Conversation Threads
// Create thread
User otherUser = ChatSDK.core().getUserNowForEntityID("EntityID");
ChatSDK.thread().createThread("Name", Collections.singletonList(otherUser)).subscribe(thread1 -> {
// Send a message
ChatSDK.thread().sendMessageWithText("Hi", thread1).subscribe();
});
// Get a list of public threads
List<Thread> threads = ChatSDK.thread().getThreads(ThreadType.Private1to1);
// Create thread
BChatSDK.thread().createThread(withUsers: [otherUser], name: "Name", threadCreated: { error, thread in
// Send a message
BChatSDK.thread().sendMessage(withText: "Hi", withThreadEntityID: thread?.entityID())
})
// Get a list of public threads
let threads = BChatSDK.thread().threads(with: bThreadType1to1)
// Create thread
[BChatSDK.thread createThreadWithUsers:@[otherUser] name:@"Name" threadCreated:^(NSError * error, id<PThread> thread) {
// Send a message
[BChatSDK.thread sendMessageWithText:@"Hi" withThreadEntityID:thread.entityID];
}];
// Get a list of public threads
NSArray * threads = [BChatSDK.thread threadsWithType:bThreadType1to1];
Messaging Server Notifications
Since messaging happens in realtime, we also need to get notifications from the server. This happens through several mechanisms. For more details see:
The UI service is used to inject views into the app. It also defines which tabs are displayed and much more. For example, you can override Activites, Fragments, and ViewControllers by subclassing them and injecting them using the UI service.
// Override an activity
ChatSDK.ui().setChatActivity(CustomChatActivity.class);
// Override a fragment
ChatSDK.ui().setProfileFragmentProvider(user -> {
ProfileFragment fragment = new AProfileFragment();
fragment.setUser(user);
return fragment;
});
// Override the chat view controller
BChatSDK.ui().setChatViewController({ thread -> UIViewController in
return AChatViewController.init(thread: thread)
})
// Override the private threads tab
BChatSDK.ui().setPrivateThreadsViewController(APrivateThreadsViewController.init(nibName: nil, bundle: nil))
The Chat SDK has a powerful local database that is automatically synchronized with the messaging server. It can be accessed using the database service.
StorageManager storageManager = ChatSDK.db();
let storageAdapter: PStorageAdapter = BChatSDK.db()
id<PStorageAdapter> storageAdapter = BChatSDK.db;
The database service can be used to fetch, create, and delete entities. For example:
// Create entity
User user = ChatSDK.db().createEntity(User.class);
// Fetch an entity with a given ID
Thread thread = ChatSDK.db().fetchEntityWithEntityID("threadEntityID", Thread.class);
// Fetch or create an entity with a given ID
User otherUser = ChatSDK.db().fetchOrCreateEntityWithEntityID(User.class, "userEntityID'");
// Create entity
if let user: PUser = BChatSDK.db().createEntity(bUserEntity) as? PUser {
}
// Fetch an entity with a given ID
if let thread: PThread? = BChatSDK.db().fetchEntity(withID: "threadEntityID", withType: bThreadEntity) as? PThread {
}
// Fetch or create an entity with a given ID
if let otherUser: PUser = BChatSDK.db().fetchOrCreateEntity(withID: "userEntityID", withType: bUserEntity) as? PUser {
}
// Create entity
id<PUser> user = [BChatSDK.db createEntity:bUserEntity];
// Fetch an entity with a given ID
id<PThread> thread = [BChatSDK.db fetchEntityWithID:@"threadEntityID" withType:bThreadEntity];
// Fetch or create an entity with a given ID
id<PUser> otherUser = [BChatSDK.db fetchOrCreateEntityWithID:@"userEntityID" withType:bUserEntity];
Each entity then has many methods that can be used. For example:
Note: Creating an entity locally doesn't automatically add it to the server or populate the data from the server. To do that you have to use the network adapter service.