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());
}
}
}
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));
}
}
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));
}
}
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));
}
}
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));
}
}
Aggregations