-
Notifications
You must be signed in to change notification settings - Fork 14
Refactor/chat provider #714
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
c86d57d
7133aaa
facc796
4847aeb
ecd20c4
6b5b741
7b5f1db
84f6fbc
c8df2b1
4a94e83
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please, let's keep some of those important comments from the original file (chat_provider) especially the ones mentioning kinds or how to handle specific events. Maybe just copy them over. Thanks.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, I'm not a huge fan of comments in code but maybe those ones are in fact useful, I willl add them back 👍🏻 I thought that by adding the the description in the test cases of those specifications (should have, must have, etc) would be enough
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I added comments back but in the nostr tags builder service cause the more relevant comments were related to the tags.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Related to the comments about kinds, I think the kinds are already pretty clear by the variable names... const int _messageKind = 9;
const int _reactionKind = 7;
const int _deletionKind = 5; If I add the comments back they would say basically the same but in comment form, this are the comments related to kinds that I've found in master: If you really think is useful I can add them, but I think its just repetitive 😅 const int _messageKind = 9; // Nostr kind 9 = text message
const int _reactionKind = 7; // Nostr kind 7 = reaction
const int _deletionKind = 5; // Nostr kind 5 = deletion
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please let me know it adding this comments back c8df2b1 is ok or if you are missing more of them
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm okay with c8df2b1. Thanks. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,110 @@ | ||
| import 'package:whitenoise/domain/services/nostr_tag_builder_service.dart'; | ||
| import 'package:whitenoise/src/rust/api/messages.dart'; | ||
|
|
||
| const int _messageKind = 9; | ||
| const int _reactionKind = 7; | ||
| const int _deletionKind = 5; | ||
|
|
||
| class MessageSenderService { | ||
| final NostrTagBuilderService _tagBuilder; | ||
| final Future<MessageWithTokens> Function({ | ||
| required String pubkey, | ||
| required String groupId, | ||
| required String message, | ||
| required int kind, | ||
| List<Tag>? tags, | ||
| }) | ||
| _sendMessageToGroupFn; | ||
|
|
||
| MessageSenderService({ | ||
| NostrTagBuilderService? tagBuilder, | ||
| Future<MessageWithTokens> Function({ | ||
| required String pubkey, | ||
| required String groupId, | ||
| required String message, | ||
| required int kind, | ||
| List<Tag>? tags, | ||
| })? | ||
| sendMessageToGroupFn, | ||
| }) : _tagBuilder = tagBuilder ?? NostrTagBuilderService(), | ||
| _sendMessageToGroupFn = sendMessageToGroupFn ?? sendMessageToGroup; | ||
|
|
||
| Future<MessageWithTokens> sendMessage({ | ||
| required String pubkey, | ||
| required String groupId, | ||
| required String content, | ||
| List<Tag>? tags, | ||
| }) async { | ||
| return _sendMessageToGroupFn( | ||
| pubkey: pubkey, | ||
| groupId: groupId, | ||
| message: content, | ||
| kind: _messageKind, | ||
| tags: tags, | ||
| ); | ||
| } | ||
|
|
||
| Future<MessageWithTokens> sendReaction({ | ||
| required String pubkey, | ||
| required String groupId, | ||
| required String messageId, | ||
| required String messagePubkey, | ||
| required int messageKind, | ||
| required String emoji, | ||
| }) async { | ||
| final tags = await _tagBuilder.buildReactionTags( | ||
| messageId: messageId, | ||
| messagePubkey: messagePubkey, | ||
| messageKind: messageKind, | ||
| ); | ||
|
|
||
| return _sendMessageToGroupFn( | ||
| pubkey: pubkey, | ||
| groupId: groupId, | ||
| message: emoji, | ||
| kind: _reactionKind, | ||
| tags: tags, | ||
| ); | ||
| } | ||
|
|
||
| Future<MessageWithTokens> sendReply({ | ||
| required String pubkey, | ||
| required String groupId, | ||
| required String replyToMessageId, | ||
| required String content, | ||
| }) async { | ||
| final tags = await _tagBuilder.buildReplyTags( | ||
| replyToMessageId: replyToMessageId, | ||
| ); | ||
|
|
||
| return _sendMessageToGroupFn( | ||
| pubkey: pubkey, | ||
| groupId: groupId, | ||
| message: content, | ||
| kind: _messageKind, | ||
| tags: tags, | ||
| ); | ||
| } | ||
|
|
||
| Future<MessageWithTokens> sendDeletion({ | ||
| required String pubkey, | ||
| required String groupId, | ||
| required String messageId, | ||
| required String messagePubkey, | ||
| required int messageKind, | ||
| }) async { | ||
| final tags = await _tagBuilder.buildDeletionTags( | ||
| messageId: messageId, | ||
| messagePubkey: messagePubkey, | ||
| messageKind: messageKind, | ||
| ); | ||
|
|
||
| return _sendMessageToGroupFn( | ||
| pubkey: pubkey, | ||
| groupId: groupId, | ||
| message: '', | ||
| kind: _deletionKind, | ||
| tags: tags, | ||
| ); | ||
| } | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.