Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Send/Receive Encoded Content #63

Merged
merged 21 commits into from
Jun 30, 2023
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions example/babel.config.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
const path = require('path');
const path = require("path");
module.exports = function (api) {
api.cache(true);
return {
presets: ['babel-preset-expo'],
presets: ["babel-preset-expo"],
plugins: [
[
'module-resolver',
"module-resolver",
{
extensions: ['.tsx', '.ts', '.js', '.json'],
extensions: [".tsx", ".ts", ".js", ".json"],
alias: {
// For development, we want to alias the library to the source
'xmtp-react-native-sdk': path.join(__dirname, '..', 'src', 'index.ts'),
"xmtp-react-native-sdk": path.join(
__dirname,
"..",
"src",
"index.ts"
),
},
},
],
"@babel/plugin-proposal-export-namespace-from",
],
};
};
14 changes: 9 additions & 5 deletions example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ PODS:
- hermes-engine/Pre-built (0.71.6)
- libevent (2.1.12)
- Logging (1.0.0)
- MessagePacker (0.4.7)
- MMKV (1.3.0):
- MMKVCore (~> 1.3.0)
- MMKVCore (1.3.0)
Expand Down Expand Up @@ -408,14 +409,15 @@ PODS:
- GenericJSON (~> 2.0)
- Logging (~> 1.0.0)
- secp256k1.swift (~> 0.1)
- XMTP (0.3.2-alpha0):
- XMTP (0.3.3-alpha0):
- Connect-Swift
- GzipSwift
- web3.swift
- XMTPRust (= 0.3.0-beta0)
- XMTPReactNative (0.1.0):
- ExpoModulesCore
- XMTP (= 0.3.2-alpha0)
- MessagePacker
- XMTP (= 0.3.3-alpha0)
- XMTPRust (0.3.0-beta0)
- Yoga (1.14.0)

Expand Down Expand Up @@ -484,6 +486,7 @@ SPEC REPOS:
- GzipSwift
- libevent
- Logging
- MessagePacker
- MMKV
- MMKVCore
- secp256k1.swift
Expand Down Expand Up @@ -618,6 +621,7 @@ SPEC CHECKSUMS:
hermes-engine: b434cea529ad0152c56c7cb6486b0c4c0b23b5de
libevent: 4049cae6c81cdb3654a443be001fb9bdceff7913
Logging: 9ef4ecb546ad3169398d5a723bc9bea1c46bef26
MessagePacker: ab2fe250e86ea7aedd1a9ee47a37083edd41fd02
MMKV: 9c6c3fa4ddd849f28c7b9a5c9d23aab84f14ee35
MMKVCore: 9bb7440b170181ac5b81f542ac258103542e693d
RCT-Folly: 424b8c9a7a0b9ab2886ffe9c3b041ef628fd4fb1
Expand Down Expand Up @@ -656,11 +660,11 @@ SPEC CHECKSUMS:
secp256k1.swift: a7e7a214f6db6ce5db32cc6b2b45e5c4dd633634
SwiftProtobuf: afced68785854575756db965e9da52bbf3dc45e7
web3.swift: 2263d1e12e121b2c42ffb63a5a7beb1acaf33959
XMTP: bbdd2c59b57104d7713a31be2fa011fc07f81314
XMTPReactNative: 48408071eeb51d1593d49c548c6002e948cd6b43
XMTP: bfc0747f46689e67132fa959c2b1da6d92aadf1e
XMTPReactNative: 3a62c6355f8ba350ca7f6e4d187a24f6f590c955
XMTPRust: 233518ed46fbe3ea9e3bc3035de9a620dba09ce5
Yoga: ba09b6b11e6139e3df8229238aa794205ca6a02a

PODFILE CHECKSUM: 522d88edc2d5fac4825e60a121c24abc18983367

COCOAPODS: 1.11.3
COCOAPODS: 1.12.1
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
80323D3D45487AD85F64F249 /* Pods-xmtpreactnativesdkexample.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-xmtpreactnativesdkexample.debug.xcconfig"; path = "Target Support Files/Pods-xmtpreactnativesdkexample/Pods-xmtpreactnativesdkexample.debug.xcconfig"; sourceTree = "<group>"; };
A6A5DB852A00551E001DF8C2 /* xmtpreactnativesdkexampleUITests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = xmtpreactnativesdkexampleUITests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
A6A5DB872A00551E001DF8C2 /* xmtpreactnativesdkexampleUITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = xmtpreactnativesdkexampleUITests.swift; sourceTree = "<group>"; };
A6AE8C832A49F1F300BD4E8B /* libMessagePack.swift.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; path = libMessagePack.swift.a; sourceTree = BUILT_PRODUCTS_DIR; };
AA286B85B6C04FC6940260E9 /* SplashScreen.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; name = SplashScreen.storyboard; path = xmtpreactnativesdkexample/SplashScreen.storyboard; sourceTree = "<group>"; };
BB2F792C24A3F905000567C9 /* Expo.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Expo.plist; sourceTree = "<group>"; };
ED297162215061F000B7C4FE /* JavaScriptCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = JavaScriptCore.framework; path = System/Library/Frameworks/JavaScriptCore.framework; sourceTree = SDKROOT; };
Expand Down Expand Up @@ -86,6 +87,7 @@
2D16E6871FA4F8E400B85C8A /* Frameworks */ = {
isa = PBXGroup;
children = (
A6AE8C832A49F1F300BD4E8B /* libMessagePack.swift.a */,
ED297162215061F000B7C4FE /* JavaScriptCore.framework */,
78B76F8B6347E6AE6088DF9B /* libPods-xmtpreactnativesdkexample.a */,
);
Expand Down Expand Up @@ -581,7 +583,7 @@
DEVELOPMENT_TEAM = FY4NZR34Z3;
GCC_C_LANGUAGE_STANDARD = gnu11;
GENERATE_INFOPLIST_FILE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 16.4;
IPHONEOS_DEPLOYMENT_TARGET = 16.0;
MARKETING_VERSION = 1.0;
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
MTL_FAST_MATH = YES;
Expand Down Expand Up @@ -614,7 +616,7 @@
DEVELOPMENT_TEAM = FY4NZR34Z3;
GCC_C_LANGUAGE_STANDARD = gnu11;
GENERATE_INFOPLIST_FILE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 16.4;
IPHONEOS_DEPLOYMENT_TARGET = 16.0;
MARKETING_VERSION = 1.0;
MTL_FAST_MATH = YES;
OTHER_SWIFT_FLAGS = "$(inherited) -D EXPO_CONFIGURATION_RELEASE";
Expand Down

This file was deleted.

41 changes: 34 additions & 7 deletions example/src/ConversationView.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { NativeStackScreenProps } from "@react-navigation/native-stack";
import { content as protoContent } from "@xmtp/proto";
import React, { useEffect, useState } from "react";
import {
Text,
Expand All @@ -8,25 +9,44 @@ import {
View,
Button,
} from "react-native";
import { Conversation, DecodedMessage } from "xmtp-react-native-sdk";
import { Conversation } from "xmtp-react-native-sdk";

import { RootStackParamList } from "./HomeView";
import { TextCodec } from "./test_utils";
import {
CodecRegistry,
ContentCodecInterface,
} from "../../src/lib/CodecRegistry";

type Props = NativeStackScreenProps<RootStackParamList, "Conversation View">;

type DecodedMessage = {
content: string;
daria-github marked this conversation as resolved.
Show resolved Hide resolved
id: string;
senderAddress: string;
sent: Date;
};

export default function ConversationView({ route }: Props): JSX.Element {
const conversation = new Conversation(route.params.conversation);

const [messages, setMessages] = useState<DecodedMessage[]>([]);
const [refreshing, setRefreshing] = useState<boolean>(false);
const [text, onChangeText] = useState<string>("");
const [content, onChangeContent] = useState<string>("");
const [isSending, setIsSending] = useState<boolean>(false);

async function loadMessages() {
try {
const messages = await conversation.messages();
const textCodec = new TextCodec();
const mappedMessages = messages.map((msg) => {
return {
...msg,
content: textCodec.decode(msg.content),
};
});
setMessages(
messages.sort((a, b) => {
mappedMessages.sort((a, b) => {
return a.sent > b.sent ? 1 : -1;
})
);
Expand All @@ -49,7 +69,14 @@ export default function ConversationView({ route }: Props): JSX.Element {

async function sendMessage() {
setIsSending(true);
const message = await conversation.send(text);
let codec: ContentCodecInterface<string | number> = new TextCodec();

const registry = new CodecRegistry();
registry.register(codec);

const encodedContent = codec.encode(content);
const data = protoContent.EncodedContent.encode(encodedContent).finish();
const message = await conversation.send(data);

const uniqueMessages = [
...new Map(
Expand All @@ -62,7 +89,7 @@ export default function ConversationView({ route }: Props): JSX.Element {
setMessages(uniqueMessages);

setIsSending(false);
onChangeText("");
onChangeContent("");
}

useEffect(() => {
Expand Down Expand Up @@ -96,8 +123,8 @@ export default function ConversationView({ route }: Props): JSX.Element {
<TextInput
onSubmitEditing={sendMessage}
editable={!isSending}
value={text}
onChangeText={onChangeText}
value={content}
onChangeText={onChangeContent}
style={{
height: 40,
margin: 12,
Expand Down
Loading