Skip to content

Commit

Permalink
refactor: Improve query pin message must check related message exist (M…
Browse files Browse the repository at this point in the history
  • Loading branch information
YeungKC authored May 29, 2023
1 parent 05a57a2 commit 0654eb6
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 10 deletions.
8 changes: 2 additions & 6 deletions lib/db/dao/pin_message_dao.dart
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,8 @@ class PinMessageDao extends DatabaseAccessor<MixinDatabase>
);
}

Selectable<String?> getPinMessageIds(String conversationId) =>
(selectOnly(db.pinMessages)
..addColumns([db.pinMessages.messageId])
..where(db.pinMessages.conversationId.equals(conversationId))
..orderBy([OrderingTerm.desc(db.pinMessages.createdAt)]))
.map((row) => row.read(db.pinMessages.messageId));
Selectable<String?> pinMessageIds(String conversationId) =>
db.pinMessageIds(conversationId);

Selectable<PinMessageItemResult> pinMessageItem(
String conversationId, String messageId) =>
Expand Down
15 changes: 14 additions & 1 deletion lib/db/mixin_database.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 7 additions & 1 deletion lib/db/moor/dao/pin_message.drift
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,16 @@ SELECT
message.content AS content,
sender.full_name AS userFullName
FROM messages message
INNER JOIN pin_messages pinMessage ON message.message_id = pinMessage.message_id
INNER JOIN users sender ON message.user_id = sender.user_id
WHERE message.conversation_id = :conversationId AND message.category = 'MESSAGE_PIN' AND message.quote_message_id = :messageId
ORDER BY message.created_at DESC
LIMIT 1;

pinMessageIds:
SELECT pinMessage.message_id FROM pin_messages pinMessage
INNER JOIN messages message ON message.message_id = pinMessage.message_id
WHERE pinMessage.conversation_id = :conversationId;

countPinMessages:
SELECT COUNT(1) FROM pin_messages;
SELECT COUNT(1) FROM pin_messages;
2 changes: 1 addition & 1 deletion lib/ui/home/hook/pin_message.dart
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ PinMessageState usePinMessageState() {
() {
if (conversationId == null) return Stream.value([]);
return context.database.pinMessageDao
.getPinMessageIds(conversationId)
.pinMessageIds(conversationId)
.watchWithStream(
eventStreams: [
DataBaseEventBus.instance.watchPinMessageStream(
Expand Down
2 changes: 1 addition & 1 deletion lib/ui/setting/proxy_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ class _ProxyTypeWidget extends StatelessWidget {
@override
Widget build(BuildContext context) => Material(
color: context.theme.listSelected,
borderRadius: BorderRadius.circular(8),
borderRadius: const BorderRadius.all(Radius.circular(8)),
child: ListTileTheme(
data: ListTileThemeData(
dense: true,
Expand Down

0 comments on commit 0654eb6

Please sign in to comment.