mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2024-12-17 17:20:21 +01:00
Compare commits
15 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 701b4186b6 | |||
| 9b6ca23dcb | |||
| 257e03f10a | |||
| 1410b4bd85 | |||
| 42a35e8c72 | |||
| 7b644c0dcf | |||
| c3d9d9a7c3 | |||
| 261767035e | |||
| c9b00b3054 | |||
| 1697190189 | |||
| 24609a98c6 | |||
| 60752feb9c | |||
| ff5ef638cd | |||
| df619d540b | |||
| 53d8a85b8c |
@@ -21,6 +21,8 @@ public let CURRENT_CHAT_VERSION: Int = 2
|
||||
// version range that supports establishing direct connection with a group member (xGrpDirectInvVRange in core)
|
||||
public let CREATE_MEMBER_CONTACT_VRANGE = VersionRange(minVersion: 2, maxVersion: CURRENT_CHAT_VERSION)
|
||||
|
||||
private let networkStatusesLock = DispatchQueue(label: "chat.simplex.app.network-statuses.lock")
|
||||
|
||||
enum TerminalItem: Identifiable {
|
||||
case cmd(Date, ChatCommand)
|
||||
case resp(Date, ChatResponse)
|
||||
@@ -1566,34 +1568,30 @@ func processReceivedMsg(_ res: ChatResponse) async {
|
||||
m.removeChat(mergedContact.id)
|
||||
}
|
||||
}
|
||||
case let .contactsSubscribed(_, contactRefs):
|
||||
await updateContactsStatus(contactRefs, status: .connected)
|
||||
case let .contactsDisconnected(_, contactRefs):
|
||||
await updateContactsStatus(contactRefs, status: .disconnected)
|
||||
case let .contactSubSummary(_, contactSubscriptions):
|
||||
await MainActor.run {
|
||||
for sub in contactSubscriptions {
|
||||
// no need to update contact here, and it is slow
|
||||
// if active(user) {
|
||||
// m.updateContact(sub.contact)
|
||||
// }
|
||||
if let err = sub.contactError {
|
||||
processContactSubError(sub.contact, err)
|
||||
} else {
|
||||
m.setContactNetworkStatus(sub.contact, .connected)
|
||||
}
|
||||
}
|
||||
}
|
||||
case let .networkStatus(status, connections):
|
||||
await MainActor.run {
|
||||
// dispatch queue to synchronize access
|
||||
networkStatusesLock.sync {
|
||||
var ns = m.networkStatuses
|
||||
// slow loop is on the background thread
|
||||
for cId in connections {
|
||||
m.networkStatuses[cId] = status
|
||||
ns[cId] = status
|
||||
}
|
||||
// fast model update is on the main thread
|
||||
DispatchQueue.main.sync {
|
||||
m.networkStatuses = ns
|
||||
}
|
||||
}
|
||||
case let .networkStatuses(_, statuses): ()
|
||||
await MainActor.run {
|
||||
// dispatch queue to synchronize access
|
||||
networkStatusesLock.sync {
|
||||
var ns = m.networkStatuses
|
||||
// slow loop is on the background thread
|
||||
for s in statuses {
|
||||
m.networkStatuses[s.agentConnId] = s.networkStatus
|
||||
ns[s.agentConnId] = s.networkStatus
|
||||
}
|
||||
// fast model update is on the main thread
|
||||
DispatchQueue.main.sync {
|
||||
m.networkStatuses = ns
|
||||
}
|
||||
}
|
||||
case let .newChatItem(user, aChatItem):
|
||||
@@ -1944,26 +1942,6 @@ func chatItemSimpleUpdate(_ user: any UserLike, _ aChatItem: AChatItem) async {
|
||||
}
|
||||
}
|
||||
|
||||
func updateContactsStatus(_ contactRefs: [ContactRef], status: NetworkStatus) async {
|
||||
let m = ChatModel.shared
|
||||
await MainActor.run {
|
||||
for c in contactRefs {
|
||||
m.networkStatuses[c.agentConnId] = status
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func processContactSubError(_ contact: Contact, _ chatError: ChatError) {
|
||||
let m = ChatModel.shared
|
||||
var err: String
|
||||
switch chatError {
|
||||
case .errorAgent(agentError: .BROKER(_, .NETWORK)): err = "network"
|
||||
case .errorAgent(agentError: .SMP(smpErr: .AUTH)): err = "contact deleted"
|
||||
default: err = String(describing: chatError)
|
||||
}
|
||||
m.setContactNetworkStatus(contact, .error(connectionError: err))
|
||||
}
|
||||
|
||||
func refreshCallInvitations() throws {
|
||||
let m = ChatModel.shared
|
||||
let callInvitations = try justRefreshCallInvitations()
|
||||
|
||||
@@ -22,7 +22,11 @@ struct SimpleXApp: App {
|
||||
|
||||
init() {
|
||||
DispatchQueue.global(qos: .background).sync {
|
||||
haskell_init()
|
||||
// we have to use debug profile file name without extension here because .hp extension is added by profiler
|
||||
haskell_init(
|
||||
getAppEventLogPath().path,
|
||||
getAppDebugProfilePrefixPath().path
|
||||
)
|
||||
// hs_init(0, nil)
|
||||
}
|
||||
UserDefaults.standard.register(defaults: appDefaults)
|
||||
|
||||
@@ -17,6 +17,7 @@ struct ChatView: View {
|
||||
@Environment(\.colorScheme) var colorScheme
|
||||
@Environment(\.dismiss) var dismiss
|
||||
@Environment(\.presentationMode) var presentationMode
|
||||
@Environment(\.scenePhase) var scenePhase
|
||||
@State @ObservedObject var chat: Chat
|
||||
@State private var showChatInfoSheet: Bool = false
|
||||
@State private var showAddMembersSheet: Bool = false
|
||||
@@ -234,7 +235,9 @@ struct ChatView: View {
|
||||
|
||||
private func initChatView() {
|
||||
let cInfo = chat.chatInfo
|
||||
if case let .direct(contact) = cInfo {
|
||||
// This check prevents the call to apiContactInfo after the app is suspended, and the database is closed.
|
||||
if case .active = scenePhase,
|
||||
case let .direct(contact) = cInfo {
|
||||
Task {
|
||||
do {
|
||||
let (stats, _) = try await apiContactInfo(chat.chatInfo.apiId)
|
||||
|
||||
@@ -12,6 +12,7 @@ private let fillColorLight = Color(uiColor: UIColor(red: 0.99, green: 0.99, blue
|
||||
struct UserPicker: View {
|
||||
@EnvironmentObject var m: ChatModel
|
||||
@Environment(\.colorScheme) var colorScheme
|
||||
@Environment(\.scenePhase) var scenePhase
|
||||
@Binding var showSettings: Bool
|
||||
@Binding var showConnectDesktop: Bool
|
||||
@Binding var userPickerVisible: Bool
|
||||
@@ -91,7 +92,10 @@ struct UserPicker: View {
|
||||
.opacity(userPickerVisible ? 1.0 : 0.0)
|
||||
.onAppear {
|
||||
do {
|
||||
m.users = try listUsers()
|
||||
// This check prevents the call of listUsers after the app is suspended, and the database is closed.
|
||||
if case .active = scenePhase {
|
||||
m.users = try listUsers()
|
||||
}
|
||||
} catch let error {
|
||||
logger.error("Error loading users \(responseError(error))")
|
||||
}
|
||||
|
||||
@@ -45,6 +45,11 @@ struct DeveloperView: View {
|
||||
}
|
||||
|
||||
if developerTools {
|
||||
Section {
|
||||
exportDebugProfileButton()
|
||||
exportEventLogButton()
|
||||
}
|
||||
|
||||
Section {
|
||||
settingsRow("key") {
|
||||
Toggle("Post-quantum E2EE", isOn: $pqExperimentalEnabled)
|
||||
@@ -62,6 +67,24 @@ struct DeveloperView: View {
|
||||
}
|
||||
}
|
||||
|
||||
@ViewBuilder private func exportDebugProfileButton() -> some View {
|
||||
let url = getAppDebugProfilePath()
|
||||
settingsRow("square.and.arrow.up") {
|
||||
Button("Export debugging profile") {
|
||||
showShareSheet(items: [url])
|
||||
}
|
||||
}.disabled(!FileManager.default.fileExists(atPath: url.path))
|
||||
}
|
||||
|
||||
@ViewBuilder private func exportEventLogButton() -> some View {
|
||||
let url = getAppEventLogPath()
|
||||
settingsRow("square.and.arrow.up") {
|
||||
Button("Export event log") {
|
||||
showShareSheet(items: [url])
|
||||
}
|
||||
}.disabled(!FileManager.default.fileExists(atPath: url.path))
|
||||
}
|
||||
|
||||
private func setPQExperimentalEnabled(_ enable: Bool) {
|
||||
do {
|
||||
try apiSetPQEncryption(enable)
|
||||
|
||||
@@ -557,11 +557,6 @@ public enum ChatResponse: Decodable, Error {
|
||||
case contactRequestRejected(user: UserRef)
|
||||
case contactUpdated(user: UserRef, toContact: Contact)
|
||||
case groupMemberUpdated(user: UserRef, groupInfo: GroupInfo, fromMember: GroupMember, toMember: GroupMember)
|
||||
// TODO remove events below
|
||||
case contactsSubscribed(server: String, contactRefs: [ContactRef])
|
||||
case contactsDisconnected(server: String, contactRefs: [ContactRef])
|
||||
case contactSubSummary(user: UserRef, contactSubscriptions: [ContactSubStatus])
|
||||
// TODO remove events above
|
||||
case networkStatus(networkStatus: NetworkStatus, connections: [String])
|
||||
case networkStatuses(user_: UserRef?, networkStatuses: [ConnNetworkStatus])
|
||||
case groupSubscribed(user: UserRef, groupInfo: GroupRef)
|
||||
@@ -724,9 +719,6 @@ public enum ChatResponse: Decodable, Error {
|
||||
case .contactRequestRejected: return "contactRequestRejected"
|
||||
case .contactUpdated: return "contactUpdated"
|
||||
case .groupMemberUpdated: return "groupMemberUpdated"
|
||||
case .contactsSubscribed: return "contactsSubscribed"
|
||||
case .contactsDisconnected: return "contactsDisconnected"
|
||||
case .contactSubSummary: return "contactSubSummary"
|
||||
case .networkStatus: return "networkStatus"
|
||||
case .networkStatuses: return "networkStatuses"
|
||||
case .groupSubscribed: return "groupSubscribed"
|
||||
@@ -885,9 +877,6 @@ public enum ChatResponse: Decodable, Error {
|
||||
case .contactRequestRejected: return noDetails
|
||||
case let .contactUpdated(u, toContact): return withUser(u, String(describing: toContact))
|
||||
case let .groupMemberUpdated(u, groupInfo, fromMember, toMember): return withUser(u, "groupInfo: \(groupInfo)\nfromMember: \(fromMember)\ntoMember: \(toMember)")
|
||||
case let .contactsSubscribed(server, contactRefs): return "server: \(server)\ncontacts:\n\(String(describing: contactRefs))"
|
||||
case let .contactsDisconnected(server, contactRefs): return "server: \(server)\ncontacts:\n\(String(describing: contactRefs))"
|
||||
case let .contactSubSummary(u, contactSubscriptions): return withUser(u, String(describing: contactSubscriptions))
|
||||
case let .networkStatus(status, conns): return "networkStatus: \(String(describing: status))\nconnections: \(String(describing: conns))"
|
||||
case let .networkStatuses(u, statuses): return withUser(u, String(describing: statuses))
|
||||
case let .groupSubscribed(u, groupInfo): return withUser(u, String(describing: groupInfo))
|
||||
|
||||
@@ -52,6 +52,10 @@ func getAppDirectory() -> URL {
|
||||
|
||||
let DB_FILE_PREFIX = "simplex_v1"
|
||||
|
||||
let DEBUG_PROFILE_PREFIX = "simplex_debug"
|
||||
|
||||
let DEBUG_PROFILE_EXTENSION = ".hp"
|
||||
|
||||
func getLegacyDatabasePath() -> URL {
|
||||
getDocumentsDirectory().appendingPathComponent("mobile_v1", isDirectory: false)
|
||||
}
|
||||
@@ -62,6 +66,18 @@ public func getAppDatabasePath() -> URL {
|
||||
: getLegacyDatabasePath()
|
||||
}
|
||||
|
||||
public func getAppDebugProfilePrefixPath() -> URL {
|
||||
getAppDirectory().appendingPathComponent(DEBUG_PROFILE_PREFIX, isDirectory: false)
|
||||
}
|
||||
|
||||
public func getAppDebugProfilePath() -> URL {
|
||||
getAppDirectory().appendingPathComponent(DEBUG_PROFILE_PREFIX + DEBUG_PROFILE_EXTENSION, isDirectory: false)
|
||||
}
|
||||
|
||||
public func getAppEventLogPath() -> URL {
|
||||
getAppDirectory().appendingPathComponent("simplex.eventlog", isDirectory: false)
|
||||
}
|
||||
|
||||
func fileModificationDate(_ path: String) -> Date? {
|
||||
do {
|
||||
let attr = try FileManager.default.attributesOfItem(atPath: path)
|
||||
|
||||
@@ -7,19 +7,36 @@
|
||||
//
|
||||
|
||||
#include "hs_init.h"
|
||||
#include <string.h>
|
||||
|
||||
extern void hs_init_with_rtsopts(int * argc, char **argv[]);
|
||||
|
||||
void haskell_init(void) {
|
||||
int argc = 5;
|
||||
char *argv[] = {
|
||||
"simplex",
|
||||
"+RTS", // requires `hs_init_with_rtsopts`
|
||||
"-A64m", // chunk size for new allocations
|
||||
"-H64m", // initial heap size
|
||||
"-xn", // non-moving GC
|
||||
0
|
||||
};
|
||||
void haskell_init(const char *eventlog, const char *heap_profile) {
|
||||
// setup static arena for bump allocation and passing to RTS
|
||||
char *argv[32] = {0,};
|
||||
int argc = 0; // number of arguments used so far, always stands at the first NULL in argv
|
||||
// common args
|
||||
argv[argc++] = "simplex"; // fake program name
|
||||
argv[argc++] = "+RTS"; // start adding RTS options
|
||||
argv[argc++] = "-T"; // make GC counters available from inside the program
|
||||
argv[argc++] = "-A64m"; // chunk size for new allocations (less frequent GC)
|
||||
argv[argc++] = "-H64m"; // larger heap size on start (faster boot)
|
||||
// argv[argc++] = "-M8G"; // keep memory usage under 8G, collecting more aggressively when approaching it (and crashing sooner rather than taking down the whole system)
|
||||
if (eventlog) {
|
||||
static char ol[1024] = "-ol";
|
||||
(void)strncpy(&ol[3], eventlog, sizeof(ol) - 3);
|
||||
argv[argc++] = ol;
|
||||
argv[argc++] = "-l-agu"; // collect GC and user events
|
||||
}
|
||||
if (heap_profile) {
|
||||
static char po[1024] = "-po";
|
||||
(void)strncpy(&po[3], heap_profile, sizeof(po) - 3);
|
||||
argv[argc++] = po; // adds ".hp" extension
|
||||
argv[argc++] = "-hT"; // emit heap profile by closure type
|
||||
}
|
||||
int non_moving_gc = !heap_profile; // not compatible with heap profile
|
||||
if (non_moving_gc) argv[argc++] = "-xn";
|
||||
// wrap args as expected by RTS
|
||||
char **pargv = argv;
|
||||
hs_init_with_rtsopts(&argc, &pargv);
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
#ifndef hs_init_h
|
||||
#define hs_init_h
|
||||
|
||||
void haskell_init(void);
|
||||
void haskell_init(const char *eventlog, const char *heap_profile);
|
||||
|
||||
void haskell_init_nse(void);
|
||||
|
||||
|
||||
+2
@@ -1753,6 +1753,8 @@ object ChatController {
|
||||
chatModel.removeChat(rhId, r.mergedContact.id)
|
||||
}
|
||||
}
|
||||
// ContactsSubscribed, ContactsDisconnected and ContactSubSummary are only used in CLI,
|
||||
// They have to be used here for remote desktop to process these status updates.
|
||||
is CR.ContactsSubscribed -> updateContactsStatus(r.contactRefs, NetworkStatus.Connected())
|
||||
is CR.ContactsDisconnected -> updateContactsStatus(r.contactRefs, NetworkStatus.Disconnected())
|
||||
is CR.ContactSubSummary -> {
|
||||
|
||||
+1
-1
@@ -12,7 +12,7 @@ constraints: zip +disable-bzip2 +disable-zstd
|
||||
source-repository-package
|
||||
type: git
|
||||
location: https://github.com/simplex-chat/simplexmq.git
|
||||
tag: 8f12555be5054a04cca88acf443f307af4ee84d8
|
||||
tag: ee90ea6a69fe8283d37d9821cd83798fd0a76260
|
||||
|
||||
source-repository-package
|
||||
type: git
|
||||
|
||||
+4
-5
@@ -1,4 +1,3 @@
|
||||
{-# LANGUAGE BangPatterns #-}
|
||||
{-# LANGUAGE DataKinds #-}
|
||||
{-# LANGUAGE DuplicateRecordFields #-}
|
||||
{-# LANGUAGE FlexibleContexts #-}
|
||||
@@ -3011,10 +3010,11 @@ subscribeUserConnections :: forall m. ChatMonad m => (PQSupport -> VersionRangeC
|
||||
subscribeUserConnections vr onlyNeeded agentBatchSubscribe user = do
|
||||
-- get user connections
|
||||
ce <- asks $ subscriptionEvents . config
|
||||
(!conns, !cts, !ucs, !gs, !ms, !sfts, !rfts, !pcs) <-
|
||||
(conns, cts, ucs, gs, ms, sfts, rfts, pcs) <-
|
||||
if onlyNeeded
|
||||
then do
|
||||
(conns, (cts, ucs, ms, sfts, rfts, pcs)) <- withStore' $ \db -> getConnectionsToSubscribe db vr initialEntities addEntity
|
||||
(conns, entities) <- withStore' (`getConnectionsToSubscribe` vr)
|
||||
let (cts, ucs, ms, sfts, rfts, pcs) = foldl' addEntity (M.empty, M.empty, M.empty, M.empty, M.empty, M.empty) entities
|
||||
pure (conns, cts, ucs, [], ms, sfts, rfts, pcs)
|
||||
else do
|
||||
withStore' unsetConnectionToSubscribe
|
||||
@@ -3037,8 +3037,7 @@ subscribeUserConnections vr onlyNeeded agentBatchSubscribe user = do
|
||||
rcvFileSubsToView rs rfts
|
||||
pendingConnSubsToView rs pcs
|
||||
where
|
||||
initialEntities = (M.empty, M.empty, M.empty, M.empty, M.empty, M.empty)
|
||||
addEntity (!cts, !ucs, !ms, !sfts, !rfts, !pcs) = \case
|
||||
addEntity (cts, ucs, ms, sfts, rfts, pcs) = \case
|
||||
RcvDirectMsgConnection c (Just ct) -> let cts' = addConn c ct cts in (cts', ucs, ms, sfts, rfts, pcs)
|
||||
RcvDirectMsgConnection c Nothing -> let pcs' = addConn c (toPCC c) pcs in (cts, ucs, ms, sfts, rfts, pcs')
|
||||
RcvGroupMsgConnection c _g m -> let ms' = addConn c m ms in (cts, ucs, ms', sfts, rfts, pcs)
|
||||
|
||||
@@ -189,18 +189,16 @@ getContactConnEntityByConnReqHash db vr user@User {userId} (cReqHash1, cReqHash2
|
||||
(userId, cReqHash1, cReqHash2, ConnDeleted)
|
||||
maybe (pure Nothing) (fmap eitherToMaybe . runExceptT . getConnectionEntity db vr user) connId_
|
||||
|
||||
getConnectionsToSubscribe :: DB.Connection -> (PQSupport -> VersionRangeChat) -> es -> (es -> ConnectionEntity -> es) -> IO ([ConnId], es)
|
||||
getConnectionsToSubscribe db vr initialES addEntity = do
|
||||
r <- DB.fold_ db "SELECT agent_conn_id FROM connections where to_subscribe = 1" ([], initialES) collect
|
||||
r <$ unsetConnectionToSubscribe db
|
||||
where
|
||||
collect (cids, es) (Only acId@(AgentConnId connId)) = do
|
||||
es' <- getUserByAConnId db acId >>= \case
|
||||
Just user -> runExceptT (getConnectionEntity db vr user acId) >>= \case
|
||||
Right ce -> pure $! addEntity es ce
|
||||
Left _err -> pure es
|
||||
Nothing -> pure es
|
||||
pure (connId : cids, es')
|
||||
getConnectionsToSubscribe :: DB.Connection -> (PQSupport -> VersionRangeChat) -> IO ([ConnId], [ConnectionEntity])
|
||||
getConnectionsToSubscribe db vr = do
|
||||
aConnIds <- map fromOnly <$> DB.query_ db "SELECT agent_conn_id FROM connections where to_subscribe = 1"
|
||||
entities <- forM aConnIds $ \acId -> do
|
||||
getUserByAConnId db acId >>= \case
|
||||
Just user -> eitherToMaybe <$> runExceptT (getConnectionEntity db vr user acId)
|
||||
Nothing -> pure Nothing
|
||||
unsetConnectionToSubscribe db
|
||||
let connIds = map (\(AgentConnId connId) -> connId) aConnIds
|
||||
pure (connIds, catMaybes entities)
|
||||
|
||||
unsetConnectionToSubscribe :: DB.Connection -> IO ()
|
||||
unsetConnectionToSubscribe db = DB.execute_ db "UPDATE connections SET to_subscribe = 0 WHERE to_subscribe = 1"
|
||||
|
||||
Reference in New Issue
Block a user