Search in sources :

Example 1 with GroupSummary

use of org.matrix.androidsdk.rest.model.group.GroupSummary 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);
            }
        });
    }
}
Also used : Group(org.matrix.androidsdk.rest.model.group.Group) GroupSummary(org.matrix.androidsdk.rest.model.group.GroupSummary) GroupProfile(org.matrix.androidsdk.rest.model.group.GroupProfile)

Example 2 with GroupSummary

use of org.matrix.androidsdk.rest.model.group.GroupSummary in project matrix-android-sdk by matrix-org.

the class GroupsManager method onJoinGroup.

/**
 * Manage the group joining.
 *
 * @param groupId the group id
 * @param notify  true to notify
 */
public void onJoinGroup(final String groupId, final boolean notify) {
    Group group = getGroup(groupId);
    if (null == group) {
        group = new Group(groupId);
    }
    if (TextUtils.equals(RoomMember.MEMBERSHIP_JOIN, group.getMembership())) {
        Log.d(LOG_TAG, "## onJoinGroup() : the group " + groupId + " was already joined");
        return;
    }
    group.setMembership(RoomMember.MEMBERSHIP_JOIN);
    mStore.storeGroup(group);
    // try retrieve  the summary
    mGroupsRestClient.getGroupSummary(groupId, new ApiCallback<GroupSummary>() {

        /**
         * Common method
         */
        private void onDone() {
            if (notify) {
                mDataHandler.onJoinGroup(groupId);
            }
        }

        @Override
        public void onSuccess(GroupSummary groupSummary) {
            Group group = getGroup(groupId);
            if (null != group) {
                group.setGroupSummary(groupSummary);
                mStore.flushGroup(group);
                onDone();
                if (null != mPendingJoinGroups.get(groupId)) {
                    mPendingJoinGroups.get(groupId).onSuccess(null);
                    mPendingJoinGroups.remove(groupId);
                }
            }
        }

        @Override
        public void onNetworkError(Exception e) {
            Log.e(LOG_TAG, "## onJoinGroup() : failed " + e.getMessage());
            onDone();
            if (null != mPendingJoinGroups.get(groupId)) {
                mPendingJoinGroups.get(groupId).onNetworkError(e);
                mPendingJoinGroups.remove(groupId);
            }
        }

        @Override
        public void onMatrixError(MatrixError e) {
            Log.e(LOG_TAG, "## onMatrixError() : failed " + e.getMessage());
            onDone();
            if (null != mPendingJoinGroups.get(groupId)) {
                mPendingJoinGroups.get(groupId).onMatrixError(e);
                mPendingJoinGroups.remove(groupId);
            }
        }

        @Override
        public void onUnexpectedError(Exception e) {
            Log.e(LOG_TAG, "## onUnexpectedError() : failed " + e.getMessage());
            onDone();
            if (null != mPendingJoinGroups.get(groupId)) {
                mPendingJoinGroups.get(groupId).onUnexpectedError(e);
                mPendingJoinGroups.remove(groupId);
            }
        }
    });
}
Also used : Group(org.matrix.androidsdk.rest.model.group.Group) GroupSummary(org.matrix.androidsdk.rest.model.group.GroupSummary) MatrixError(org.matrix.androidsdk.rest.model.MatrixError)

Aggregations

Group (org.matrix.androidsdk.rest.model.group.Group)2 GroupSummary (org.matrix.androidsdk.rest.model.group.GroupSummary)2 MatrixError (org.matrix.androidsdk.rest.model.MatrixError)1 GroupProfile (org.matrix.androidsdk.rest.model.group.GroupProfile)1