forked from Nexus/nexus
don't send empty messages if only a subprofile trigger is sent
This commit is contained in:
parent
9f2d223809
commit
7435ecd5f0
1 changed files with 46 additions and 18 deletions
|
|
@ -436,18 +436,30 @@ class const Composer(
|
|||
attachment != null && attachment.$2 == null) {
|
||||
return;
|
||||
}
|
||||
if (ref.read(SettingsController.provider).value case Settings(
|
||||
subprofiles: true,
|
||||
latchSubprofiles: true,
|
||||
)) {
|
||||
final subprofiles = ref.read(SubprofilesController.provider(roomId));
|
||||
if (subprofiles.triggeredBy(controller.text) case final triggered?
|
||||
when triggered.id != subprofiles.current?.id) {
|
||||
ref
|
||||
.read(AccountDataController.provider.notifier)
|
||||
.setRoomProfile(roomId, triggered.id)
|
||||
.onError(showError);
|
||||
}
|
||||
final subprofiles = ref.read(SubprofilesController.provider(roomId));
|
||||
final match = subprofiles.triggerMatch(controller.text);
|
||||
void switchSubprofile(String id) {
|
||||
if (id == subprofiles.current?.id) return;
|
||||
ref
|
||||
.read(AccountDataController.provider.notifier)
|
||||
.setRoomProfile(roomId, id)
|
||||
.onError(showError);
|
||||
}
|
||||
|
||||
// A trigger on its own would send an empty message, so it switches to
|
||||
// its subprofile instead
|
||||
if (match != null && match.body.trim().isEmpty && attachment == null) {
|
||||
switchSubprofile(match.profile.id);
|
||||
controller.text = "";
|
||||
return;
|
||||
}
|
||||
|
||||
// gomuks sends this message as the triggered subprofile itself, this
|
||||
// keeps sending as it afterwards
|
||||
if (ref.read(SettingsController.provider).value
|
||||
case Settings(subprofiles: true, latchSubprofiles: true)
|
||||
when match != null) {
|
||||
switchSubprofile(match.profile.id);
|
||||
}
|
||||
|
||||
onSend(
|
||||
|
|
|
|||
Loading…
Reference in a new issue