locality_social_cloud_chat 1.4.0
locality_social_cloud_chat: ^1.4.0 copied to clipboard
A chat based on Locality Social Cloud that supported End-to-End encrypted Chats and GroupChats and Chat Message state management.
example/lib/main.dart
import 'package:locality_core/locality_core.dart';
import 'package:locality_social_cloud_chat/locality_social_cloud_chat.dart';
import 'package:locality_social_cloud_chat/model/dto/simple_message.dart';
import 'package:locality_social_cloud_chat/model/framework/chat_message.dart';
import 'package:locality_social_cloud_chat/model/framework/chat_message_factory.dart';
import 'package:locality_social_cloud_chat/model/topic/key_exchange_lobby.dart';
import 'package:locality_social_cloud_chat/model/topic/messaging_subscriptions.dart';
import 'package:locality_social_cloud_chat/model/topic/messaging_topic.dart';
/// A concrete implementation of [ChatMessageFactory] that instantiates [SimpleMessage] from payloads.
class TestChatMessageFactory implements ChatMessageFactory {
@override
ChatMessage createFrom(String id, Map<String, dynamic> payload) {
payload['id'] = id;
return SimpleMessage.fromMap(payload);
}
}
void main() async {
LocalitySocialCloud cloud = await LocalitySocialCloud.startTest(
userCredentials: UserCredentials("userId", "password"),
developerCredentials: DeveloperCredentials(
realmId: "ptr2",
realmSecret: "h3w1uzXhmHc4JvZi6ZE6bGXlPPISH/t26Pb6vtGzffE="),
isRegistration: true);
AuthenticatedSessionUser authenticatedSessionUser = cloud.getLoggedInUser();
LocalitySocialCloudChat localitySocialCloudChat;
KeyExchangeLobby keyExchangeLobby =
await LocalitySocialCloudChat.getKeyExchangeLobby("hello");
if (!keyExchangeLobby.containsMe(authenticatedSessionUser)) {
keyExchangeLobby.announcePresence(authenticatedSessionUser);
}
// We want to message this user
PublicUser? klaus = keyExchangeLobby.getUserById("KLAUS");
if (klaus != null) {
// Klaus announced his presence, so we can message him
MessagingTopic messagingTopic = await LocalitySocialCloudChat.getUserChat(
authenticatedSessionUser, klaus, TestChatMessageFactory());
messagingTopic.sendMessage(SimpleMessage(
user: authenticatedSessionUser, message: "HELLO BONJOUR KLAUS"));
}
MessagingSubscriptions messagingSubscriptions =
await LocalitySocialCloudChat.getUserMessageTopicSubscriptions(
user: authenticatedSessionUser);
messagingSubscriptions.subscriptions.values.forEach((subscription) =>
// Will connect to all messaging topics
LocalitySocialCloudChat.getSubscribedTopic(
subscription, TestChatMessageFactory()));
}