Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 6 additions & 19 deletions src/main/java/io/github/hikingc/matrixsdk/api/Room.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import io.github.hikingc.matrixsdk.api.rooms.*;
import io.github.hikingc.matrixsdk.api.rooms.models.ResolvedAlias;
import io.github.hikingc.matrixsdk.api.rooms.models.RoomSummary;
import io.github.hikingc.matrixsdk.api.rooms.queries.CreationRoomType;
import io.github.hikingc.matrixsdk.api.rooms.queries.JoinRoomRequest;
import io.github.hikingc.matrixsdk.api.rooms.queries.VisibilityRoomType;
import io.github.hikingc.matrixsdk.exceptions.MatrixIOException;
Expand All @@ -21,25 +20,13 @@
/// @see <a href="https://spec.matrix.org/v1.19/client-server-api/#rooms">Matrix Client-Server API
/// Specification for Rooms</a>
public interface Room {
/// Creates a room, this method will let the homeserver choose the default configuration for most
/// tasks and the following parameters will overwrite them if set to a non-null value.
///
/// @param isFederated if the room will be federated
/// @param name the room's name, if any.
/// @param aliasName the room's canonical alias, if any
/// @param topic the room's topic, if any.
/// @param type the [CreationRoomType]
/// @param isVisible if the room will be visible to the public
/// Creates a room based on the received [InitialRoomConfiguration].
///
/// @param configuration of the room.
/// @return the created room’s ID.
/// @throws MatrixIOException when the payload cannot be processed
/// @throws MatrixNetworkException when the response status is not successful
String create(
boolean isFederated,
String name,
String aliasName,
String topic,
CreationRoomType type,
boolean isVisible);
String create(InitialRoomConfiguration configuration);

/// Requests the server to resolve a room alias if not possible, the server will use the
/// federation API.
Expand Down Expand Up @@ -184,7 +171,7 @@ String joinByRoomIdOrAliasIfAllowed(
/// @param since a pagination token from a previous request, allowing you to get the next or
/// previous batch of rooms. The direction of pagination is specified by which token is
/// supplied.
/// @return a [PublicRoomDirectory] containing [PublishedRoomsChunk] records of the published
/// @return a [PublicRoomDirectory] containing [io.github.hikingc.matrixsdk.api.rooms.models.PublishedRoomsChunk] records of the published
/// rooms on the server.
/// @throws MatrixIOException when the payload cannot be processed.
/// @throws NullPointerException when the roomId is null.
Expand All @@ -195,7 +182,7 @@ String joinByRoomIdOrAliasIfAllowed(
/// Lists a server’s published room directory.
///
/// @param request a [PublicRoomRequest] with additional filters for the request.
/// @return a [PublicRoomDirectory] containing [PublishedRoomsChunk] records of the published
/// @return a [PublicRoomDirectory] containing [io.github.hikingc.matrixsdk.api.rooms.models.PublishedRoomsChunk] records of the published
/// rooms on the server.
PublicRoomDirectory getPublishedRoomDirectory(PublicRoomRequest request);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public record RoomPowerLevels(
Integer redact,
Integer stateDefault,
Map<String, Integer> users,
Integer users_default)
Integer usersDefault)
implements StateEventContent {

public record Notifications(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
package io.github.hikingc.matrixsdk.api.rooms;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import io.github.hikingc.matrixsdk.api.events.content.RoomPowerLevels;
import io.github.hikingc.matrixsdk.api.rooms.queries.CreationRoomType;
import io.github.hikingc.matrixsdk.api.rooms.queries.VisibilityRoomType;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import org.jspecify.annotations.NonNull;

/// The configuration data that a server will follow to configure the room.
///
/// @param creationContent extra keys, currently only `m.federate` is mapped.
/// @param initialState a [List] of state events to set in the new room. This allows the user to
/// override the default state events set in the new room.
/// @param invite a [List] of UserIDs to invite to the room. The server will be responsible for
/// handling these invitations,
/// @param invite3pid a [List] of objects representing third-party IDs to invite into the room.
/// @param isDirect Sets a flag on `m.room.member` events. See the
/// [spec](https://spec.matrix.org/v1.18/client-server-api/#direct-messaging) for more
/// information,
/// @param name of the room. Overwrites `initialState`.
/// @param powerLevelContentOverride the power level content to override in the default power level
/// event. This object is applied on top of the generated `m.room.power_levels` event content
/// prior to it being sent to the room. Defaults to overriding nothing.
/// @param preset Convenience parameter for setting various default state events based on a
/// [CreationRoomType] value. If unset, it will use `visibility`.
/// @param roomAliasName if included, a room alias will be created and mapped to the newly created
/// room. The alias will belong on the same homeserver which created the room.
/// @param roomVersion to set for the room. If not provided, the homeserver is to use its configured
/// default. If provided, the homeserver will return a 400 error with the errcode
/// M_UNSUPPORTED_ROOM_VERSION if it does not support the room version.
/// @param topic of the room topic. Overwrites `initialState`.
/// @param visibility of the room. Defaults to private if unset.
@JsonInclude(JsonInclude.Include.NON_ABSENT)
public record InitialRoomConfiguration(
CreationContent creationContent,
List<StateEvent> initialState,
List<String> invite,
@JsonProperty("invite_3pid") List<Invite3pid> invite3pid,
Boolean isDirect,
String name,
RoomPowerLevels powerLevelContentOverride,
CreationRoomType preset,
String roomAliasName,
String roomVersion,
String topic,
VisibilityRoomType visibility) {
/// Extra keys, such as m.federate, to be added to the content of the m.room.create event.
///
/// @param isFederated If the room will be federated.
public record CreationContent(@JsonProperty("m.federate") Boolean isFederated) {}

/// A list of state events to set in the new room. This allows the user to override the default
/// state events set in the new room.
///
/// Takes precedence over events set by preset, but gets overridden by name and topic keys.
///
/// @param content The content of the event.
/// @param stateKey The state\_key of the state event. Defaults to an empty string.
/// @param type The type of event to send.
public record StateEvent(Object content, String stateKey, String type) {}

/// Represents third-party IDs to invite to the room.
///
/// @param address
/// @param idAccessToken
/// @param idServer
/// @param medium
public record Invite3pid(String address, String idAccessToken, String idServer, String medium) {}

/// Creates a federated, empty and private room with the name and topic desired.
///
/// @param name of the room.
/// @param topic of the room.
/// @return a private room preset, ready to be used.
@NonNull
public static InitialRoomConfiguration createRoomWithSaneDefaults(String name, String topic) {
Objects.requireNonNull(name, "Room name must not be null");
Objects.requireNonNull(topic, "Topic must not be null");
return new InitialRoomConfiguration(
new CreationContent(true),
Collections.emptyList(),
Collections.emptyList(),
Collections.emptyList(),
false,
name,
null,
CreationRoomType.PRIVATE_CHAT,
null,
null,
topic,
VisibilityRoomType.PRIVATE);
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,27 +1,18 @@
package io.github.hikingc.matrixsdk.api.rooms.queries;

import com.fasterxml.jackson.annotation.JsonProperty;

/// The room type keys used to tell the client what available preset should the server create the
/// room with.
public enum CreationRoomType {

/// Recommended to use this to configure when you want to make 1 to 1 conversations.
PRIVATE_CHAT("private_chat"),
/// Same as PRIVATE\_CHAT except all invitees are given the same power level as the room creator.
TRUSTED_PRIVATE_CHAT("trusted_private_chat"),
@JsonProperty("private_chat")
PRIVATE_CHAT,
/// Same as [#PRIVATE_CHAT] except all invitees are given the same power level as the room creator.
@JsonProperty("trusted_private_chat")
TRUSTED_PRIVATE_CHAT,
/// For public access, unlike the other types, choosing this will forbid guest access.
PUBLIC_CHAT("public_chat");

private final String value;

CreationRoomType(String value) {
this.value = value;
}

/// Returns the string room type value ('private\_chat', 'public\_chat' or
/// 'trusted\_private\_chat') expected by the Matrix homeserver.
///
/// @return the parameter string
public String getValue() {
return this.value;
}
@JsonProperty("public_chat")
PUBLIC_CHAT
}
Original file line number Diff line number Diff line change
@@ -1,22 +1,13 @@
package io.github.hikingc.matrixsdk.api.rooms.queries;

/// The new visibility type for the room.
import com.fasterxml.jackson.annotation.JsonProperty;

/// The visibility type for a room.
public enum VisibilityRoomType {
/// Set the visibility private.
PRIVATE("private"),
@JsonProperty("private")
PRIVATE,
/// Set the visibility to public.
PUBLIC("public");

private final String value;

VisibilityRoomType(String value) {
this.value = value;
}

/// Returns the parameter value ('private' or 'public') expected by Matrix servers.
///
/// @return the parameter visibility value.
public String getValue() {
return this.value;
}
@JsonProperty("public")
PUBLIC
}
Loading
Loading