Groups
im.groups handles "My groups", public groups, creating groups, managing members, join applications and invitations, the group blocklist and join links. Roles are represented by GroupRole; whether an operation is allowed is checked by the server.
| You want to | See |
|---|---|
| Show my groups, create a group | List and create |
| Edit the group profile, show and manage members | Group profile and members |
| Apply to join, handle invitations and approvals | Applications and invitations |
| Add people with a link, group blocklist | Join links and blocklist |
List and create
kotlin
import com.deeprespond.im.*
val group = im.groups.create(
name = "项目讨论",
type = GroupType.PRIVATE,
members = listOf("bob"),
)
val info = im.groups.get(group.groupId, refresh = true)list()/listFlow()subscribe to my groups.getreads one group and returnsnullif it isn't visible;lookupgets several group profiles at once;publicGroupspages through public groups by name prefixnamePrefix.createcan also set the avatar, description, announcement,attributes,memberInvite,joinModeand an invitation message for initial members.- Each initial member's outcome is in
CreateGroupResult.results; checkcodeitem by item. A successful create doesn't mean every initial member joined.
Group profile and members
kotlin
im.groups.update(groupId, announcement = "周五下午开会")
val members = im.groups.members(groupId)
try {
members.loadMore()
println(members.snapshot.value.items.size)
} finally {
members.close()
}members()/membersFlow()return the member list, filterable byroleandmuted;lookupMemberslooks up members by username.updateMemberchanges a member's group nickname and attributes.- When several people may edit the group profile, pass the
versionyou read toupdate. If someone else changed it, the call fails withversion_conflict; re-read and decide again.
| Operation | Method |
|---|---|
| Invite, remove members | invite, removeMembers, returning a result per user |
| Set roles | setRole(groupId, username, role) |
| Mute, unmute | mute(groupId, username, duration?), unmute |
| Mute everyone | setMuteAll(groupId, on) |
| Transfer ownership | transferOwner(groupId, username) |
| Online count | onlineCount(groupId) |
| Leave, dissolve | leave(groupId), dismiss(groupId) |
Applications and invitations
kotlin
val status = im.groups.applications.apply(groupId, message = "希望加入")
val invitations = im.groups.invitations.received()
println(status)
println(invitations.items.size)applyreturnsjoined(joined the group),pending(awaiting approval) oralready_member.applications.mine()lists the user's applications andwithdrawwithdraws one.invitations.accept/declineaccept or decline received invitations.- The owner and admins use
requests.listto see the group's applications and invitations, and handle them withapprove,declineandwithdrawInvite, passing the request kindGroupRequestKindand the other user's username. - Whether the user must confirm invitations is managed with
groups.settings.get()/set();nulluses the app default. - Whether applying joins directly or needs approval depends on the group type,
joinModeandmemberInvite. Show the result from the return value; don't infer it from the buttons in your UI.
After invite returns, check each result: a non-empty code means inviting that user failed. On success status is joined (in the group), invited (waiting for the user to confirm), pending_review (waiting for admin approval) or already_member. The call not throwing doesn't mean everyone joined.
The invitation cooldown (group_invite_cooldown_enabled) is set in the console's group runtime policies:
- Off by default: after someone leaves or declines, you can invite them again right away.
- When on: for 24 hours after someone leaves or declines, this group can't invite them again; the result's
codeisrate_limitedwithreasondeclined_cooldownindetails. - The cooldown only limits invitations. Being added by the server, applying and join links aren't affected; requirements like the user's confirmation and admin approval still apply.
- Separately, after a join application is declined, the applicant can't apply again for 24 hours. This always applies.
Join links and blocklist
- The owner and admins manage join links with
joinLink.get(),create(expiresIn?)andrevoke(). The person opening a link callspreviewto see the group first, thenjoin. - Manage the group blocklist with
blacklist.list/add/remove;addcan take areason. - Duration parameters such as
expiresInand a mute'sdurationare KotlinDurations.
For group files, see Files; for sending group messages, see Messages. For full parameters, see GroupsModule.
