Browse Source

fix actived UI

pull/18/head
Sun 4 years ago
parent
commit
a8c8f5630f
  1. 6
      lib/provider.dart
  2. 32
      src/apps/group_chat/layer.rs

6
lib/provider.dart

@ -115,6 +115,7 @@ class AccountProvider extends ChangeNotifier { @@ -115,6 +115,7 @@ class AccountProvider extends ChangeNotifier {
this.coreShowWidget = DefaultCoreShow();
// load sessions.
this.actived = 0;
this.sessions.clear();
this.orderKeys.clear();
rpc.send('session-list', []);
@ -131,6 +132,7 @@ class AccountProvider extends ChangeNotifier { @@ -131,6 +132,7 @@ class AccountProvider extends ChangeNotifier {
}
logout() {
this.actived = 0;
this.accounts.clear();
this.clearActivedAccount();
this.sessions.clear();
@ -193,7 +195,7 @@ class AccountProvider extends ChangeNotifier { @@ -193,7 +195,7 @@ class AccountProvider extends ChangeNotifier {
}
clearActivedSession(SessionType type) {
if (this.activedSession.type == type && this.actived > 0) {
if (this.actived > 0 && this.activedSession.type == type) {
rpc.send('session-suspend', [this.actived, this.activedSession.gid,
this.activedSession.type == SessionType.Group]
);
@ -227,7 +229,7 @@ class AccountProvider extends ChangeNotifier { @@ -227,7 +229,7 @@ class AccountProvider extends ChangeNotifier {
if (online == OnlineType.Lost) {
this.activedSession.online = OnlineType.Waiting;
Timer(Duration(seconds: 10), () {
if (this.sessions[id].online == OnlineType.Waiting) {
if (this.sessions[id] != null && this.sessions[id].online == OnlineType.Waiting) {
this.sessions[id].online = OnlineType.Lost;
notifyListeners();
}

32
src/apps/group_chat/layer.rs

@ -17,7 +17,7 @@ use tdn_storage::local::DStorage; @@ -17,7 +17,7 @@ use tdn_storage::local::DStorage;
use crate::layer::{Layer, Online};
use crate::rpc::{session_connect, session_create, session_last, session_lost, session_suspend};
use crate::session::{connect_session, SessionType};
use crate::session::{connect_session, Session, SessionType};
use crate::storage::{group_chat_db, session_db, write_avatar_sync};
use super::models::{from_network_message, GroupChat, Member, Request};
@ -243,9 +243,33 @@ async fn handle_event( @@ -243,9 +243,33 @@ async fn handle_event(
let msg = from_network_message(height, gid, mid, &mgid, nmsg, mtime, &base)?;
results.rpcs.push(rpc::message_create(mgid, &msg));
println!("Sync: create message ok");
results
.rpcs
.push(session_last(mgid, &sid, &msg.datetime, &msg.content, false));
// UPDATE SESSION.
let s_db = session_db(&base, &mgid)?;
if let Ok(id) = Session::last(
&s_db,
&gid,
&SessionType::Group,
&msg.datetime,
&msg.content,
true,
) {
results.rpcs.push(session_last(
mgid,
&id,
&msg.datetime,
&msg.content,
false,
));
} else {
let c_db = group_chat_db(&base, &mgid)?;
if let Some(f) = GroupChat::get_id(&c_db, &gid)? {
let mut session = f.to_session();
session.last_content = msg.content;
session.insert(&s_db)?;
results.rpcs.push(session_create(mgid, &session));
}
}
}
}

Loading…
Cancel
Save