Room

Join a room

client.joinRoomById(id);

Input Parameters:

Name
Type
Description
Required

roomId

String

Room_id string

true

Create a room

 Future<String> createRoom(
      {Map<String, Object?>? creationContent,
      List<StateEvent>? initialState,
      List<String>? invite,
      List<Invite3pid>? invite3pid,
      bool? isDirect,
      String? name,
      Map<String, Object?>? powerLevelContentOverride,
      CreateRoomPreset? preset,
      String? roomAliasName,
      String? roomVersion,
      String? topic,
      Visibility? visibility})

Create DM

// Start a new direct chat
final roomId = await createRoom(
      invite: [mxid],
      isDirect: true,
      preset: preset,
      initialState: initialState,
      powerLevelContentOverride: powerLevelContentOverride,
 );

Invite user to a room

Future<void> invite(String userID)

Input Parameters:

Name
Type
Description
Required

userID

String

user ID

true

Get room information

builder: (context, snapshot) {
   final timeline = snapshot.data;
 }

Future<SyncUpdate> sync(
      {String? filter,
      String? since,
      bool? fullState,
      PresenceType? setPresence,
      int? timeout})

Input Parameters:

Name
Type
Description
Required

filter

String

filter string

false

since

String

since string

false

fullState

bool

fullState bool

false

setPresence

PresenceType

setPresence PresenceType

false

timeout

String

timeout int

false

Leave a room

Future<void> leave() async

Modify room name

Future<String> setName(String newName)

Input Parameters:

Name
Type
Description
Required

newName

String

room name

true

Modify room type

 var response = await client.setRoomStateWithKey(
      roomId,
      eventType,
      stateKey,
      body,
    );

Input parameters:

Name
Type
Description
Required

roomid

string

Roomid string

true

eventType

string

The type of event to send

true

stateKey

string

The state_key for the state to send.

false

body

map

JSON data

true

Example

 var response = await client.setRoomStateWithKey(
      room.id,
      "m.room.join_rules",
      '',
      jsonData,
    );

JSON structure

The JSON data has the following structure:

{
    "join_rule": "token.access",
    "join_params": {
        "logic": "ANY",
        "Require": [
            {
                "required token": {
                    "name": "USD Coin",
                    "symbol": "USDC",
                    "logo": "https://static.alchemyapi.io/images/assets/3408.png",
                    "address": "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48"
                },
                "requiredAmount": 10
            },
            {
                "required token": {
                    "name": "0N1 Power",
                    "symbol": "0N1",
                    "logo": "https://lh3.googleusercontent.com/7gOej3SUvqALR-qkqL_ApAt97SpUKQOZQe88p8jPjeiDDcqITesbAdsLcWlsIg8oh7SRrTpUPfPlm12lb4xDahgP2h32pQQYCsuOM_s=s120",
                    "Address": "0x3bf2922f4520a8ba0c2efc3d2a1539678dad5e9d",
                    "type": "ERC721"
                },
                "Amount required": 1
            }
        ]
    }
}

Explanation of Fields

  • join_rule: This field specifies the rule for joining a room.

    • token.access: This rule allows only users with the required tokens to enter the room.

    • token.message: With this rule, all users are permitted to enter the room and view messages. However, only users who meet certain requirements can send messages within the room.

  • join_params: This section contains additional parameters for controlling room access.

    • logic: It specifies whether users need to meet just one of the specified requirements (ANY) or all of them (ALL) in order to gain access to the room.

    • Require: An array of objects specifying the required tokens and their associated criteria for access. You can configure at most five requirements.

      • required token: Details of the token that is required for access. This includes:

        • name: The name of the token.

        • symbol: The symbol of the token.

        • logo: URL to the logo image of the token.

        • address: The contract address of the token.

        • requiredAmount: Specifies the minimum required amount of the token for access.

Last updated