use of org.matrix.androidsdk.rest.model.group.Group in project matrix-android-sdk by matrix-org.
the class MXFileStore method loadGroups.
/**
* Load groups from the filesystem.
*
* @return true if the operation succeeds.
*/
private boolean loadGroups() {
boolean succeed = true;
try {
// extract the messages list
List<String> filenames = listFiles(mStoreGroupsFolderFile.list());
long start = System.currentTimeMillis();
for (String filename : filenames) {
File groupFile = new File(mStoreGroupsFolderFile, filename);
if (groupFile.exists()) {
Object groupAsVoid = readObject("loadGroups " + filename, groupFile);
if ((null != groupAsVoid) && (groupAsVoid instanceof Group)) {
Group group = (Group) groupAsVoid;
mGroups.put(group.getGroupId(), group);
} else {
succeed = false;
break;
}
}
}
if (succeed) {
long delta = (System.currentTimeMillis() - start);
Log.d(LOG_TAG, "loadGroups : " + filenames.size() + " groups in " + delta + " ms");
mStoreStats.put("loadGroups", delta);
}
} catch (Exception e) {
succeed = false;
Log.e(LOG_TAG, "loadGroups failed : " + e.getMessage());
}
return succeed;
}
use of org.matrix.androidsdk.rest.model.group.Group in project matrix-android-sdk by matrix-org.
the class GroupsManager method getInvitedGroups.
/**
* @return the groups list in which the user is invited
*/
public Collection<Group> getInvitedGroups() {
List<Group> invitedGroups = new ArrayList<>();
Collection<Group> groups = getGroups();
for (Group group : groups) {
if (group.isInvited()) {
invitedGroups.add(group);
}
}
return invitedGroups;
}
use of org.matrix.androidsdk.rest.model.group.Group in project matrix-android-sdk by matrix-org.
the class GroupsManager method createGroup.
/**
* Create a group.
*
* @param localPart the local part
* @param groupName the group human name
* @param callback the asynchronous callback
*/
public void createGroup(String localPart, String groupName, final ApiCallback<String> callback) {
final CreateGroupParams params = new CreateGroupParams();
params.localpart = localPart;
params.profile = new GroupProfile();
params.profile.name = groupName;
getGroupsRestClient().createGroup(params, new ApiCallback<String>() {
@Override
public void onSuccess(String groupId) {
Group group = getGroup(groupId);
// if the group does not exist, create it
if (null == group) {
group = new Group(groupId);
group.setGroupProfile(params.profile);
group.setMembership(RoomMember.MEMBERSHIP_JOIN);
mStore.storeGroup(group);
}
callback.onSuccess(groupId);
}
@Override
public void onNetworkError(Exception e) {
callback.onNetworkError(e);
}
@Override
public void onMatrixError(MatrixError e) {
callback.onMatrixError(e);
}
@Override
public void onUnexpectedError(Exception e) {
callback.onUnexpectedError(e);
}
});
}
use of org.matrix.androidsdk.rest.model.group.Group in project matrix-android-sdk by matrix-org.
the class MXFileStore method saveGroups.
/**
* Flush groups list
*/
private void saveGroups() {
// some updated rooms ?
if ((mGroupsToCommit.size() > 0) && (null != mFileStoreHandler)) {
// get the list
final HashSet<String> fGroupIds = mGroupsToCommit;
mGroupsToCommit = new HashSet<>();
try {
Runnable r = new Runnable() {
@Override
public void run() {
mFileStoreHandler.post(new Runnable() {
public void run() {
if (!isKilled()) {
Log.d(LOG_TAG, "saveGroups " + fGroupIds.size() + " groups");
long start = System.currentTimeMillis();
for (String groupId : fGroupIds) {
Group group;
synchronized (mGroups) {
group = mGroups.get(groupId);
}
if (null != group) {
writeObject("saveGroup " + groupId, new File(mStoreGroupsFolderFile, groupId), group);
} else {
File tokenFile = new File(mStoreGroupsFolderFile, groupId);
if (tokenFile.exists()) {
tokenFile.delete();
}
}
}
Log.d(LOG_TAG, "saveGroups done in " + (System.currentTimeMillis() - start) + " ms");
}
}
});
}
};
Thread t = new Thread(r);
t.start();
} catch (OutOfMemoryError oom) {
Log.e(LOG_TAG, "saveGroups : failed" + oom.getMessage());
}
}
}
use of org.matrix.androidsdk.rest.model.group.Group in project matrix-android-sdk by matrix-org.
the class GroupsManager method onNewGroupInvitation.
/**
* Create a group from an invitation.
*
* @param groupId the group id
* @param profile the profile
* @param inviter the inviter
* @param notify true to notify
*/
public void onNewGroupInvitation(final String groupId, final GroupSyncProfile profile, final String inviter, final boolean notify) {
Group group = getGroup(groupId);
// it should always be null
if (null == group) {
group = new Group(groupId);
}
GroupSummary summary = new GroupSummary();
summary.profile = new GroupProfile();
if (null != profile) {
summary.profile.name = profile.name;
summary.profile.avatarUrl = profile.avatarUrl;
}
group.setGroupSummary(summary);
group.setInviter(inviter);
group.setMembership(RoomMember.MEMBERSHIP_INVITE);
mStore.storeGroup(group);
if (notify) {
mUIHandler.post(new Runnable() {
@Override
public void run() {
mDataHandler.onNewGroupInvitation(groupId);
}
});
}
}
Aggregations