Skip to content

Commit e857775

Browse files
author
Franco Bugnano
committed
Started implementing ConversationList
1 parent dc6f6d9 commit e857775

File tree

6 files changed

+381
-102
lines changed

6 files changed

+381
-102
lines changed

lib/src/chatbox.dart

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,19 @@ typedef SendMessageHandler = void Function(SendMessageEvent event);
2121
typedef TranslationToggledHandler = void Function(TranslationToggledEvent event);
2222

2323
class SendMessageEvent {
24-
ConversationData conversation;
25-
User me;
26-
SentMessage message;
24+
final ConversationData conversation;
25+
final UserData me;
26+
final SentMessage message;
2727

2828
SendMessageEvent.fromJson(Map<String, dynamic> json)
2929
: conversation = ConversationData.fromJson(json['conversation']),
30-
me = User.fromJson(json['me']),
30+
me = UserData.fromJson(json['me']),
3131
message = SentMessage.fromJson(json['message']);
3232
}
3333

3434
class TranslationToggledEvent {
35-
ConversationData conversation;
36-
bool isEnabled;
35+
final ConversationData conversation;
36+
final bool isEnabled;
3737

3838
TranslationToggledEvent.fromJson(Map<String, dynamic> json)
3939
: conversation = ConversationData.fromJson(json['conversation']),
@@ -92,7 +92,10 @@ class ChatBoxState extends State<ChatBox> {
9292
WebViewController? _webViewController;
9393

9494
/// List of JavaScript statements that haven't been executed.
95-
final List<String> _pending = [];
95+
final _pending = <String>[];
96+
97+
// A counter to ensure that IDs are unique
98+
int _idCounter = 0;
9699

97100
/// A mapping of user ids to the variable name of the respective JavaScript
98101
/// Talk.User object.
@@ -102,9 +105,6 @@ class ChatBoxState extends State<ChatBox> {
102105
/// Talk.ConversationBuilder object.
103106
final _conversations = <String, String>{};
104107

105-
// A counter to ensure that IDs are unique
106-
int _idCounter = 0;
107-
108108
/// Encapsulates the message entry field tied to the currently selected conversation.
109109
// TODO: messageField still needs to be refactored
110110
//late MessageField messageField;
@@ -273,6 +273,7 @@ class ChatBoxState extends State<ChatBox> {
273273
return _users[user.id]!;
274274
}
275275

276+
/// For internal use only. Implementation detail that may change anytime.
276277
String getConversationVariableName(Conversation conversation) {
277278
if (_conversations[conversation.id] == null) {
278279
// STEP 1: Generate unique variable name

lib/src/chatoptions.dart

Lines changed: 3 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,8 @@ extension TranslateConversationsValue on TranslateConversations {
134134
}
135135
}
136136

137-
/// This class represents the various configuration options used to finetune the
138-
/// behaviour of UI elements.
139-
abstract class _ChatOptions {
137+
/// Options to configure the behaviour of the [ChatBox] UI.
138+
class ChatBoxOptions {
140139
/// Controls what text appears in the chat subtitle, right below the chat title.
141140
///
142141
/// Defaults to [ChatMode.subject].
@@ -181,7 +180,7 @@ abstract class _ChatOptions {
181180
/// This option specifies which conversation Ids should be translated in this UI.
182181
List<String>? conversationIdsToTranslate;
183182

184-
_ChatOptions({this.chatSubtitleMode,
183+
ChatBoxOptions({this.chatSubtitleMode,
185184
this.chatTitleMode,
186185
this.dir,
187186
this.messageField,
@@ -272,29 +271,3 @@ abstract class _ChatOptions {
272271
}
273272
}
274273

275-
/// Options to configure the behaviour of the [ChatBox] UI.
276-
class ChatBoxOptions extends _ChatOptions{
277-
ChatBoxOptions({chatSubtitleMode,
278-
chatTitleMode,
279-
dir,
280-
messageField,
281-
showChatHeader,
282-
showTranslationToggle,
283-
theme,
284-
translateConversations,
285-
conversationsToTranslate,
286-
conversationIdsToTranslate,
287-
})
288-
: super(chatSubtitleMode: chatSubtitleMode,
289-
chatTitleMode: chatTitleMode,
290-
dir: dir,
291-
messageField: messageField,
292-
showChatHeader: showChatHeader,
293-
showTranslationToggle: showTranslationToggle,
294-
theme: theme,
295-
translateConversations: translateConversations,
296-
conversationsToTranslate: conversationsToTranslate,
297-
conversationIdsToTranslate: conversationIdsToTranslate,
298-
);
299-
}
300-

lib/src/conversation.dart

Lines changed: 22 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class Participant {
3333
/// You can use this object to set up or modify a conversation before showing it.
3434
/// Note: any changes you make here will not be sent to TalkJS immediately.
3535
/// Instead, instantiate a TalkJS UI using methods such as [Session.createInbox].
36-
class Conversation {
36+
class _BaseConversation {
3737
/// The unique conversation identifier.
3838
String id;
3939

@@ -51,19 +51,27 @@ class Conversation {
5151
/// The conversation subject which will be displayed in the chat header.
5252
String? subject;
5353

54-
// The participants for this conversation
55-
List<Participant> participants;
56-
57-
/// Don't use the ConversationBuilder constructor directly.
58-
// use session.getOrCreateConversation instead.
59-
Conversation({
54+
_BaseConversation({
6055
required this.id,
6156
this.custom,
6257
this.welcomeMessages,
6358
this.photoUrl,
6459
this.subject,
65-
this.participants = const <Participant>[],
6660
});
61+
}
62+
63+
class Conversation extends _BaseConversation {
64+
// The participants for this conversation
65+
List<Participant> participants;
66+
67+
Conversation({
68+
required String id,
69+
Map<String, String?>? custom,
70+
List<String>? welcomeMessages,
71+
String? photoUrl,
72+
String? subject,
73+
this.participants = const <Participant>[],
74+
}) : super(id: id, custom: custom, welcomeMessages: welcomeMessages, photoUrl: photoUrl, subject: subject);
6775

6876
/* TODO: conversation.sendMessage is to be rewritten so that it works when we don't show the WebView
6977
/// Sends a text message in a given conversation.
@@ -122,31 +130,12 @@ class Conversation {
122130
*/
123131
}
124132

125-
class ConversationData {
126-
/// The unique conversation identifier.
127-
String id;
128-
129-
/// Custom metadata for this conversation
130-
Map<String, String?>? custom;
131-
132-
/// Messages sent at the beginning of a chat.
133-
///
134-
/// The messages will appear as system messages.
135-
List<String>? welcomeMessages;
136-
137-
/// The URL to a photo which will be shown as the photo for the conversation.
138-
String? photoUrl;
139-
140-
/// The conversation subject which will be displayed in the chat header.
141-
String? subject;
142-
133+
class ConversationData extends _BaseConversation {
143134
ConversationData.fromJson(Map<String, dynamic> json)
144-
: id = json['id'],
145-
custom = json['custom'] != null ? Map<String, String?>.from(json['custom']) : null,
146-
welcomeMessages = json['welcomeMessages'] != null ? List<String>.from(json['welcomeMessages']) : null,
147-
photoUrl = json['photoUrl'],
148-
subject = json['subject'];
149-
135+
: super(id: json['id'],
136+
custom: json['custom'] != null ? Map<String, String?>.from(json['custom']) : null,
137+
welcomeMessages: json['welcomeMessages'] != null ? List<String>.from(json['welcomeMessages']) : null,
138+
photoUrl: json['photoUrl'],
139+
subject: json['subject']);
150140
}
151141

152-

0 commit comments

Comments
 (0)