fix some power level checks, fixes #19
This commit is contained in:
parent
7d8b267986
commit
e310f0f60e
2 changed files with 136 additions and 115 deletions
|
|
@ -91,81 +91,92 @@ class ChatBox extends HookConsumerWidget {
|
|||
padding: EdgeInsets.symmetric(horizontal: 8),
|
||||
child: Row(
|
||||
spacing: 8,
|
||||
children: [
|
||||
EmojiPickerButton(
|
||||
context: context,
|
||||
onSelection: (_) => node?.requestFocus(),
|
||||
controller: controller.value,
|
||||
),
|
||||
PopupMenuButton(
|
||||
tooltip: "Add media",
|
||||
enabled: canSendMessages,
|
||||
itemBuilder: (context) => [
|
||||
PopupMenuItem(
|
||||
child: ListTile(
|
||||
title: Text("Camera"),
|
||||
leading: Icon(Icons.add_a_photo),
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: canSendMessages
|
||||
? [
|
||||
EmojiPickerButton(
|
||||
context: context,
|
||||
onSelection: (_) => node?.requestFocus(),
|
||||
controller: controller.value,
|
||||
),
|
||||
),
|
||||
PopupMenuItem(
|
||||
child: ListTile(
|
||||
title: Text("Gallery"),
|
||||
leading: Icon(Icons.add_photo_alternate),
|
||||
PopupMenuButton(
|
||||
tooltip: "Add media",
|
||||
enabled: canSendMessages,
|
||||
itemBuilder: (context) => [
|
||||
PopupMenuItem(
|
||||
child: ListTile(
|
||||
title: Text("Camera"),
|
||||
leading: Icon(Icons.add_a_photo),
|
||||
),
|
||||
),
|
||||
PopupMenuItem(
|
||||
child: ListTile(
|
||||
title: Text("Gallery"),
|
||||
leading: Icon(Icons.add_photo_alternate),
|
||||
),
|
||||
),
|
||||
PopupMenuItem(
|
||||
child: ListTile(
|
||||
title: Text("Files"),
|
||||
leading: Icon(Icons.attachment),
|
||||
),
|
||||
),
|
||||
],
|
||||
icon: Icon(Icons.add),
|
||||
),
|
||||
),
|
||||
PopupMenuItem(
|
||||
child: ListTile(
|
||||
title: Text("Files"),
|
||||
leading: Icon(Icons.attachment),
|
||||
Expanded(
|
||||
child: FlutterTagger(
|
||||
triggerStrategy: TriggerStrategy.eager,
|
||||
overlay: MentionOverlay(
|
||||
query: query.value,
|
||||
triggerCharacter: triggerCharacter.value,
|
||||
addTag: ({required id, required name}) {
|
||||
controller.value.addTag(id: id, name: name);
|
||||
node?.requestFocus();
|
||||
},
|
||||
),
|
||||
controller: controller.value,
|
||||
onSearch: (newQuery, newTriggerCharacter) {
|
||||
triggerCharacter.value = newTriggerCharacter;
|
||||
query.value = newQuery;
|
||||
},
|
||||
triggerCharacterAndStyles: {
|
||||
"@": style,
|
||||
"#": style,
|
||||
},
|
||||
builder: (context, key) => TextFormField(
|
||||
enabled: canSendMessages,
|
||||
maxLines: 12,
|
||||
minLines: 1,
|
||||
autofocus: true,
|
||||
decoration: InputDecoration(
|
||||
hintText: "Your message here...",
|
||||
border: InputBorder.none,
|
||||
),
|
||||
controller: controller.value,
|
||||
key: key,
|
||||
onFieldSubmitted: (_) => send(),
|
||||
// Don't defocus on submit
|
||||
onEditingComplete: () {},
|
||||
textInputAction: TextInputAction.done,
|
||||
focusNode: node,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
icon: Icon(Icons.add),
|
||||
),
|
||||
Expanded(
|
||||
child: FlutterTagger(
|
||||
triggerStrategy: TriggerStrategy.eager,
|
||||
overlay: MentionOverlay(
|
||||
query: query.value,
|
||||
triggerCharacter: triggerCharacter.value,
|
||||
addTag: ({required id, required name}) {
|
||||
controller.value.addTag(id: id, name: name);
|
||||
node?.requestFocus();
|
||||
},
|
||||
),
|
||||
controller: controller.value,
|
||||
onSearch: (newQuery, newTriggerCharacter) {
|
||||
triggerCharacter.value = newTriggerCharacter;
|
||||
query.value = newQuery;
|
||||
},
|
||||
triggerCharacterAndStyles: {"@": style, "#": style},
|
||||
builder: (context, key) => TextFormField(
|
||||
enabled: canSendMessages,
|
||||
maxLines: 12,
|
||||
minLines: 1,
|
||||
autofocus: true,
|
||||
decoration: InputDecoration(
|
||||
hintText: canSendMessages
|
||||
? "Your message here..."
|
||||
: "You don't have permission to send messages in this room...",
|
||||
border: InputBorder.none,
|
||||
IconButton(
|
||||
onPressed: !canSendMessages ? null : send,
|
||||
icon: Icon(Icons.send),
|
||||
tooltip: "Send message",
|
||||
),
|
||||
controller: controller.value,
|
||||
key: key,
|
||||
onFieldSubmitted: (_) => send(),
|
||||
// Don't defocus on submit
|
||||
onEditingComplete: () {},
|
||||
textInputAction: TextInputAction.done,
|
||||
focusNode: node,
|
||||
),
|
||||
),
|
||||
),
|
||||
IconButton(
|
||||
onPressed: !canSendMessages ? null : send,
|
||||
icon: Icon(Icons.send),
|
||||
tooltip: "Send message",
|
||||
),
|
||||
],
|
||||
]
|
||||
: [
|
||||
Padding(
|
||||
padding: EdgeInsetsGeometry.all(8),
|
||||
child: Text(
|
||||
"You don't have permission to send messages in this room...",
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
|
|
|
|||
|
|
@ -87,53 +87,63 @@ class RoomChat extends HookConsumerWidget {
|
|||
List<PopupMenuEntry> getMessageOptions(Message message) {
|
||||
final isSentByMe = message.authorId == userId;
|
||||
return [
|
||||
PopupMenuItem(
|
||||
child: Row(
|
||||
children: [
|
||||
...{
|
||||
...ref.watch(
|
||||
AccountDataController.provider.select(
|
||||
(value) => IList(
|
||||
value["m.recent_emoji"]?.content["recent_emoji"] ??
|
||||
[],
|
||||
).map((entry) => entry["emoji"]),
|
||||
if (ref.watch(
|
||||
PowerLevelController.provider(
|
||||
PowerLevelConfig(eventType: "m.reaction"),
|
||||
),
|
||||
))
|
||||
PopupMenuItem(
|
||||
child: Row(
|
||||
children: [
|
||||
...{
|
||||
...ref.watch(
|
||||
AccountDataController.provider.select(
|
||||
(value) => IList(
|
||||
value["m.recent_emoji"]?.content["recent_emoji"] ??
|
||||
[],
|
||||
).map((entry) => entry["emoji"]),
|
||||
),
|
||||
),
|
||||
"👍",
|
||||
"🤣",
|
||||
"😭",
|
||||
"🤔",
|
||||
}
|
||||
.toIList()
|
||||
.sublist(0, 4)
|
||||
.map(
|
||||
(emoji) => IconButton(
|
||||
onPressed: () async {
|
||||
Navigator.of(context).pop();
|
||||
await notifier
|
||||
.sendReaction(emoji, message)
|
||||
.onError(showError);
|
||||
},
|
||||
icon: Text(emoji),
|
||||
),
|
||||
),
|
||||
"👍",
|
||||
"🤣",
|
||||
"😭",
|
||||
"🤔",
|
||||
}
|
||||
.toIList()
|
||||
.sublist(0, 4)
|
||||
.map(
|
||||
(emoji) => IconButton(
|
||||
onPressed: () async {
|
||||
Navigator.of(context).pop();
|
||||
await notifier
|
||||
.sendReaction(emoji, message)
|
||||
.onError(showError);
|
||||
},
|
||||
icon: Text(emoji),
|
||||
),
|
||||
),
|
||||
EmojiPickerButton(
|
||||
context: context,
|
||||
onPressed: Navigator.of(context).pop,
|
||||
onSelection: (emoji) =>
|
||||
notifier.sendReaction(emoji, message).onError(showError),
|
||||
),
|
||||
],
|
||||
EmojiPickerButton(
|
||||
context: context,
|
||||
onPressed: Navigator.of(context).pop,
|
||||
onSelection: (emoji) =>
|
||||
notifier.sendReaction(emoji, message).onError(showError),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
if (ref.watch(
|
||||
PowerLevelController.provider(
|
||||
PowerLevelConfig(eventType: "m.room.message"),
|
||||
),
|
||||
))
|
||||
PopupMenuItem(
|
||||
onTap: () {
|
||||
relatedMessage.value = message;
|
||||
relationType.value = RelationType.reply;
|
||||
composerNode.requestFocus();
|
||||
},
|
||||
child: ListTile(leading: Icon(Icons.reply), title: Text("Reply")),
|
||||
),
|
||||
),
|
||||
PopupMenuItem(
|
||||
onTap: () {
|
||||
relatedMessage.value = message;
|
||||
relationType.value = RelationType.reply;
|
||||
composerNode.requestFocus();
|
||||
},
|
||||
child: ListTile(leading: Icon(Icons.reply), title: Text("Reply")),
|
||||
),
|
||||
if (message is TextMessage && isSentByMe)
|
||||
PopupMenuItem(
|
||||
onTap: () {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue