Skip to main content

locality_social_cloud_chat 1.3.0 copy "locality_social_cloud_chat: ^1.3.0" to clipboard
locality_social_cloud_chat: ^1.3.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()));
}
2
likes
0
points
280
downloads

Publisher

verified publisherlocality.media

Weekly Downloads

A chat based on Locality Social Cloud that supported End-to-End encrypted Chats and GroupChats and Chat Message state management.

Homepage
Repository
View/report issues

License

unknown (license)

Dependencies

crypto, flutter, locality_core, m511chacha20, secure_local_key_value_storage, theory, uuid

More

Packages that depend on locality_social_cloud_chat