# Android SDK API Doc ## User ### ProfileService API #### 通过登录session获取ProfileService对象 ```kotlin val profileService = session.profileService() ``` #### 1、设置用户昵称 ```kotlin suspend fun setDisplayName(userId: String, newDisplayName: String) ``` #### 2、设置用户头像 ```kotlin suspend fun updateAvatar(userId: String, newAvatarUri: Uri, fileName: String) ``` #### 3、设置用户描述 ```kotlin suspend fun setProfileBio(userId: String, bio: String) ``` 入参: | Name | Type | Description | Required | | :------ | :----- | :---------- | :------- | | userId | string | 用户id | true | | bio | string | 用户描述 | true | 出参: 无 #### 3、获取用户Profile ```kotlin suspend fun getProfile(userId: String): JsonDict ``` 入参: | Name | Type | Description | Required | | :------ | :----- | :---------- | :------- | | userId | string | 用户id | true | 出参: | Type | Description | Required | | :----- | :---------- | :------- | | JsonDict | 用户profile键值对 | true | JsonDict类型字段: | Name | Type | Description | Required | | :------ | :----- | :---------- | :------- | | displayname | string | 用户名称 | true | | avatar_url | string | 用户头像 | true | | bio | string | 用户描述 | true | | wallet_address | string | 钱包地址 | true | ### AccountDataService API #### 通过登录session获取AccountDataService对象 ```kotlin val accountDataService = session.accountDataService() ``` #### 1、设置account data 该方法可设置用户相关的自定义数据,content为对应type下的全量数据。 ```kotlin suspend fun updateUserAccountData(type: String, content: Content) ``` 入参: | Name | Type | Description | Required | | :------ | :----- | :---------- | :------- | | type | string | 数据类型(可自定义) | true | | content | Content | key/value pairs | true | 出参:无 #### 2、获取account data ```kotlin fun getUserAccountDataEvent(type: String): UserAccountDataEvent? ``` 入参: | Name | Type | Description | Required | | :------ | :----- | :------------------------------------- | :------- | | type | string | 数据类型 | true | 出参 UserAccountDataEvent: | Name | Type | Description | Required | | :------ | :----- | :------------------------------------- | :------- | | type | string | 数据类型 | true | | content | Content | key/value pairs | true | ### UserService API #### 通过登录session获取UserService对象 ```kotlin val userService = session.userService() ``` #### 1、获取联系人列表 ```kotlin suspend fun getContacts(): List<ContactInfo> ``` 入参:无 出参: | Type | Description | Required | | :----- | :---------- | :------- | | List<ContactInfo> | 联系人信息列表 | true | ContactInfo类型字段: | Name | Type | Description | Required | | :------ | :----- | :---------- | :------- | | contactId | String | 联系人id | true | | displayName | String | 联系人名称 | false | | avatarUrl | String | 联系人头像 | false | | walletAddress | String | 钱包地址 | false | | tags | String array | 标签数组 | false | #### 2、添加联系人 ```kotlin suspend fun addContact(contactId: String, tags: List<String> = listOf()) ``` 入参: | Name | Type | Description | Required | | :------ | :----- | :---------- | :------- | | contactId | String | 联系人id | true | | tags | String array | 标签数组 | false | 出参:无 #### 2、删除联系人 ```kotlin suspend fun removeContact(contactId: String) ``` 入参: | Name | Type | Description | Required | | :------ | :----- | :---------- | :------- | | contactId | String | 联系人id | true | 出参:无 --- ## Room ### RoomService API #### 通过登录session获取AccountDataService对象 ```kotlin val roomService = session.roomService() ``` #### 1、创建私聊房间 ```kotlin suspend fun createDirectRoom(otherUserId: String): String ``` 入参: | Name | Type | Description | Required | | :------ | :----- | :---------- | :------- | | otherUserId | string | 对方用户id | true | 出参: | Type | Description | Required | | :----- | :---------- | :------- | | string | 房间id | true | #### 2、创建普通房间 ``` suspend fun createRoom(createRoomParams: CreateRoomParams): String ``` 入参: | Name | Type | Description | Required | | :------ | :----- | :---------- | :------- | | createRoomParams | CreateRoomParams | 房间参数 | true | CreateRoomParams类型: | Name | Type | Description | | :------ | :----- | :---------- | | name | string | 房间名称 | | topic | string | 房间主题 | | avatarUri | Uri | 房间头像 | | invitedUserIds | string array | 邀请用户id数组 | | preset | CreateRoomPreset | 房间预置状态 | CreateRoomPreset枚举类型: | Value | Description | | :------ | :----- | | PRESET_PUBLIC_CHAT | 公开房间,不需要邀请就可以join | | PRESET_PRIVATE_CHAT | 私有房间,需要邀请才能join | | PRESET_TRUSTED_PRIVATE_CHAT | 私有房间,用于单聊 | 出参: | Type | Description | Required | | :----- | :---------- | :------- | | string | 房间id | true | #### 3、加入房间 ```kotlin suspend fun joinRoom( roomId: String, reason: String? = null, viaServers: List<String> = emptyList() ) ``` 入参: | Name | Type | Description | Required | | :------ | :----- | :---------- | :------- | | roomId | string | 房间Id | true | | reason | string | 加入原因 | false | | viaServers | string array | server domain数组 | false | 出参: | Type | Description | Required | | :----- | :---------- | :------- | | string | 房间id | true | #### 4、离开房间 ```kotlin suspend fun leaveRoom(roomId: String, reason: String? = null) ``` 入参: | Name | Type | Description | Required | | :------ | :----- | :---------- | :------- | | roomId | string | 房间Id | true | | reason | string | 离开原因 | false | 出参: 无 #### 5、与钱包地址创建私聊房间 如果已经存在私聊房间,则返回已存在的房间id ```kotlin suspend fun createDmByWalletAddress(address: String): String ``` **Input parameter:** | Name | Type | Description | Required | | :------ | :----- | :---------- | :------- | | address | string | 对方用户钱包地址 | true | **Output parameter:** | Type | Description | Required | | :----- | :---------- | :------- | | string | 房间id | true | #### 6、删除房间 仅房间Owner有权限删除房间 ```kotlin suspend fun deleteRoom(roomId: String, reason: String? = null) ``` **Input parameter:** | Name | Type | Description | Required | | :------ | :----- | :---------- | :------- | | roomId | string | 房间Id | true | | reason | string | 删除原因 | false | **Output parameter:** None #### 7、隐藏房间 隐藏的房间不显示在房间列表,收到新消息后自动显示,取消隐藏 ```kotlin suspend fun hideRoom(roomId: String) ``` **Input parameter:** | Name | Type | Description | Required | | :------ | :----- | :---------- | :------- | | roomId | string | 房间Id | true | **Output parameter:** None #### 8、显示房间 重新显示隐藏的房间 ```kotlin suspend fun showRoom(roomId: String) ``` **Input parameter:** | Name | Type | Description | Required | | :------ | :----- | :---------- | :------- | | roomId | string | 房间Id | true | **Output parameter:** None #### 9、获取私聊房间 ```kotlin fun getExistingDirectRoomWithUser(otherUserId: String): String? ``` **Input parameter:** | Name | Type | Description | Required | | :------ | :----- | :---------- | :------- | | otherUserId | string | 私聊用户id|true| **Output parameter:** | Type | Description | Required | | :----- | :---------- | :------- | | string | 私聊房间id|false| ### RoomPushRuleService API #### 通过Room对象获取RoomPushRuleService对象 ```kotlin val roomPushRuleService = room.roomPushRuleService() ``` #### 1、设置房间通知状态 ```kotlin suspend fun setRoomNotificationState(roomNotificationState: RoomNotificationState) ``` 入参: | Name | Type | Description | Required | | :------ | :----- | :---------- | :------- | | roomNotificationState | RoomNotificationState | 通知状态 | true | RoomNotificationState枚举类型: | Value | Description | | :------ | :---------- | | ALL_MESSAGES | 全部消息触发通知 | | MENTIONS_ONLY | 被@时触发通知 | | MUTE | 没有通知 | 出参:无 #### 2、获取房间通知状态 ```kotlin fun getLiveRoomNotificationState(): LiveData<RoomNotificationState> ``` 入参:无 出参: | Type | Description | Required | | :----- | :---------- | :------- | | RoomNotificationState | 通知状态 | true | ### TagService API #### 通过Room对象获取TagService对象 ```kotlin val tagService = room.tagService() ``` #### 1、添加tag ```kotlin suspend fun addTag(tag: String, order: Double?) ``` 入参: | Name | Type | Description | Required | | :------ | :----- | :---------- | :------- | | tag | string | 标签名称 | true | | order | double | 0-1之间的数字,表示指定tag下的房间相对位置(越小越靠前) | false | 出参:无 #### 2、删除tag ```kotlin suspend fun deleteTag(tag: String) ``` 入参: | Name | Type | Description | Required | | :------ | :----- | :---------- | :------- | | tag | string | 标签名称 | true | 出参:无 ### SendService API #### 通过Room对象获取SendService对象 ```kotlin val sendService = room.sendService() ``` #### 1、发送文本 ```kotlin fun sendTextMessage( text: CharSequence, msgType: String = MessageType.MSGTYPE_TEXT, autoMarkdown: Boolean = false, additionalContent: Content? = null, ): Cancelable ``` 入参: | Name | Type | Description | Required | | :------ | :----- | :---------- | :------- | | text | string | 文本内容 | true | | msgType | string | 消息类型,默认text | true | | autoMarkdown | boolean | 是否支持markdown,默认false | true | | additionalContent | Content | additional content | false | 出参: | Type | Description | Required | | :----- | :---------- | :------- | | Cancelable | 可取消对象 | true | #### 2、发送图片 ```kotlin fun sendMedia( attachment: ContentAttachmentData, compressBeforeSending: Boolean, roomIds: Set<String>, rootThreadEventId: String? = null, relatesTo: RelationDefaultContent? = null, additionalContent: Content? = null, ): Cancelable ``` ### LocationSharingService API #### 通过Room对象获取LocationSharingService对象 ```kotlin val locationSharingService = room.locationSharingService() ``` #### 1、发送静态location消息 ```kotlin suspend fun sendStaticLocation(latitude: Double, longitude: Double, uncertainty: Double?, isUserLocation: Boolean): Cancelable ``` 入参: | Name | Type | Description | Required | | :------ | :----- | :---------- | :------- | | latitude | double | latitude of the location | true | | longitude | double | longitude of the location | true | | uncertainty | double | Accuracy of the location in meters | false | | isUserLocation | boolean | indicates whether the location data corresponds to the user location or not (pinned location) | true | 出参: | Type | Description | Required | | :----- | :---------- | :------- | | Cancelable | 可取消对象 | true | #### 1、发送动态location消息 ```kotlin suspend fun sendLiveLocation(beaconInfoEventId: String, latitude: Double, longitude: Double, uncertainty: Double?): Cancelable ``` 入参: | Name | Type | Description | Required | | :------ | :----- | :---------- | :------- | | beaconInfoEventId | string | event id of the initial beacon info state event | true | | latitude | double | latitude of the location | true | | longitude | double | longitude of the location | true | | uncertainty | double | Accuracy of the location in meters | false | 出参: | Type | Description | Required | | :----- | :---------- | :------- | | Cancelable | 可取消对象 | true |