Skip to content

Commit

Permalink
Merge pull request #37 from NicParmee-Kena/main
Browse files Browse the repository at this point in the history
WEB: Update `getLastMessages` to return newest messages first and count backwards
  • Loading branch information
asmodeoux authored Aug 16, 2024
2 parents d7577db + 3d7ffe8 commit 12536ab
Show file tree
Hide file tree
Showing 11 changed files with 36 additions and 19 deletions.
3 changes: 3 additions & 0 deletions flutter_twilio_conversations/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## 2.0.5+15
* WEB: Update `getLastMessages` to return newest messages first and count backwards

## 2.0.4+14
* INTERFACE: Added optional `webChannel` parameter to `registerForNotification` and `unregisterForNotification` methods
* WEB: Added implementation for `registerForNotification` and `unregisterForNotification` methods
Expand Down
6 changes: 3 additions & 3 deletions flutter_twilio_conversations/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: flutter_twilio_conversations
description: Integrate the Twilio Conversations SDK with your Flutter app using this Twilio Conversations Flutter plugin
version: 2.0.4+14
version: 2.0.5+15
repository: https://github.com/Diversido/flutter_twilio_conversations
issue_tracker: https://github.com/Diversido/flutter_twilio_conversations/issues

Expand All @@ -11,8 +11,8 @@ environment:
dependencies:
flutter:
sdk: flutter
flutter_twilio_conversations_platform_interface: ^2.0.4
flutter_twilio_conversations_web: ^2.0.4
flutter_twilio_conversations_platform_interface: ^2.0.5
flutter_twilio_conversations_web: ^2.0.5
enum_to_string: ^2.0.1
intl: ^0.19.0

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: flutter_twilio_conversations_platform_interface
description: A common platform interface for the flutter_twilio_conversations plugin.
version: 2.0.4
version: 2.0.5
repository: https://github.com/Diversido/flutter_twilio_conversations/tree/main/flutter_twilio_conversations_platform_interface
issue_tracker: https://github.com/Diversido/flutter_twilio_conversations/issues

Expand Down
3 changes: 3 additions & 0 deletions flutter_twilio_conversations_web/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## 2.0.5
* Update `getLastMessages` to return newest messages first and count backwards

## 2.0.4
* Added implementation for `registerForNotification` and `unregisterForNotification` methods
* Update signatures for `tokenExpired` and `tokenAboutToExpire` events
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class TwilioConversationsPlugin extends FlutterTwilioConversationsPlatform {

Future<dynamic> getChannel(String channelSidOrUniqueName) async {
return await ChannelsMethods()
.getChannel(channelSidOrUniqueName, _chatClient, this);
.getChannel(channelSidOrUniqueName, _chatClient!, this);
}

Future<dynamic> getPublicChannelsList() async {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ class TwilioConversationsClient extends EventEmitter {
external JSPaginator<TwilioConversationsChannel> getSubscribedConversations();
external dynamic getSubscribedUsers();

external dynamic getConversationBySid(String channelSid);
external TwilioConversationsChannel getConversationBySid(
String conversationSid,
);
external dynamic updateToken(String token);
external dynamic shutdown();
external dynamic getConversationByUniqueName(String UniqueName);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:dio/dio.dart';
import 'package:flutter_twilio_conversations_web/interop/classes/js_map.dart';
import 'package:flutter_twilio_conversations_web/interop/classes/unsent_message.dart';
import 'package:js/js.dart';

@JS('Twilio.Conversations.MessageBuilder')
Expand All @@ -10,5 +11,5 @@ class MessageBuilder {
external MessageBuilder setAttributes(JSMap attributes);
external MessageBuilder addMedia(FormData media);
external MessageBuilder withOptions(JSMap options);
external dynamic build();
external UnsentMessage build();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import 'package:js/js.dart';

@JS('Twilio.Conversations.UnsentMessage')
class UnsentMessage {
external factory UnsentMessage();

/// Send the prepared message to the conversation.
/// return index of the new message in the conversation.
external int send();
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,17 @@ import 'package:flutter_twilio_conversations_web/mapper.dart';
class ChannelsMethods {
Future<Map<String, dynamic>?> getChannel(
String channelSidOrUniqueName,
TwilioWebClient.TwilioConversationsClient? _chatClient,
TwilioWebClient.TwilioConversationsClient _chatClient,
TwilioConversationsPlugin pluginInstance) async {
try {
final channelBySid = await promiseToFuture<TwilioConversationsChannel>(
_chatClient?.getConversationBySid(channelSidOrUniqueName),
_chatClient.getConversationBySid(channelSidOrUniqueName),
);

if (channelBySid.sid == "") {
final channelByUniqueName =
await promiseToFuture<TwilioConversationsChannel>(
_chatClient?.getConversationBySid(channelSidOrUniqueName),
_chatClient.getConversationBySid(channelSidOrUniqueName),
);
return await Mapper.channelToMap(pluginInstance, channelByUniqueName);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,13 @@ class MessagesMethods {
Future<dynamic> getLastMessages(int count, String channelSid,
TwilioWebClient.TwilioConversationsClient? _chatClient) async {
try {
final channels =
await promiseToFuture<JSPaginator<TwilioConversationsChannel>>(
_chatClient!.getSubscribedConversations(),
);
final channel = await promiseToFuture<TwilioConversationsChannel>(
_chatClient!.getConversationBySid(channelSid));

final messages =
await promiseToFuture<JSPaginator<TwilioConversationsMessage>>(
channels.items
.firstWhere((element) => element.sid == channelSid)
.getMessages(50, 0, "forward"));
channel.getMessages(
count, channel.lastMessage?.index ?? 0, "backwards"));

final messageList = await Future.wait(
messages.items.map((message) => Mapper.messageToMap(message)));
Expand Down
4 changes: 2 additions & 2 deletions flutter_twilio_conversations_web/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: flutter_twilio_conversations_web
description: Web platform implementation of flutter_twilio_conversations_web
version: 2.0.4
version: 2.0.5
repository: https://github.com/Diversido/flutter_twilio_conversations/tree/main/flutter_twilio_conversations_web
issue_tracker: https://github.com/Diversido/flutter_twilio_conversations/issues

Expand All @@ -17,7 +17,7 @@ dependencies:
sdk: flutter
flutter_web_plugins:
sdk: flutter
flutter_twilio_conversations_platform_interface: ^2.0.4
flutter_twilio_conversations_platform_interface: ^2.0.5
meta: ^1.12.0
js: ^0.6.4
intl: ^0.19.0
Expand Down

0 comments on commit 12536ab

Please sign in to comment.