Skip to content

Commit

Permalink
v1.0.0 : add keyboard to fetched messages
Browse files Browse the repository at this point in the history
  • Loading branch information
vhunkalo committed Oct 24, 2024
1 parent d126b1b commit c3bc6bd
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 27 deletions.
42 changes: 21 additions & 21 deletions .idea/libraries/Dart_SDK.xml

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

40 changes: 34 additions & 6 deletions lib/src/backbone/builder/messages_list_message.dart
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
import 'package:webitel_portal_sdk/src/domain/entities/button.dart';
import 'package:webitel_portal_sdk/src/domain/entities/dialog_message_response.dart';
import 'package:webitel_portal_sdk/src/domain/entities/keyboard.dart';
import 'package:webitel_portal_sdk/src/domain/entities/media_file_response.dart';
import 'package:webitel_portal_sdk/src/domain/entities/peer.dart';
import 'package:webitel_portal_sdk/src/domain/entities/sender.dart';
import 'package:webitel_portal_sdk/src/generated/chat/messages/message.pb.dart';
import 'package:webitel_portal_sdk/src/generated/chat/messages/peer.pb.dart';
import 'package:webitel_portal_sdk/src/generated/chat/messages/message.pb.dart'
as pb;
import 'package:webitel_portal_sdk/src/generated/chat/messages/peer.pb.dart'
as pb;

final class MessagesListMessageBuilder {
late String _chatId;
late String _userId;
late List<Message> _messages;
late List<Peer> _peers;
late List<pb.Message> _messages;
late List<pb.Peer> _peers;

MessagesListMessageBuilder setChatId(String chatId) {
_chatId = chatId;
Expand All @@ -21,12 +25,12 @@ final class MessagesListMessageBuilder {
return this;
}

MessagesListMessageBuilder setMessages(List<Message> messages) {
MessagesListMessageBuilder setMessages(List<pb.Message> messages) {
_messages = messages;
return this;
}

MessagesListMessageBuilder setPeers(List<Peer> peers) {
MessagesListMessageBuilder setPeers(List<pb.Peer> peers) {
_peers = peers;
return this;
}
Expand All @@ -37,8 +41,32 @@ final class MessagesListMessageBuilder {
final messageType =
_peers[peerIndex].id == _userId ? Sender.user : Sender.operator;

// Process the keyboard if it's not null
Keyboard? keyboard;
if (message.keyboard.buttons.isNotEmpty) {
keyboard = Keyboard(
buttons: message.keyboard.buttons.map((buttonRow) {
return buttonRow.row
.map((button) {
// Check if the button has either a code or URL
if (button.code.isNotEmpty || button.url.isNotEmpty) {
return Button(
text: button.text,
code: button.code,
url: button.url,
);
}
return null;
})
.whereType<Button>()
.toList();
}).toList(),
);
}

return DialogMessageResponse(
input: message.keyboard.noInput,
keyboard: keyboard ?? Keyboard.initial(),
timestamp: message.date.toInt(),
messageId: message.id.toInt(),
chatId: _chatId,
Expand Down

0 comments on commit c3bc6bd

Please sign in to comment.