Browse Source

fix phone save image and online

pull/18/head
Sun 4 years ago
parent
commit
9e666bb0a8
  1. 1
      android/app/src/main/AndroidManifest.xml
  2. 10
      lib/apps/assistant/message.dart
  3. 6
      lib/apps/assistant/page.dart
  4. 6
      lib/apps/chat/detail.dart
  5. 1
      lib/apps/file/list.dart
  6. 6
      lib/apps/group_chat/detail.dart
  7. 11
      lib/provider.dart
  8. 4
      lib/security.dart
  9. 10
      lib/widgets/chat_message.dart
  10. 14
      pubspec.lock
  11. 2
      pubspec.yaml
  12. 4
      src/apps/group_chat/models.rs
  13. 13
      src/apps/group_chat/rpc.rs
  14. 4
      src/rpc.rs

1
android/app/src/main/AndroidManifest.xml

@ -41,4 +41,5 @@ @@ -41,4 +41,5 @@
</application>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.RECORD_AUDIO"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
</manifest>

10
lib/apps/assistant/message.dart

@ -1,7 +1,7 @@ @@ -1,7 +1,7 @@
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:image_gallery_saver/image_gallery_saver.dart';
import 'package:image_save/image_save.dart';
import 'package:permission_handler/permission_handler.dart';
import 'package:open_file/open_file.dart';
@ -69,8 +69,12 @@ class AssistantMessage extends StatelessWidget { @@ -69,8 +69,12 @@ class AssistantMessage extends StatelessWidget {
].request();
if (statuses[Permission.storage] == PermissionStatus.granted) {
final result = await ImageGallerySaver.saveFile(imagePath);
print(result);
// Save to album.
final data = await File(imagePath).readAsBytes();
final bool? success = await ImageSave.saveImage(data, content, albumName: "ESSE");
print(success);
Navigator.pop(context);
}
},

6
lib/apps/assistant/page.dart

@ -162,7 +162,7 @@ class _AssistantDetailState extends State<AssistantDetail> { @@ -162,7 +162,7 @@ class _AssistantDetailState extends State<AssistantDetail> {
child: Column(
children: [
Container(
padding: EdgeInsets.only(left: 20.0, right: 20.0, top: 10.0, bottom: 10.0),
padding: EdgeInsets.only(left: 20.0, right: 20.0, top: 10.0, bottom: 6.0),
child: Row(
children: [
if (!isDesktop)
@ -183,9 +183,9 @@ class _AssistantDetailState extends State<AssistantDetail> { @@ -183,9 +183,9 @@ class _AssistantDetailState extends State<AssistantDetail> {
Text('Jarvis',
style: TextStyle(fontWeight: FontWeight.bold),
),
SizedBox(height: 6.0),
SizedBox(height: 5.0),
Text(lang.onlineActive,
style: TextStyle(color: color.onPrimary.withOpacity(0.5), fontSize: 14.0))
style: TextStyle(color: color.onPrimary.withOpacity(0.5), fontSize: 12.0))
],
),
),

6
lib/apps/chat/detail.dart

@ -178,7 +178,7 @@ class _ChatDetailState extends State<ChatDetail> { @@ -178,7 +178,7 @@ class _ChatDetailState extends State<ChatDetail> {
child: Column(
children: [
Container(
padding: EdgeInsets.only(left: 20.0, right: 20.0, top: 10.0, bottom: 10.0),
padding: EdgeInsets.only(left: 20.0, right: 20.0, top: 10.0, bottom: 6.0),
child: Row(
children: [
if (!isDesktop)
@ -201,13 +201,13 @@ class _ChatDetailState extends State<ChatDetail> { @@ -201,13 +201,13 @@ class _ChatDetailState extends State<ChatDetail> {
friend.name,
style: TextStyle(fontWeight: FontWeight.bold),
),
SizedBox(height: 6.0),
SizedBox(height: 5.0),
Text(friend.isClosed
? lang.closed
: session.onlineLang(lang),
style: TextStyle(
color: color.onPrimary.withOpacity(0.5),
fontSize: 14.0))
fontSize: 12.0))
],
),
),

1
lib/apps/file/list.dart

@ -16,7 +16,6 @@ class FilesList extends StatefulWidget { @@ -16,7 +16,6 @@ class FilesList extends StatefulWidget {
const List FILE_DIRECTORY = [
["Starred", Icons.star],
["Documents", Icons.description],
["Pictures", Icons.photo],
["Media", Icons.music_video],
["Trash", Icons.auto_delete],
];

6
lib/apps/group_chat/detail.dart

@ -183,7 +183,7 @@ class _GroupChatDetailState extends State<GroupChatDetail> { @@ -183,7 +183,7 @@ class _GroupChatDetailState extends State<GroupChatDetail> {
child: Column(
children: [
Container(
padding: EdgeInsets.only(left: 20.0, right: 20.0, top: 10.0, bottom: 10.0),
padding: EdgeInsets.only(left: 20.0, right: 20.0, top: 10.0, bottom: 6.0),
child: Row(
children: [
if (!isDesktop)
@ -206,13 +206,13 @@ class _GroupChatDetailState extends State<GroupChatDetail> { @@ -206,13 +206,13 @@ class _GroupChatDetailState extends State<GroupChatDetail> {
this.group!.name,
style: TextStyle(fontWeight: FontWeight.bold),
),
const SizedBox(height: 6.0),
const SizedBox(height: 5.0),
Text(this.group!.isClosed
? lang.closed
: session.onlineLang(lang),
style: TextStyle(
color: color.onPrimary.withOpacity(0.5),
fontSize: 14.0))
fontSize: 12.0))
],
),
),

11
lib/provider.dart

@ -61,8 +61,6 @@ class AccountProvider extends ChangeNotifier { @@ -61,8 +61,6 @@ class AccountProvider extends ChangeNotifier {
rpc.addListener('session-connect', _sessionConnect, false);
rpc.addListener('session-suspend', _sessionSuspend, false);
rpc.addListener('session-lost', _sessionLost, false);
systemInfo();
}
/// when security load accounts from rpc.
@ -99,11 +97,7 @@ class AccountProvider extends ChangeNotifier { @@ -99,11 +97,7 @@ class AccountProvider extends ChangeNotifier {
this.activedAccountId = account.gid;
this.accounts[account.gid] = account;
rpc.send('account-login', [account.gid, account.lock]);
rpc.send('session-list', []);
new Future.delayed(Duration(seconds: DEFAULT_ONLINE_DELAY),
() => rpc.send('account-online', [account.gid]));
updateLogined(account);
}
@ -122,7 +116,6 @@ class AccountProvider extends ChangeNotifier { @@ -122,7 +116,6 @@ class AccountProvider extends ChangeNotifier {
if (!this.activedAccount.online) {
this.activedAccount.online = true;
rpc.send('account-login', [gid, this.activedAccount.lock]);
new Future.delayed(Duration(seconds: DEFAULT_ONLINE_DELAY),
() => rpc.send('account-online', [gid]));
}
@ -190,10 +183,6 @@ class AccountProvider extends ChangeNotifier { @@ -190,10 +183,6 @@ class AccountProvider extends ChangeNotifier {
notifyListeners();
}
systemInfo() {
rpc.send('account-system-info', []);
}
clearActivedSession(SessionType type) {
if (this.actived > 0 && this.activedSession.type == type) {
rpc.send('session-suspend', [this.actived, this.activedSession.gid,

4
lib/security.dart

@ -149,6 +149,9 @@ class _SecurityPageState extends State<SecurityPage> { @@ -149,6 +149,9 @@ class _SecurityPageState extends State<SecurityPage> {
await rpc.init(Global.wsRpc);
}
// init system info.
rpc.send('account-system-info', []);
// check if has logined.
final loginedAccounts = await getLogined();
@ -173,6 +176,7 @@ class _SecurityPageState extends State<SecurityPage> { @@ -173,6 +176,7 @@ class _SecurityPageState extends State<SecurityPage> {
} else {
// TODO tostor error
print(res.error);
await clearLogined();
}
}

10
lib/widgets/chat_message.dart

@ -1,7 +1,7 @@ @@ -1,7 +1,7 @@
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:image_gallery_saver/image_gallery_saver.dart';
import 'package:image_save/image_save.dart';
import 'package:provider/provider.dart';
import 'package:permission_handler/permission_handler.dart';
import 'package:open_file/open_file.dart';
@ -98,8 +98,12 @@ class ChatMessage extends StatelessWidget { @@ -98,8 +98,12 @@ class ChatMessage extends StatelessWidget {
].request();
if (statuses[Permission.storage] == PermissionStatus.granted) {
final result = await ImageGallerySaver.saveFile(imagePath);
print(result);
// Save to album.
final data = await File(imagePath).readAsBytes();
final bool? success = await ImageSave.saveImage(data, message.content, albumName: "ESSE");
print(success);
Navigator.pop(context);
}
},

14
pubspec.lock

@ -303,13 +303,6 @@ packages: @@ -303,13 +303,6 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "3.0.2"
image_gallery_saver:
dependency: "direct main"
description:
name: image_gallery_saver
url: "https://pub.dartlang.org"
source: hosted
version: "1.6.9"
image_picker:
dependency: "direct main"
description:
@ -331,6 +324,13 @@ packages: @@ -331,6 +324,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "2.3.0"
image_save:
dependency: "direct main"
description:
name: image_save
url: "https://pub.dartlang.org"
source: hosted
version: "5.0.0"
integration_test:
dependency: "direct dev"
description: flutter

2
pubspec.yaml

@ -23,7 +23,7 @@ dependencies: @@ -23,7 +23,7 @@ dependencies:
url_launcher: any
permission_handler: any
image_picker: any # pick image
image_gallery_saver: any # Mobile save image to gallery
image_save: any # Mobile save image to gallery
file_picker: any # pick file
file_selector: any # pick file
file_selector_linux:

4
src/apps/group_chat/models.rs

@ -342,7 +342,7 @@ impl GroupChat { @@ -342,7 +342,7 @@ impl GroupChat {
if unique_check.len() > 0 {
let id = unique_check.pop().unwrap().pop().unwrap().as_i64();
self.id = id;
let sql = format!("UPDATE groups SET height = {}, owner = '{}', gtype = {}, addr='{}', name = '{}', bio = '{}', is_ok = {}, is_need_agree = {}, is_closed = {}, key = '{}', datetime = {},is_remote = {}, is_deleted = false WHERE id = {}",
let sql = format!("UPDATE groups SET height = {}, owner = '{}', gtype = {}, addr='{}', name = '{}', bio = '{}', is_ok = {}, is_need_agree = {}, is_closed = {}, key = '{}', datetime = {}, is_remote = {}, is_deleted = false WHERE id = {}",
self.height,
self.owner.to_hex(),
self.g_type.to_u32(),
@ -359,7 +359,7 @@ impl GroupChat { @@ -359,7 +359,7 @@ impl GroupChat {
);
db.update(&sql)?;
} else {
let sql = format!("INSERT INTO groups (height, owner, gcd, gtype, addr, name, bio, is_ok, is_need_agree, is_closed, key, datetime, is_deleted) VALUES ({}, '{}', '{}', {}, '{}', '{}', '{}', {}, {}, {}, '{}', {}, {}, false)",
let sql = format!("INSERT INTO groups (height, owner, gcd, gtype, addr, name, bio, is_ok, is_need_agree, is_closed, key, datetime, is_remote, is_deleted) VALUES ({}, '{}', '{}', {}, '{}', '{}', '{}', {}, {}, {}, '{}', {}, {}, false)",
self.height,
self.owner.to_hex(),
self.g_id.to_hex(),

13
src/apps/group_chat/rpc.rs

@ -1,7 +1,7 @@ @@ -1,7 +1,7 @@
use std::sync::Arc;
use tdn::types::{
group::GroupId,
message::SendType,
message::{NetworkType, SendType},
primitive::{HandleResult, PeerAddr},
rpc::{json, rpc_response, RpcError, RpcHandler, RpcParam},
};
@ -179,6 +179,7 @@ pub(crate) fn new_rpc_handler(handler: &mut RpcHandler<RpcState>) { @@ -179,6 +179,7 @@ pub(crate) fn new_rpc_handler(handler: &mut RpcHandler<RpcState>) {
GroupLocation::from_u32(params[0].as_i64().ok_or(RpcError::ParseError)? as u32);
let gtype = GroupType::from_u32(params[1].as_i64().ok_or(RpcError::ParseError)? as u32);
let my_name = params[2].as_str().ok_or(RpcError::ParseError)?.to_owned();
// params[3] is remote addr next parse.
let name = params[4].as_str().ok_or(RpcError::ParseError)?.to_owned();
let bio = params[5].as_str().ok_or(RpcError::ParseError)?.to_owned();
let need_agree = params[6].as_bool().ok_or(RpcError::ParseError)?;
@ -204,6 +205,8 @@ pub(crate) fn new_rpc_handler(handler: &mut RpcHandler<RpcState>) { @@ -204,6 +205,8 @@ pub(crate) fn new_rpc_handler(handler: &mut RpcHandler<RpcState>) {
glocation == GroupLocation::Remote,
);
let gcd = gc.g_id;
let gdid = gc.id;
let gheight = gc.height;
// save db
let me = state.group.read().await.clone_user(&gid)?;
@ -231,6 +234,14 @@ pub(crate) fn new_rpc_handler(handler: &mut RpcHandler<RpcState>) { @@ -231,6 +234,14 @@ pub(crate) fn new_rpc_handler(handler: &mut RpcHandler<RpcState>) {
let mut session = gc.to_session();
session.insert(&s_db)?;
results.rpcs.push(session_create(gid, &session));
// online local group.
state
.layer
.write()
.await
.add_running(&gcd, gid, gdid, gheight)?;
results.networks.push(NetworkType::AddGroup(gcd));
}
Ok(results)

4
src/rpc.rs

@ -266,6 +266,8 @@ fn new_rpc_handler( @@ -266,6 +266,8 @@ fn new_rpc_handler(
let mut results = HandleResult::rpc(json!(vec![gid.to_hex()]));
results.networks.push(NetworkType::AddGroup(gid)); // add AddGroup to TDN.
debug!("Account Logined: {}.", gid.to_hex());
Ok(results)
},
);
@ -292,6 +294,8 @@ fn new_rpc_handler( @@ -292,6 +294,8 @@ fn new_rpc_handler(
let mut results = HandleResult::rpc(json!(vec![gid.to_hex()]));
results.networks.push(NetworkType::AddGroup(gid)); // add AddGroup to TDN.
debug!("Account Logined: {}.", gid.to_hex());
if let Some(addr) = some_addr {
let group_lock = state.group.read().await;
let sender = group_lock.sender();

Loading…
Cancel
Save