Skip to content

Commit

Permalink
feat: add conversation refresh, bump to v0.3.1
Browse files Browse the repository at this point in the history
  • Loading branch information
geoah committed Jan 31, 2021
1 parent a157100 commit 6dd416f
Show file tree
Hide file tree
Showing 41 changed files with 163 additions and 166 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# flutterapp
# mochi

A new Flutter application.

Expand Down
2 changes: 1 addition & 1 deletion android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ android {

defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.example.flutterapp"
applicationId "com.example.mochi"
minSdkVersion 16
targetSdkVersion 28
versionCode flutterVersionCode.toInteger()
Expand Down
2 changes: 1 addition & 1 deletion android/app/src/debug/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.flutterapp">
package="com.example.mochi">
<!-- Flutter needs it to communicate with the running application
to allow setting breakpoints, to provide hot reload, etc.
-->
Expand Down
4 changes: 2 additions & 2 deletions android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.flutterapp">
package="com.example.mochi">

<!-- io.flutter.app.FlutterApplication is an android.app.Application that
calls FlutterMain.startInitialization(this); in its onCreate method.
Expand All @@ -8,7 +8,7 @@
FlutterApplication and put your custom class here. -->
<application
android:name="io.flutter.app.FlutterApplication"
android:label="flutterapp"
android:label="mochi"
android:icon="@mipmap/ic_launcher">
<activity
android:name=".MainActivity"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.example.flutterapp;
package com.example.mochi;

import android.os.Bundle;
import io.flutter.app.FlutterActivity;
Expand Down
2 changes: 1 addition & 1 deletion android/app/src/profile/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.flutterapp">
package="com.example.mochi">
<!-- Flutter needs it to communicate with the running application
to allow setting breakpoints, to provide hot reload, etc.
-->
Expand Down
11 changes: 11 additions & 0 deletions artifacts/changelog.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,16 @@
<enclosure url="https://github.com/nimona/flutter-mochi/releases/download/v0.3.0/Mochi0.3.0-0.2.2.delta" sparkle:version="0.3.0" sparkle:shortVersionString="0.3.0" sparkle:deltaFrom="0.2.2" length="14562093" type="application/octet-stream" sparkle:edSignature="4aHOyMXZmUjYA/uCiKVOV7X5oag60InT4er8y0vihCd6zf5E+vvn4QIAR2da11Yn9tGVtC9PKA/O19f44uK+CA=="/>
</sparkle:deltas>
</item>
<item>
<title>0.3.1</title>
<pubDate>Sun, 31 Jan 2021 16:17:20 +0000</pubDate>
<sparkle:minimumSystemVersion>10.11</sparkle:minimumSystemVersion>
<enclosure url="https://github.com/nimona/flutter-mochi/releases/download/v0.3.1/mochi-v0.3.1.zip" sparkle:version="0.3.1" sparkle:shortVersionString="0.3.1" length="26142937" type="application/octet-stream" sparkle:edSignature="3njezIU4jz8tZ0pcd3PFkANfttQSV47l4ixnQTLJYikDxxYTOhKx6dT0g4E3V4GdH+e7DmAB8ys6EEV9qJ+HBg=="/>
<sparkle:deltas>
<enclosure url="https://github.com/nimona/flutter-mochi/releases/download/v0.3.1/Mochi0.3.1-0.3.0.delta" sparkle:version="0.3.1" sparkle:shortVersionString="0.3.1" sparkle:deltaFrom="0.3.0" length="5132933" type="application/octet-stream" sparkle:edSignature="cYV3ZM9kDWeenbx+PDkXFn8jLCPAVXaQsQRbuLNN4pv5T4qwCX9w2OYQLU3zmexSxBN0S0vC7bvH/IqdhOlgAA=="/>
<enclosure url="https://github.com/nimona/flutter-mochi/releases/download/v0.3.1/Mochi0.3.1-0.2.3.delta" sparkle:version="0.3.1" sparkle:shortVersionString="0.3.1" sparkle:deltaFrom="0.2.3" length="16020797" type="application/octet-stream" sparkle:edSignature="hYAIv0sE5kjTF2biWoGSFwxHJ4sw786m2edWBLNjBhA1Ab/ddrO7BC1lzhNbpz2fo+TTeLPy3bFEdk/e/OxmAA=="/>
<enclosure url="https://github.com/nimona/flutter-mochi/releases/download/v0.3.1/Mochi0.3.1-0.2.2.delta" sparkle:version="0.3.1" sparkle:shortVersionString="0.3.1" sparkle:deltaFrom="0.2.2" length="16019764" type="application/octet-stream" sparkle:edSignature="7QGPiXBrg17saklVk32jJXisjiUuoc4oBbcEuSO0bfn56qawnM5b/o200QdllsiyxrVtXX5qjfN0OeVmvhkJAg=="/>
</sparkle:deltas>
</item>
</channel>
</rss>
1 change: 1 addition & 0 deletions ios/Flutter/Debug.xcconfig
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig"
#include "Generated.xcconfig"
1 change: 1 addition & 0 deletions ios/Flutter/Release.xcconfig
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig"
#include "Generated.xcconfig"
4 changes: 2 additions & 2 deletions ios/Flutter/flutter_export_environment.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ export "FLUTTER_APPLICATION_PATH=/Users/geoah/src/github.com/nimona/flutter-moch
export "FLUTTER_TARGET=lib/main.dart"
export "FLUTTER_BUILD_DIR=build"
export "SYMROOT=${SOURCE_ROOT}/../build/ios"
export "FLUTTER_BUILD_NAME=0.2.2"
export "FLUTTER_BUILD_NUMBER=0.2.2"
export "FLUTTER_BUILD_NAME=0.3.1"
export "FLUTTER_BUILD_NUMBER=0.3.1"
export "DART_OBFUSCATION=false"
export "TRACK_WIDGET_CREATION=false"
export "TREE_SHAKE_ICONS=false"
Expand Down
6 changes: 3 additions & 3 deletions ios/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@
"$(inherited)",
"$(PROJECT_DIR)/Flutter",
);
PRODUCT_BUNDLE_IDENTIFIER = com.example.flutterapp;
PRODUCT_BUNDLE_IDENTIFIER = com.example.mochi;
PRODUCT_NAME = "$(TARGET_NAME)";
VERSIONING_SYSTEM = "apple-generic";
};
Expand Down Expand Up @@ -454,7 +454,7 @@
"$(inherited)",
"$(PROJECT_DIR)/Flutter",
);
PRODUCT_BUNDLE_IDENTIFIER = com.example.flutterapp;
PRODUCT_BUNDLE_IDENTIFIER = com.example.mochi;
PRODUCT_NAME = "$(TARGET_NAME)";
VERSIONING_SYSTEM = "apple-generic";
};
Expand All @@ -477,7 +477,7 @@
"$(inherited)",
"$(PROJECT_DIR)/Flutter",
);
PRODUCT_BUNDLE_IDENTIFIER = com.example.flutterapp;
PRODUCT_BUNDLE_IDENTIFIER = com.example.mochi;
PRODUCT_NAME = "$(TARGET_NAME)";
VERSIONING_SYSTEM = "apple-generic";
};
Expand Down
2 changes: 1 addition & 1 deletion ios/Runner/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>flutterapp</string>
<string>mochi</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
Expand Down
27 changes: 16 additions & 11 deletions lib/blocs/conversations/conversations_bloc.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import 'dart:async';
import 'package:bloc/bloc.dart';
import 'package:flutterapp/data/repository.dart';
import 'package:flutterapp/event/conversation_created.dart';
import 'package:flutterapp/model/conversation.dart';
import 'package:flutterapp/blocs/conversations/conversations_event.dart';
import 'package:flutterapp/blocs/conversations/conversations_state.dart';
import 'package:mochi/data/repository.dart';
import 'package:mochi/event/conversation_created.dart';
import 'package:mochi/model/conversation.dart';
import 'package:mochi/blocs/conversations/conversations_event.dart';
import 'package:mochi/blocs/conversations/conversations_state.dart';

class ConversationsBloc extends Bloc<ConversationsEvent, ConversationsState> {
ConversationsBloc() : super(ConversationsLoading());
Expand All @@ -31,7 +31,7 @@ class ConversationsBloc extends Bloc<ConversationsEvent, ConversationsState> {
try {
await _conversationsSubscription?.cancel();
await _conversationsGet?.cancel();
var handler = (ConversationCreated event) {
var handleConversationCreated = (ConversationCreated event) {
final Conversation conversation = Conversation(
hash: event.hashS,
name: event.dataM.nonceS,
Expand All @@ -41,11 +41,16 @@ class ConversationsBloc extends Bloc<ConversationsEvent, ConversationsState> {
_conversationsSubscription = Repository.get()
.subscribeToConversations()
.stream
.listen(handler);
_conversationsGet = Repository.get()
.getConversations(100, 0)
.stream
.listen(handler);
.listen(handleConversationCreated);
_conversationsGet =
Repository.get().getConversations(100, 0).stream.listen((event) {
try {
Repository.get().refreshConversation(event.hashS);
} catch (e) {}
try {
handleConversationCreated(event);
} catch (e) {}
});
yield ConversationsLoaded();
} catch (_) {
yield ConversationsNotLoaded();
Expand Down
2 changes: 1 addition & 1 deletion lib/blocs/conversations/conversations_event.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'package:equatable/equatable.dart';

import 'package:flutterapp/model/conversation.dart';
import 'package:mochi/model/conversation.dart';

abstract class ConversationsEvent extends Equatable {
ConversationsEvent([List props = const []]) : super();
Expand Down
2 changes: 1 addition & 1 deletion lib/blocs/conversations/conversations_state.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'package:flutter/material.dart';

import 'package:flutterapp/model/conversation.dart';
import 'package:mochi/model/conversation.dart';

@immutable
abstract class ConversationsState {
Expand Down
24 changes: 15 additions & 9 deletions lib/blocs/messages/messages_bloc.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import 'dart:async';
import 'package:bloc/bloc.dart';
import 'package:flutterapp/data/repository.dart';
import 'package:flutterapp/event/conversation_message_added.dart';
import 'package:flutterapp/event/conversation_nickname_updated.dart';
import 'package:flutterapp/model/message.dart';
import 'package:flutterapp/blocs/messages/messages_event.dart';
import 'package:flutterapp/blocs/messages/messages_state.dart';
import 'package:mochi/data/repository.dart';
import 'package:mochi/event/conversation_message_added.dart';
import 'package:mochi/event/conversation_nickname_updated.dart';
import 'package:mochi/model/message.dart';
import 'package:mochi/blocs/messages/messages_event.dart';
import 'package:mochi/blocs/messages/messages_state.dart';

class MessagesBloc extends Bloc<MessagesEvent, MessagesState> {
MessagesBloc() : super(MessagesInitial());
Expand All @@ -31,7 +31,7 @@ class MessagesBloc extends Bloc<MessagesEvent, MessagesState> {
) async* {
try {
yield MessagesLoaded(event.conversation, [], {});
var handler = (event) {
var handler = (bool old, event) {
if (event is ConversationMessageAdded) {
add(
AddMessage(
Expand All @@ -54,17 +54,23 @@ class MessagesBloc extends Bloc<MessagesEvent, MessagesState> {
);
}
};
var oldHandler = (event) {
return handler(true, event);
};
var newHandler = (event) {
return handler(false, event);
};
// close old controllers
_subCtrl?.close();
_getCtrl?.close();
// start listening for new events
_subCtrl = await Repository.get()
.subscribeToMessagesForConversation(event.conversation.hash);
_subCtrl.stream.listen(handler);
_subCtrl.stream.listen(newHandler);
// get old events
_getCtrl = await Repository.get()
.getMessagesForConversation(event.conversation.hash, 100, 0);
_getCtrl.stream.listen(handler);
_getCtrl.stream.listen(oldHandler);
} catch (err) {
yield MessagesNotLoaded();
}
Expand Down
4 changes: 2 additions & 2 deletions lib/blocs/messages/messages_event.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'package:equatable/equatable.dart';
import 'package:flutterapp/model/conversation.dart';
import 'package:mochi/model/conversation.dart';

import 'package:flutterapp/model/message.dart';
import 'package:mochi/model/message.dart';

abstract class MessagesEvent extends Equatable {
MessagesEvent([List props = const []]) : super();
Expand Down
4 changes: 2 additions & 2 deletions lib/blocs/messages/messages_state.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'package:equatable/equatable.dart';
import 'package:flutter/material.dart';
import 'package:flutterapp/model/conversation.dart';
import 'package:flutterapp/model/message.dart';
import 'package:mochi/model/conversation.dart';
import 'package:mochi/model/message.dart';

@immutable
abstract class MessagesState extends Equatable {
Expand Down
16 changes: 8 additions & 8 deletions lib/conversation_list_container.dart
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutterapp/blocs/conversations/conversations_bloc.dart';
import 'package:flutterapp/blocs/conversations/conversations_event.dart';
import 'package:flutterapp/blocs/conversations/conversations_state.dart';
import 'package:flutterapp/blocs/messages/messages_bloc.dart';
import 'package:flutterapp/blocs/messages/messages_event.dart';
import 'package:flutterapp/data/repository.dart';
import 'package:flutterapp/flutter_conversations_keys.dart';
import 'package:flutterapp/widgets/loading_indicator.dart';
import 'package:mochi/blocs/conversations/conversations_bloc.dart';
import 'package:mochi/blocs/conversations/conversations_event.dart';
import 'package:mochi/blocs/conversations/conversations_state.dart';
import 'package:mochi/blocs/messages/messages_bloc.dart';
import 'package:mochi/blocs/messages/messages_event.dart';
import 'package:mochi/data/repository.dart';
import 'package:mochi/flutter_conversations_keys.dart';
import 'package:mochi/widgets/loading_indicator.dart';

class ConversationListContainer extends StatefulWidget {
ConversationListContainer();
Expand Down
5 changes: 3 additions & 2 deletions lib/data/datastore.dart
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import 'dart:async';

import 'package:flutterapp/event/conversation_created.dart';
import 'package:flutterapp/event/nimona_typed.dart';
import 'package:mochi/event/conversation_created.dart';
import 'package:mochi/event/nimona_typed.dart';

abstract class DataStore {
Future<void> init();

Future<void> joinConversation(String conversationRootHash);
Future<void> refreshConversation(String conversationRootHash);
Stream<ConversationCreated> getConversations(int limit, int offset);
Stream<ConversationCreated> subscribeToConversations();
Future<void> createConversation(String name, String topic);
Expand Down
13 changes: 9 additions & 4 deletions lib/data/mockdatastore.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import 'dart:async';
import 'dart:math';

import 'package:flutterapp/data/datastore.dart';
import 'package:flutterapp/event/conversation_created.dart';
import 'package:flutterapp/event/nimona_typed.dart';
import 'package:flutterapp/event/utils.dart';
import 'package:mochi/data/datastore.dart';
import 'package:mochi/event/conversation_created.dart';
import 'package:mochi/event/nimona_typed.dart';
import 'package:mochi/event/utils.dart';

final List<String> mockEvents = [
'{"data:m":{"nonce:s":"hello-world!!1"},"metadata:m":{},"type:s":"stream:poc.nimona.io/conversation","_hash:s":"oh1.2rA8iDpuVpTS3WDeG7LLQWGUtzrgw9xHgGAVHPafnCTo"}',
Expand Down Expand Up @@ -33,6 +33,11 @@ class MockDataStore implements DataStore {
String conversationRootHash,
) async {}

@override
Future<void> refreshConversation(
String conversationRootHash,
) async {}

@override
Stream<ConversationCreated> getConversations(
int limit,
Expand Down
25 changes: 18 additions & 7 deletions lib/data/nimonadatastore.dart
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import 'dart:async';

import 'package:flutterapp/data/datastore.dart';
import 'package:flutterapp/event/conversation_created.dart'
import 'package:mochi/data/datastore.dart';
import 'package:mochi/event/conversation_created.dart'
as conversation_created;
import 'package:flutterapp/event/conversation_message_added.dart'
import 'package:mochi/event/conversation_message_added.dart'
as conversation_message_added;
import 'package:flutterapp/event/nimona_medatada.dart';
import 'package:flutterapp/event/nimona_stream_subscription.dart' as nss;
import 'package:flutterapp/event/nimona_typed.dart';
import 'package:flutterapp/event/utils.dart';
import 'package:mochi/event/nimona_medatada.dart';
import 'package:mochi/event/nimona_stream_subscription.dart' as nss;
import 'package:mochi/event/nimona_typed.dart';
import 'package:mochi/event/utils.dart';
import 'package:nimona/models/get_request.dart';
import 'package:nimona/nimona.dart';
import 'package:uuid/uuid.dart';
Expand All @@ -23,6 +23,17 @@ class NimonaDataStore implements DataStore {
}
}

@override
Future<void> refreshConversation(
String conversationRootHash,
) async {
try {
await Nimona.requestStream(conversationRootHash);
} catch (e) {
print('ERROR refreshing stream, err=' + e.toString());
}
}

@override
Future<void> joinConversation(
String conversationRootHash,
Expand Down
14 changes: 10 additions & 4 deletions lib/data/repository.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import 'dart:async';

import 'package:flutterapp/data/datastore.dart';
import 'package:flutterapp/data/nimonadatastore.dart';
import 'package:flutterapp/event/conversation_created.dart';
import 'package:flutterapp/event/nimona_typed.dart';
import 'package:mochi/data/datastore.dart';
import 'package:mochi/data/nimonadatastore.dart';
import 'package:mochi/event/conversation_created.dart';
import 'package:mochi/event/nimona_typed.dart';

class Repository {
static final Repository _repo = new Repository._internal();
Expand All @@ -19,6 +19,12 @@ class Repository {
_dataStore.init();
}

Future<void> refreshConversation(
String conversationRootHash,
) async {
return _dataStore.refreshConversation(conversationRootHash);
}

Future<void> joinConversation(
String conversationRootHash,
) async {
Expand Down
4 changes: 2 additions & 2 deletions lib/event/conversation_created.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'dart:convert';

import 'package:flutterapp/event/nimona_medatada.dart';
import 'package:flutterapp/event/nimona_typed.dart';
import 'package:mochi/event/nimona_medatada.dart';
import 'package:mochi/event/nimona_typed.dart';

class ConversationCreated implements NimonaTyped {
DataM dataM;
Expand Down
Loading

0 comments on commit 6dd416f

Please sign in to comment.