Alerts, do not disturb and reports
This page covers the user's alert settings (do not disturb, quiet hours, notification previews), conversation mutes, alerts for new messages while the app is in the foreground, and reports.
There are two different objects:
im.push: the user's alert settings stored on the server and synced across all their devices. Works even withoutim-push.DRPush.of(im): the system notification controller on this Android device; see Offline push.
| You want to | See |
|---|---|
| Do not disturb, quiet hours, what notifications show | Global settings |
| Mute one chat or group | Conversation mutes |
| Alert for new messages while the app is in the foreground | Foreground message alerts |
| Report a user, message, group or chat room | Reports |
Global settings
import com.deeprespond.im.*
import kotlin.time.Duration.Companion.hours
im.push.updateSettings(
dnd = DndChange.On(8.hours),
quietHours = QuietHoursChange.Set(QuietHours("22:00", "08:00", "Asia/Shanghai")),
preview = PreviewChange.Set(PushPreview.SENDER_ONLY),
)DndChange.Offturns off do not disturb,QuietHoursChange.Offremoves quiet hours, andPreviewChange.UseDefaultreturns to the app's default preview mode. Anullargument leaves that setting unchanged.- Quiet hours use an IANA time zone, and
startandendareHH:mm; when the range crosses midnight,endis earlier thanstart. settingsis aStateFlow. InPushSettings, do not disturb is split into whether it's on (dndEnabled) and when it ends (dndUntil); the preview mode has the user's own choicepreviewand the mode in effecteffectivePreview, with valuesFULL(show content),SENDER_ONLY(show only the sender) andNONE(show neither).
Conversation mutes
import com.deeprespond.im.*
im.push.mute(MuteTarget.single("bob"), MuteMode.NONE)
im.push.mute(MuteTarget.group(groupId), MuteMode.MENTION_ONLY)
im.push.unmute(MuteTarget.single("bob"))MuteMode.NONEmeans "no alerts", not "unmute";MENTION_ONLYalerts only when the user is mentioned, for groups only.durationsets when the mute ends; without it, the mute lasts indefinitely.getMutereads the local setting, andunmuteremoves the mute.
Foreground message alerts
The MessageReceived event carries notify (whether this message should alert) and alert; you can also decide with im.push.shouldNotify(message). While the app is in the foreground, only show an in-app alert for messages that should alert, to avoid duplicating system push. The decision takes read state, whether the screen is being viewed, conversation mutes and global settings into account, so don't alert just because an event arrived.
Mutes don't delete messages: messages and unread counts keep syncing as usual. Turning off a notification channel doesn't sign the user out of IM either.
Reports
import com.deeprespond.im.*
val result = im.reports.submit(
ReportTarget.User("bob"),
ReportReason.ABUSE,
description = "持续发送侮辱消息",
)
val mine = im.reports.mine()
println(result)
println(mine.items.size)ReportTargethas five forms:Message(messageId),User(username, evidenceMessageIds?),Group(groupId, evidenceMessageIds?),Chatroom(roomId),ChatroomMessage(roomId, messageId).- User and group reports can attach up to 5 evidence messages: for a user report they must be sent by that user, for a group report they must be from that group, and recalled messages aren't allowed.
- Reasons (
ReportReason):AD(ads),FRAUD,PORN(sexual content),POLITICS(political content),TERRORISM(violence or terrorism),ABUSE,ILLEGAL,INFRINGEMENT,MINOR(involves minors),OTHER. - Whether reporting is allowed, and how often, is decided by the app's runtime configuration.
For full parameters, see PushModule and ReportsModule.
