Search in sources :

Example 11 with RoomState

use of org.matrix.androidsdk.data.RoomState in project matrix-android-sdk by matrix-org.

the class MatrixMessageListFragment method onSearchResponse.

/**
 * Manage the search response.
 *
 * @param searchResponse         the search response
 * @param onSearchResultListener the search result listener
 */
protected void onSearchResponse(final SearchResponse searchResponse, final OnSearchResultListener onSearchResultListener) {
    List<SearchResult> searchResults = searchResponse.searchCategories.roomEvents.results;
    ArrayList<MessageRow> messageRows = new ArrayList<>(searchResults.size());
    for (SearchResult searchResult : searchResults) {
        RoomState roomState = null;
        if (null != mRoom) {
            roomState = mRoom.getState();
        }
        if (null == roomState) {
            Room room = mSession.getDataHandler().getStore().getRoom(searchResult.result.roomId);
            if (null != room) {
                roomState = room.getState();
            }
        }
        boolean isValidMessage = false;
        if ((null != searchResult.result) && (null != searchResult.result.getContent())) {
            JsonObject object = searchResult.result.getContentAsJsonObject();
            if (null != object) {
                isValidMessage = (0 != object.entrySet().size());
            }
        }
        if (isValidMessage) {
            messageRows.add(new MessageRow(searchResult.result, roomState));
        }
    }
    Collections.reverse(messageRows);
    mAdapter.clear();
    mAdapter.addAll(messageRows);
    mNextBatch = searchResponse.searchCategories.roomEvents.nextBatch;
    if (null != onSearchResultListener) {
        try {
            onSearchResultListener.onSearchSucceed(messageRows.size());
        } catch (Exception e) {
            Log.e(LOG_TAG, "onSearchResponse failed with " + e.getMessage());
        }
    }
}
Also used : MessageRow(org.matrix.androidsdk.adapters.MessageRow) ArrayList(java.util.ArrayList) JsonObject(com.google.gson.JsonObject) SearchResult(org.matrix.androidsdk.rest.model.search.SearchResult) Room(org.matrix.androidsdk.data.Room) RoomState(org.matrix.androidsdk.data.RoomState)

Example 12 with RoomState

use of org.matrix.androidsdk.data.RoomState in project matrix-android-sdk by matrix-org.

the class RoomsRestClient method updateGuestAccess.

/**
 * Update the guest access rule of the room.
 * To deny guest access to the room, aGuestAccessRule must be set to {@link RoomState#GUEST_ACCESS_FORBIDDEN}
 *
 * @param aRoomId          the room id
 * @param aGuestAccessRule the guest access rule: {@link RoomState#GUEST_ACCESS_CAN_JOIN} or {@link RoomState#GUEST_ACCESS_FORBIDDEN}
 * @param callback         the async callback response
 */
public void updateGuestAccess(final String aRoomId, final String aGuestAccessRule, final ApiCallback<Void> callback) {
    final String description = "updateGuestAccess : roomId=" + aRoomId + " rule=" + aGuestAccessRule;
    // build RoomState as input parameter
    RoomState roomStateParam = new RoomState();
    roomStateParam.guest_access = aGuestAccessRule;
    try {
        mApi.setGuestAccess(aRoomId, roomStateParam, new RestAdapterCallback<Void>(description, mUnsentEventsManager, callback, new RestAdapterCallback.RequestRetryCallBack() {

            @Override
            public void onRetry() {
                updateGuestAccess(aRoomId, aGuestAccessRule, callback);
            }
        }));
    } catch (Throwable t) {
        callback.onUnexpectedError(new Exception(t));
    }
}
Also used : RoomState(org.matrix.androidsdk.data.RoomState)

Example 13 with RoomState

use of org.matrix.androidsdk.data.RoomState in project matrix-android-sdk by matrix-org.

the class RoomsRestClient method updateTopic.

/**
 * Update the room topic.
 *
 * @param roomId   the room id
 * @param topic    the room topic
 * @param callback the async callback
 */
public void updateTopic(final String roomId, final String topic, final ApiCallback<Void> callback) {
    final String description = "updateTopic : roomId " + roomId + " topic " + topic;
    RoomState roomState = new RoomState();
    roomState.topic = topic;
    try {
        mApi.setRoomTopic(roomId, roomState, new RestAdapterCallback<Void>(description, mUnsentEventsManager, callback, new RestAdapterCallback.RequestRetryCallBack() {

            @Override
            public void onRetry() {
                updateTopic(roomId, topic, callback);
            }
        }));
    } catch (Throwable t) {
        callback.onUnexpectedError(new Exception(t));
    }
}
Also used : RoomState(org.matrix.androidsdk.data.RoomState)

Example 14 with RoomState

use of org.matrix.androidsdk.data.RoomState in project matrix-android-sdk by matrix-org.

the class RoomsRestClient method updateRoomName.

/**
 * Update the room name.
 *
 * @param roomId   the room id
 * @param name     the room name
 * @param callback the async callback
 */
public void updateRoomName(final String roomId, final String name, final ApiCallback<Void> callback) {
    final String description = "updateName : roomId " + roomId + " name " + name;
    RoomState roomState = new RoomState();
    roomState.name = name;
    try {
        mApi.setRoomName(roomId, roomState, new RestAdapterCallback<Void>(description, mUnsentEventsManager, callback, new RestAdapterCallback.RequestRetryCallBack() {

            @Override
            public void onRetry() {
                updateRoomName(roomId, name, callback);
            }
        }));
    } catch (Throwable t) {
        callback.onUnexpectedError(new Exception(t));
    }
}
Also used : RoomState(org.matrix.androidsdk.data.RoomState)

Example 15 with RoomState

use of org.matrix.androidsdk.data.RoomState in project matrix-android-sdk by matrix-org.

the class RoomsRestClient method updateCanonicalAlias.

/**
 * Update the room name.
 *
 * @param roomId         the room id
 * @param canonicalAlias the canonical alias
 * @param callback       the async callback
 */
public void updateCanonicalAlias(final String roomId, final String canonicalAlias, final ApiCallback<Void> callback) {
    final String description = "updateCanonicalAlias : roomId " + roomId + " canonicalAlias " + canonicalAlias;
    RoomState roomState = new RoomState();
    roomState.alias = canonicalAlias;
    try {
        mApi.setCanonicalAlias(roomId, roomState, new RestAdapterCallback<Void>(description, mUnsentEventsManager, callback, new RestAdapterCallback.RequestRetryCallBack() {

            @Override
            public void onRetry() {
                updateCanonicalAlias(roomId, canonicalAlias, callback);
            }
        }));
    } catch (Throwable t) {
        callback.onUnexpectedError(new Exception(t));
    }
}
Also used : RoomState(org.matrix.androidsdk.data.RoomState)

Aggregations

RoomState (org.matrix.androidsdk.data.RoomState)30 Room (org.matrix.androidsdk.data.Room)22 Event (org.matrix.androidsdk.rest.model.Event)21 JsonObject (com.google.gson.JsonObject)20 HashMap (java.util.HashMap)20 CountDownLatch (java.util.concurrent.CountDownLatch)20 MatrixError (org.matrix.androidsdk.rest.model.MatrixError)20 Test (org.junit.Test)18 MXEventListener (org.matrix.androidsdk.listeners.MXEventListener)16 ArrayList (java.util.ArrayList)13 Context (android.content.Context)12 EventTimeline (org.matrix.androidsdk.data.EventTimeline)9 Credentials (org.matrix.androidsdk.rest.model.login.Credentials)4 MXDeviceInfo (org.matrix.androidsdk.crypto.data.MXDeviceInfo)3 Uri (android.net.Uri)2 MXCryptoError (org.matrix.androidsdk.crypto.MXCryptoError)2 MXUsersDevicesMap (org.matrix.androidsdk.crypto.data.MXUsersDevicesMap)2 IMXStore (org.matrix.androidsdk.data.store.IMXStore)2 MXFileStore (org.matrix.androidsdk.data.store.MXFileStore)2 ApiCallback (org.matrix.androidsdk.rest.callback.ApiCallback)2