From 718e19dd82b0e4b807a8074dfcb3c89708bae9b6 Mon Sep 17 00:00:00 2001 From: Volodymyr Hryhoriev Date: Mon, 12 Mar 2018 14:17:15 +0200 Subject: [PATCH 1/7] Implement 'fetch user by username from DB' feature. --- Nynja/ChatService.swift | 2 +- Nynja/ContactDAO.swift | 14 +++++++++++++- Nynja/ContactDAOProtocol.swift | 3 ++- .../AddContactByUsernameInteractor.swift | 19 +++---------------- .../Interactor/MyGroupAliasInteractor.swift | 2 +- .../Interactor/OtherUserInteractor.swift | 2 +- .../Profile/Presenter/ScheduledMessage.swift | 2 +- .../Interactor/RepliesInteractor.swift | 4 ++-- .../Interactor/SettingsGroupInteractor.swift | 2 +- 9 files changed, 25 insertions(+), 25 deletions(-) diff --git a/Nynja/ChatService.swift b/Nynja/ChatService.swift index cb8765a90..99ffbe0a1 100644 --- a/Nynja/ChatService.swift +++ b/Nynja/ChatService.swift @@ -27,7 +27,7 @@ class ChatService { static func fetchChatModel(from message: Message) throws -> AnyObject? { if let p = message.feed_id as? p2p { - if let target = p.reciever(for: StorageService.sharedInstance.phoneId), let contact = ContactDAO.findContact(by: target) { + if let target = p.reciever(for: StorageService.sharedInstance.phoneId), let contact = ContactDAO.findContactBy(phoneId: target) { return contact } } diff --git a/Nynja/ContactDAO.swift b/Nynja/ContactDAO.swift index 8c8ed981c..a8bced0b5 100644 --- a/Nynja/ContactDAO.swift +++ b/Nynja/ContactDAO.swift @@ -29,7 +29,7 @@ class ContactDAO: ContactDAOProtocol { } } - static func findContact(by phoneId: String) -> Contact? { + static func findContactBy(phoneId: String) -> Contact? { do { guard let dbContact = try fetchContact(by: phoneId) else { return nil } return Contact(contact: dbContact) @@ -38,6 +38,18 @@ class ContactDAO: ContactDAOProtocol { } } + static func findContactBy(username: String) -> Contact? { + let nickColumn = Column(ContactTable.Column.nick.title) + + guard let contact = dbManager.fetch({ db in + return try DBContact.filter(nickColumn == username).fetchOne(db) + }) else { + return nil + } + + return Contact(contact: contact) + } + // MARK: -- Contacts static func fetchContacts() -> [Contact] { diff --git a/Nynja/ContactDAOProtocol.swift b/Nynja/ContactDAOProtocol.swift index 1493c15d0..735aa2bb7 100644 --- a/Nynja/ContactDAOProtocol.swift +++ b/Nynja/ContactDAOProtocol.swift @@ -13,7 +13,8 @@ protocol ContactDAOProtocol: DAOProtocol { static func fetchContact(by id: String) throws -> DBContact? static func fetchContact(by rowId: Int64) throws -> DBContact? - static func findContact(by phoneId: String) -> Contact? + static func findContactBy(phoneId: String) -> Contact? + static func findContactBy(username: String) -> Contact? // MARK: -- Contacts static func fetchContacts() -> [Contact] diff --git a/Nynja/Modules/AddContactByUsername/Interactor/AddContactByUsernameInteractor.swift b/Nynja/Modules/AddContactByUsername/Interactor/AddContactByUsernameInteractor.swift index eac602d5c..a891143aa 100644 --- a/Nynja/Modules/AddContactByUsername/Interactor/AddContactByUsernameInteractor.swift +++ b/Nynja/Modules/AddContactByUsername/Interactor/AddContactByUsernameInteractor.swift @@ -15,28 +15,14 @@ class AddContactByUsernameInteractor: AddContactByUsernameInteractorInputProtoco } func getContactByUserName(username: String) { - if let contact = findContactInRoster(username: username) { + if let contact = ContactDAO.findContactBy(username: username) { self.presenter.getContactSuccess(contact: contact) } else { MQTTService.sharedInstance.searchContactByUsername(nick: username) } } - func findContactInRoster(username: String) -> Contact? { - if let rosters = (StorageService.sharedInstance.profile.rosters as? [Roster]) { - if rosters.count > 0 { - if let contacts = rosters[0].userlist { - for contact in contacts { - if contact.nick == username { - return Contact(contact: contact) - } - } - } - } - } - return nil - } - + // MARK: - IoHandlerDelegate func getContactByUsernameSucces(contact: Contact) { self.presenter.getContactSuccess(contact: contact) } @@ -44,4 +30,5 @@ class AddContactByUsernameInteractor: AddContactByUsernameInteractorInputProtoco func contactByUsernameNotFound() { self.presenter.getContactFailed() } + } diff --git a/Nynja/Modules/MyGroupAlias/Interactor/MyGroupAliasInteractor.swift b/Nynja/Modules/MyGroupAlias/Interactor/MyGroupAliasInteractor.swift index 44d05bc26..c4fcf9495 100644 --- a/Nynja/Modules/MyGroupAlias/Interactor/MyGroupAliasInteractor.swift +++ b/Nynja/Modules/MyGroupAlias/Interactor/MyGroupAliasInteractor.swift @@ -26,7 +26,7 @@ class MyGroupAliasInteractor: BaseInteractor, MyGroupAliasInteractorInputProtoco func checkAlias(_ alias: String) { var myNick = "" - if let phoneId = StorageService.sharedInstance.phoneId, let myContact = ContactDAO.findContact(by: phoneId) { + if let phoneId = StorageService.sharedInstance.phoneId, let myContact = ContactDAO.findContactBy(phoneId: phoneId) { myNick = Member(contact: myContact).alias ?? "" } nicks.forEach { diff --git a/Nynja/Modules/OtherUser/Interactor/OtherUserInteractor.swift b/Nynja/Modules/OtherUser/Interactor/OtherUserInteractor.swift index 15ca4a4bf..de14a9e07 100644 --- a/Nynja/Modules/OtherUser/Interactor/OtherUserInteractor.swift +++ b/Nynja/Modules/OtherUser/Interactor/OtherUserInteractor.swift @@ -30,7 +30,7 @@ class OtherUserInteractor: BaseInteractor, OtherUserInteractorInputProtocol { super.loadData() if contact == nil { guard let contactId = UserDefaults.standard.string(forKey: String(SharedParameters.contactId.rawValue)), - let localContact = ContactDAO.findContact(by: contactId) else { + let localContact = ContactDAO.findContactBy(phoneId: contactId) else { return } contact = localContact diff --git a/Nynja/Modules/Profile/Presenter/ScheduledMessage.swift b/Nynja/Modules/Profile/Presenter/ScheduledMessage.swift index c32057081..2d4fd3bca 100644 --- a/Nynja/Modules/Profile/Presenter/ScheduledMessage.swift +++ b/Nynja/Modules/Profile/Presenter/ScheduledMessage.swift @@ -19,7 +19,7 @@ class ScheduledMessage : CellModel { self.job = job guard let messages = job.data, !messages.isEmpty else { return } if let message = messages.first { - if let p2p = message.feed_id as? p2p, let phoneId = message.to, let contact = ContactDAO.findContact(by: phoneId) { + if let p2p = message.feed_id as? p2p, let phoneId = message.to, let contact = ContactDAO.findContactBy(phoneId: phoneId) { self.title = contact.fullName self.photoURL = contact.avatarUrl } else if let roomId = message.to, let room = RoomDAO.findRoom(by: roomId) { diff --git a/Nynja/Modules/Replies/Interactor/RepliesInteractor.swift b/Nynja/Modules/Replies/Interactor/RepliesInteractor.swift index ae0ba01f5..9b6ce4cf7 100644 --- a/Nynja/Modules/Replies/Interactor/RepliesInteractor.swift +++ b/Nynja/Modules/Replies/Interactor/RepliesInteractor.swift @@ -92,10 +92,10 @@ class RepliesInteractor: BaseInteractor, RepliesInteractorInputProtocol, Message if let _ = (message.feed_id as? muc), let member = member(for: message) { return MessageSender(fullname: member.fullName ?? "", nick: member.alias, avatar: member.avatar) } else { - if isOwner, let phoneId = StorageService.sharedInstance.phoneId, let myContact = ContactDAO.findContact(by: phoneId) { + if isOwner, let phoneId = StorageService.sharedInstance.phoneId, let myContact = ContactDAO.findContactBy(phoneId: phoneId) { return MessageSender(fullname: myContact.fullName ?? "", nick: myContact.nick, avatar: myContact.avatar) } else { - if let to = (message.feed_id as? p2p)?.to, let contact = ContactDAO.findContact(by: to) { + if let to = (message.feed_id as? p2p)?.to, let contact = ContactDAO.findContactBy(phoneId: to) { return MessageSender(fullname: contact.fullName ?? "", nick: contact.nick, avatar: contact.avatar) } } diff --git a/Nynja/Modules/SettingsGroup/Interactor/SettingsGroupInteractor.swift b/Nynja/Modules/SettingsGroup/Interactor/SettingsGroupInteractor.swift index 66fe5e5c2..485bb6a3c 100644 --- a/Nynja/Modules/SettingsGroup/Interactor/SettingsGroupInteractor.swift +++ b/Nynja/Modules/SettingsGroup/Interactor/SettingsGroupInteractor.swift @@ -87,7 +87,7 @@ class SettingsGroupInteractor: BaseInteractor, SettingsGroupInteractorInputProto } func clearHistory(_ id: String) { - guard let phoneId = StorageService.sharedInstance.phoneId, let me = ContactDAO.findContact(by: phoneId) else { + guard let phoneId = StorageService.sharedInstance.phoneId, let me = ContactDAO.findContactBy(phoneId: phoneId) else { presenter?.showError("No info about me") return } -- GitLab From 4a271e5e3ab2cf2338506e67911b79e93b46a9d0 Mon Sep 17 00:00:00 2001 From: Volodymyr Hryhoriev Date: Tue, 13 Mar 2018 12:50:21 +0200 Subject: [PATCH 2/7] Move Source, Model and Spec groups to ServerModel. --- Nynja.xcodeproj/project.pbxproj | 23 +++++++++++-------- .../{Library => ServerModel}/Model/Auth.swift | 0 .../{Library => ServerModel}/Model/CDR.swift | 0 .../Model/Contact.swift | 0 .../Model/Cursor.swift | 0 .../{Library => ServerModel}/Model/Desc.swift | 0 .../Model/ExtendedStar.swift | 0 .../Model/Feature.swift | 0 .../Model/Friend.swift | 0 .../Model/History.swift | 0 .../Model/Index.swift | 0 .../{Library => ServerModel}/Model/Job.swift | 0 .../{Library => ServerModel}/Model/Loc.swift | 0 .../Model/Member.swift | 0 .../Model/Message.swift | 0 .../Model/Person.swift | 0 .../Model/Profile.swift | 0 .../{Library => ServerModel}/Model/Room.swift | 0 .../Model/Roster.swift | 0 .../Model/Search.swift | 0 .../Model/Service.swift | 0 .../{Library => ServerModel}/Model/Star.swift | 0 .../{Library => ServerModel}/Model/Tag.swift | 0 .../{Library => ServerModel}/Model/Task.swift | 0 .../{Library => ServerModel}/Model/Test.swift | 0 .../Model/Typing.swift | 0 .../{Library => ServerModel}/Model/Vox.swift | 0 .../{Library => ServerModel}/Model/act.swift | 0 .../Model/boundaryEvent.swift | 0 .../Model/chain.swift | 0 .../Model/container.swift | 0 .../{Library => ServerModel}/Model/cur.swift | 0 .../Model/error.swift | 0 .../Model/error2.swift | 0 Nynja/{Library => ServerModel}/Model/io.swift | 0 .../{Library => ServerModel}/Model/iter.swift | 0 .../Model/iterator.swift | 0 .../{Library => ServerModel}/Model/log.swift | 0 .../Model/messageEvent.swift | 0 .../{Library => ServerModel}/Model/muc.swift | 0 Nynja/{Library => ServerModel}/Model/ok.swift | 0 .../{Library => ServerModel}/Model/ok2.swift | 0 .../Model/operation.swift | 0 .../{Library => ServerModel}/Model/p2p.swift | 0 .../Model/process.swift | 0 .../{Library => ServerModel}/Model/push.swift | 0 .../Model/reader.swift | 0 .../Model/receiveTask.swift | 0 .../Model/sequenceFlow.swift | 0 .../Model/serviceTask.swift | 0 .../Model/timeoutEvent.swift | 0 .../Model/userTask.swift | 0 .../Model/writer.swift | 0 .../Source/Decoder.swift | 0 .../Source/StringAtom.swift | 0 .../Source/TypeSpec.swift | 0 .../Spec/Auth_Spec.swift | 0 .../Spec/CDR_Spec.swift | 0 .../Spec/Contact_Spec.swift | 0 .../Spec/Cursor_Spec.swift | 0 .../Spec/Desc_Spec.swift | 0 .../Spec/ExtendedStar_Spec.swift | 0 .../Spec/Feature_Spec.swift | 0 .../Spec/Friend_Spec.swift | 0 .../Spec/History_Spec.swift | 0 .../Spec/Index_Spec.swift | 0 .../Spec/Job_Spec.swift | 0 .../Spec/Loc_Spec.swift | 0 .../Spec/Member_Spec.swift | 0 .../Spec/Message_Spec.swift | 0 .../Spec/Person_Spec.swift | 0 .../Spec/Profile_Spec.swift | 0 .../Spec/Room_Spec.swift | 0 .../Spec/Roster_Spec.swift | 0 .../Spec/Search_Spec.swift | 0 .../Spec/Service_Spec.swift | 0 .../Spec/Star_Spec.swift | 0 .../Spec/Tag_Spec.swift | 0 .../Spec/Test_Spec.swift | 0 .../Spec/Typing_Spec.swift | 0 .../Spec/Vox_Spec.swift | 0 .../Spec/act_Spec.swift | 0 .../Spec/boundaryEvent_Spec.swift | 0 .../Spec/chain_Spec.swift | 0 .../Spec/container_Spec.swift | 0 .../Spec/cur_Spec.swift | 0 .../Spec/error2_Spec.swift | 0 .../Spec/error_Spec.swift | 0 .../Spec/io_Spec.swift | 0 .../Spec/iter_Spec.swift | 0 .../Spec/iterator_Spec.swift | 0 .../Spec/log_Spec.swift | 0 .../Spec/messageEvent_Spec.swift | 0 .../Spec/muc_Spec.swift | 0 .../Spec/ok2_Spec.swift | 0 .../Spec/ok_Spec.swift | 0 .../Spec/operation_Spec.swift | 0 .../Spec/p2p_Spec.swift | 0 .../Spec/process_Spec.swift | 0 .../Spec/push_Spec.swift | 0 .../Spec/reader_Spec.swift | 0 .../Spec/receiveTask_Spec.swift | 0 .../Spec/sequenceFlow_Spec.swift | 0 .../Spec/serviceTask_Spec.swift | 0 .../Spec/task_Spec.swift | 0 .../Spec/timeoutEvent_Spec.swift | 0 .../Spec/userTask_Spec.swift | 0 .../Spec/writer_Spec.swift | 0 108 files changed, 14 insertions(+), 9 deletions(-) rename Nynja/{Library => ServerModel}/Model/Auth.swift (100%) rename Nynja/{Library => ServerModel}/Model/CDR.swift (100%) rename Nynja/{Library => ServerModel}/Model/Contact.swift (100%) rename Nynja/{Library => ServerModel}/Model/Cursor.swift (100%) rename Nynja/{Library => ServerModel}/Model/Desc.swift (100%) rename Nynja/{Library => ServerModel}/Model/ExtendedStar.swift (100%) rename Nynja/{Library => ServerModel}/Model/Feature.swift (100%) rename Nynja/{Library => ServerModel}/Model/Friend.swift (100%) rename Nynja/{Library => ServerModel}/Model/History.swift (100%) rename Nynja/{Library => ServerModel}/Model/Index.swift (100%) rename Nynja/{Library => ServerModel}/Model/Job.swift (100%) rename Nynja/{Library => ServerModel}/Model/Loc.swift (100%) rename Nynja/{Library => ServerModel}/Model/Member.swift (100%) rename Nynja/{Library => ServerModel}/Model/Message.swift (100%) rename Nynja/{Library => ServerModel}/Model/Person.swift (100%) rename Nynja/{Library => ServerModel}/Model/Profile.swift (100%) rename Nynja/{Library => ServerModel}/Model/Room.swift (100%) rename Nynja/{Library => ServerModel}/Model/Roster.swift (100%) rename Nynja/{Library => ServerModel}/Model/Search.swift (100%) rename Nynja/{Library => ServerModel}/Model/Service.swift (100%) rename Nynja/{Library => ServerModel}/Model/Star.swift (100%) rename Nynja/{Library => ServerModel}/Model/Tag.swift (100%) rename Nynja/{Library => ServerModel}/Model/Task.swift (100%) rename Nynja/{Library => ServerModel}/Model/Test.swift (100%) rename Nynja/{Library => ServerModel}/Model/Typing.swift (100%) rename Nynja/{Library => ServerModel}/Model/Vox.swift (100%) rename Nynja/{Library => ServerModel}/Model/act.swift (100%) rename Nynja/{Library => ServerModel}/Model/boundaryEvent.swift (100%) rename Nynja/{Library => ServerModel}/Model/chain.swift (100%) rename Nynja/{Library => ServerModel}/Model/container.swift (100%) rename Nynja/{Library => ServerModel}/Model/cur.swift (100%) rename Nynja/{Library => ServerModel}/Model/error.swift (100%) rename Nynja/{Library => ServerModel}/Model/error2.swift (100%) rename Nynja/{Library => ServerModel}/Model/io.swift (100%) rename Nynja/{Library => ServerModel}/Model/iter.swift (100%) rename Nynja/{Library => ServerModel}/Model/iterator.swift (100%) rename Nynja/{Library => ServerModel}/Model/log.swift (100%) rename Nynja/{Library => ServerModel}/Model/messageEvent.swift (100%) rename Nynja/{Library => ServerModel}/Model/muc.swift (100%) rename Nynja/{Library => ServerModel}/Model/ok.swift (100%) rename Nynja/{Library => ServerModel}/Model/ok2.swift (100%) rename Nynja/{Library => ServerModel}/Model/operation.swift (100%) rename Nynja/{Library => ServerModel}/Model/p2p.swift (100%) rename Nynja/{Library => ServerModel}/Model/process.swift (100%) rename Nynja/{Library => ServerModel}/Model/push.swift (100%) rename Nynja/{Library => ServerModel}/Model/reader.swift (100%) rename Nynja/{Library => ServerModel}/Model/receiveTask.swift (100%) rename Nynja/{Library => ServerModel}/Model/sequenceFlow.swift (100%) rename Nynja/{Library => ServerModel}/Model/serviceTask.swift (100%) rename Nynja/{Library => ServerModel}/Model/timeoutEvent.swift (100%) rename Nynja/{Library => ServerModel}/Model/userTask.swift (100%) rename Nynja/{Library => ServerModel}/Model/writer.swift (100%) rename Nynja/{Library => ServerModel}/Source/Decoder.swift (100%) rename Nynja/{Library => ServerModel}/Source/StringAtom.swift (100%) rename Nynja/{Library => ServerModel}/Source/TypeSpec.swift (100%) rename Nynja/{Library => ServerModel}/Spec/Auth_Spec.swift (100%) rename Nynja/{Library => ServerModel}/Spec/CDR_Spec.swift (100%) rename Nynja/{Library => ServerModel}/Spec/Contact_Spec.swift (100%) rename Nynja/{Library => ServerModel}/Spec/Cursor_Spec.swift (100%) rename Nynja/{Library => ServerModel}/Spec/Desc_Spec.swift (100%) rename Nynja/{Library => ServerModel}/Spec/ExtendedStar_Spec.swift (100%) rename Nynja/{Library => ServerModel}/Spec/Feature_Spec.swift (100%) rename Nynja/{Library => ServerModel}/Spec/Friend_Spec.swift (100%) rename Nynja/{Library => ServerModel}/Spec/History_Spec.swift (100%) rename Nynja/{Library => ServerModel}/Spec/Index_Spec.swift (100%) rename Nynja/{Library => ServerModel}/Spec/Job_Spec.swift (100%) rename Nynja/{Library => ServerModel}/Spec/Loc_Spec.swift (100%) rename Nynja/{Library => ServerModel}/Spec/Member_Spec.swift (100%) rename Nynja/{Library => ServerModel}/Spec/Message_Spec.swift (100%) rename Nynja/{Library => ServerModel}/Spec/Person_Spec.swift (100%) rename Nynja/{Library => ServerModel}/Spec/Profile_Spec.swift (100%) rename Nynja/{Library => ServerModel}/Spec/Room_Spec.swift (100%) rename Nynja/{Library => ServerModel}/Spec/Roster_Spec.swift (100%) rename Nynja/{Library => ServerModel}/Spec/Search_Spec.swift (100%) rename Nynja/{Library => ServerModel}/Spec/Service_Spec.swift (100%) rename Nynja/{Library => ServerModel}/Spec/Star_Spec.swift (100%) rename Nynja/{Library => ServerModel}/Spec/Tag_Spec.swift (100%) rename Nynja/{Library => ServerModel}/Spec/Test_Spec.swift (100%) rename Nynja/{Library => ServerModel}/Spec/Typing_Spec.swift (100%) rename Nynja/{Library => ServerModel}/Spec/Vox_Spec.swift (100%) rename Nynja/{Library => ServerModel}/Spec/act_Spec.swift (100%) rename Nynja/{Library => ServerModel}/Spec/boundaryEvent_Spec.swift (100%) rename Nynja/{Library => ServerModel}/Spec/chain_Spec.swift (100%) rename Nynja/{Library => ServerModel}/Spec/container_Spec.swift (100%) rename Nynja/{Library => ServerModel}/Spec/cur_Spec.swift (100%) rename Nynja/{Library => ServerModel}/Spec/error2_Spec.swift (100%) rename Nynja/{Library => ServerModel}/Spec/error_Spec.swift (100%) rename Nynja/{Library => ServerModel}/Spec/io_Spec.swift (100%) rename Nynja/{Library => ServerModel}/Spec/iter_Spec.swift (100%) rename Nynja/{Library => ServerModel}/Spec/iterator_Spec.swift (100%) rename Nynja/{Library => ServerModel}/Spec/log_Spec.swift (100%) rename Nynja/{Library => ServerModel}/Spec/messageEvent_Spec.swift (100%) rename Nynja/{Library => ServerModel}/Spec/muc_Spec.swift (100%) rename Nynja/{Library => ServerModel}/Spec/ok2_Spec.swift (100%) rename Nynja/{Library => ServerModel}/Spec/ok_Spec.swift (100%) rename Nynja/{Library => ServerModel}/Spec/operation_Spec.swift (100%) rename Nynja/{Library => ServerModel}/Spec/p2p_Spec.swift (100%) rename Nynja/{Library => ServerModel}/Spec/process_Spec.swift (100%) rename Nynja/{Library => ServerModel}/Spec/push_Spec.swift (100%) rename Nynja/{Library => ServerModel}/Spec/reader_Spec.swift (100%) rename Nynja/{Library => ServerModel}/Spec/receiveTask_Spec.swift (100%) rename Nynja/{Library => ServerModel}/Spec/sequenceFlow_Spec.swift (100%) rename Nynja/{Library => ServerModel}/Spec/serviceTask_Spec.swift (100%) rename Nynja/{Library => ServerModel}/Spec/task_Spec.swift (100%) rename Nynja/{Library => ServerModel}/Spec/timeoutEvent_Spec.swift (100%) rename Nynja/{Library => ServerModel}/Spec/userTask_Spec.swift (100%) rename Nynja/{Library => ServerModel}/Spec/writer_Spec.swift (100%) diff --git a/Nynja.xcodeproj/project.pbxproj b/Nynja.xcodeproj/project.pbxproj index 0e049d84d..e25e8c047 100644 --- a/Nynja.xcodeproj/project.pbxproj +++ b/Nynja.xcodeproj/project.pbxproj @@ -3170,6 +3170,7 @@ 3A768DE41ECB3E7600108F7C /* Library */ = { isa = PBXGroup; children = ( + A44A2C962057E3E8009863B6 /* ServerModel */, 4B1D7E12202A09E200703228 /* Viper */, 4B736D4820238FA40028F2CB /* ThumbnailGenerator.swift */, 2648B14F1FEAA889007F2AAE /* IdGenerator.swift */, @@ -3180,9 +3181,6 @@ 85F3DD45203F411B00F210C0 /* Utils */, E7A77FD61FACC34F004AE609 /* Extensions */, 3A1C87411F6101A50029B0BC /* Reachability.swift */, - 3AA13C161F21821800BE5D8F /* Spec */, - 3AA13C2B1F21821900BE5D8F /* Source */, - 3AA13C311F21821900BE5D8F /* Model */, 3A82187C1EDEEDF400337B05 /* UI */, 3A8045D91F60E18E00AED866 /* Queue.swift */, 266AE8C2203496B60096A12C /* AsyncOperation.swift */, @@ -3345,8 +3343,7 @@ 005886F42032065600FE2E89 /* boundaryEvent_Spec.swift */, 005886F62032068A00FE2E89 /* timeoutEvent_Spec.swift */, ); - name = Spec; - path = Library/Spec; + path = Spec; sourceTree = ""; }; 3AA13C2B1F21821900BE5D8F /* Source */ = { @@ -3357,8 +3354,7 @@ 3A36E5231F4C6A0F001427DF /* StringAtom.swift */, 3A768DE51ECB3E8D00108F7C /* Bert.swift */, ); - name = Source; - path = Library/Source; + path = Source; sourceTree = ""; }; 3AA13C311F21821900BE5D8F /* Model */ = { @@ -3417,8 +3413,7 @@ 005886E8203204EA00FE2E89 /* boundaryEvent.swift */, 005886EA2032053F00FE2E89 /* timeoutEvent.swift */, ); - name = Model; - path = Library/Model; + path = Model; sourceTree = ""; }; 3AB452082A8DAEAD93F689D8 /* Auth */ = { @@ -4838,6 +4833,16 @@ path = Presenter; sourceTree = ""; }; + A44A2C962057E3E8009863B6 /* ServerModel */ = { + isa = PBXGroup; + children = ( + 3AA13C161F21821800BE5D8F /* Spec */, + 3AA13C2B1F21821900BE5D8F /* Source */, + 3AA13C311F21821900BE5D8F /* Model */, + ); + path = ServerModel; + sourceTree = ""; + }; A4D0787972A19641165C28B6 /* WireFrame */ = { isa = PBXGroup; children = ( diff --git a/Nynja/Library/Model/Auth.swift b/Nynja/ServerModel/Model/Auth.swift similarity index 100% rename from Nynja/Library/Model/Auth.swift rename to Nynja/ServerModel/Model/Auth.swift diff --git a/Nynja/Library/Model/CDR.swift b/Nynja/ServerModel/Model/CDR.swift similarity index 100% rename from Nynja/Library/Model/CDR.swift rename to Nynja/ServerModel/Model/CDR.swift diff --git a/Nynja/Library/Model/Contact.swift b/Nynja/ServerModel/Model/Contact.swift similarity index 100% rename from Nynja/Library/Model/Contact.swift rename to Nynja/ServerModel/Model/Contact.swift diff --git a/Nynja/Library/Model/Cursor.swift b/Nynja/ServerModel/Model/Cursor.swift similarity index 100% rename from Nynja/Library/Model/Cursor.swift rename to Nynja/ServerModel/Model/Cursor.swift diff --git a/Nynja/Library/Model/Desc.swift b/Nynja/ServerModel/Model/Desc.swift similarity index 100% rename from Nynja/Library/Model/Desc.swift rename to Nynja/ServerModel/Model/Desc.swift diff --git a/Nynja/Library/Model/ExtendedStar.swift b/Nynja/ServerModel/Model/ExtendedStar.swift similarity index 100% rename from Nynja/Library/Model/ExtendedStar.swift rename to Nynja/ServerModel/Model/ExtendedStar.swift diff --git a/Nynja/Library/Model/Feature.swift b/Nynja/ServerModel/Model/Feature.swift similarity index 100% rename from Nynja/Library/Model/Feature.swift rename to Nynja/ServerModel/Model/Feature.swift diff --git a/Nynja/Library/Model/Friend.swift b/Nynja/ServerModel/Model/Friend.swift similarity index 100% rename from Nynja/Library/Model/Friend.swift rename to Nynja/ServerModel/Model/Friend.swift diff --git a/Nynja/Library/Model/History.swift b/Nynja/ServerModel/Model/History.swift similarity index 100% rename from Nynja/Library/Model/History.swift rename to Nynja/ServerModel/Model/History.swift diff --git a/Nynja/Library/Model/Index.swift b/Nynja/ServerModel/Model/Index.swift similarity index 100% rename from Nynja/Library/Model/Index.swift rename to Nynja/ServerModel/Model/Index.swift diff --git a/Nynja/Library/Model/Job.swift b/Nynja/ServerModel/Model/Job.swift similarity index 100% rename from Nynja/Library/Model/Job.swift rename to Nynja/ServerModel/Model/Job.swift diff --git a/Nynja/Library/Model/Loc.swift b/Nynja/ServerModel/Model/Loc.swift similarity index 100% rename from Nynja/Library/Model/Loc.swift rename to Nynja/ServerModel/Model/Loc.swift diff --git a/Nynja/Library/Model/Member.swift b/Nynja/ServerModel/Model/Member.swift similarity index 100% rename from Nynja/Library/Model/Member.swift rename to Nynja/ServerModel/Model/Member.swift diff --git a/Nynja/Library/Model/Message.swift b/Nynja/ServerModel/Model/Message.swift similarity index 100% rename from Nynja/Library/Model/Message.swift rename to Nynja/ServerModel/Model/Message.swift diff --git a/Nynja/Library/Model/Person.swift b/Nynja/ServerModel/Model/Person.swift similarity index 100% rename from Nynja/Library/Model/Person.swift rename to Nynja/ServerModel/Model/Person.swift diff --git a/Nynja/Library/Model/Profile.swift b/Nynja/ServerModel/Model/Profile.swift similarity index 100% rename from Nynja/Library/Model/Profile.swift rename to Nynja/ServerModel/Model/Profile.swift diff --git a/Nynja/Library/Model/Room.swift b/Nynja/ServerModel/Model/Room.swift similarity index 100% rename from Nynja/Library/Model/Room.swift rename to Nynja/ServerModel/Model/Room.swift diff --git a/Nynja/Library/Model/Roster.swift b/Nynja/ServerModel/Model/Roster.swift similarity index 100% rename from Nynja/Library/Model/Roster.swift rename to Nynja/ServerModel/Model/Roster.swift diff --git a/Nynja/Library/Model/Search.swift b/Nynja/ServerModel/Model/Search.swift similarity index 100% rename from Nynja/Library/Model/Search.swift rename to Nynja/ServerModel/Model/Search.swift diff --git a/Nynja/Library/Model/Service.swift b/Nynja/ServerModel/Model/Service.swift similarity index 100% rename from Nynja/Library/Model/Service.swift rename to Nynja/ServerModel/Model/Service.swift diff --git a/Nynja/Library/Model/Star.swift b/Nynja/ServerModel/Model/Star.swift similarity index 100% rename from Nynja/Library/Model/Star.swift rename to Nynja/ServerModel/Model/Star.swift diff --git a/Nynja/Library/Model/Tag.swift b/Nynja/ServerModel/Model/Tag.swift similarity index 100% rename from Nynja/Library/Model/Tag.swift rename to Nynja/ServerModel/Model/Tag.swift diff --git a/Nynja/Library/Model/Task.swift b/Nynja/ServerModel/Model/Task.swift similarity index 100% rename from Nynja/Library/Model/Task.swift rename to Nynja/ServerModel/Model/Task.swift diff --git a/Nynja/Library/Model/Test.swift b/Nynja/ServerModel/Model/Test.swift similarity index 100% rename from Nynja/Library/Model/Test.swift rename to Nynja/ServerModel/Model/Test.swift diff --git a/Nynja/Library/Model/Typing.swift b/Nynja/ServerModel/Model/Typing.swift similarity index 100% rename from Nynja/Library/Model/Typing.swift rename to Nynja/ServerModel/Model/Typing.swift diff --git a/Nynja/Library/Model/Vox.swift b/Nynja/ServerModel/Model/Vox.swift similarity index 100% rename from Nynja/Library/Model/Vox.swift rename to Nynja/ServerModel/Model/Vox.swift diff --git a/Nynja/Library/Model/act.swift b/Nynja/ServerModel/Model/act.swift similarity index 100% rename from Nynja/Library/Model/act.swift rename to Nynja/ServerModel/Model/act.swift diff --git a/Nynja/Library/Model/boundaryEvent.swift b/Nynja/ServerModel/Model/boundaryEvent.swift similarity index 100% rename from Nynja/Library/Model/boundaryEvent.swift rename to Nynja/ServerModel/Model/boundaryEvent.swift diff --git a/Nynja/Library/Model/chain.swift b/Nynja/ServerModel/Model/chain.swift similarity index 100% rename from Nynja/Library/Model/chain.swift rename to Nynja/ServerModel/Model/chain.swift diff --git a/Nynja/Library/Model/container.swift b/Nynja/ServerModel/Model/container.swift similarity index 100% rename from Nynja/Library/Model/container.swift rename to Nynja/ServerModel/Model/container.swift diff --git a/Nynja/Library/Model/cur.swift b/Nynja/ServerModel/Model/cur.swift similarity index 100% rename from Nynja/Library/Model/cur.swift rename to Nynja/ServerModel/Model/cur.swift diff --git a/Nynja/Library/Model/error.swift b/Nynja/ServerModel/Model/error.swift similarity index 100% rename from Nynja/Library/Model/error.swift rename to Nynja/ServerModel/Model/error.swift diff --git a/Nynja/Library/Model/error2.swift b/Nynja/ServerModel/Model/error2.swift similarity index 100% rename from Nynja/Library/Model/error2.swift rename to Nynja/ServerModel/Model/error2.swift diff --git a/Nynja/Library/Model/io.swift b/Nynja/ServerModel/Model/io.swift similarity index 100% rename from Nynja/Library/Model/io.swift rename to Nynja/ServerModel/Model/io.swift diff --git a/Nynja/Library/Model/iter.swift b/Nynja/ServerModel/Model/iter.swift similarity index 100% rename from Nynja/Library/Model/iter.swift rename to Nynja/ServerModel/Model/iter.swift diff --git a/Nynja/Library/Model/iterator.swift b/Nynja/ServerModel/Model/iterator.swift similarity index 100% rename from Nynja/Library/Model/iterator.swift rename to Nynja/ServerModel/Model/iterator.swift diff --git a/Nynja/Library/Model/log.swift b/Nynja/ServerModel/Model/log.swift similarity index 100% rename from Nynja/Library/Model/log.swift rename to Nynja/ServerModel/Model/log.swift diff --git a/Nynja/Library/Model/messageEvent.swift b/Nynja/ServerModel/Model/messageEvent.swift similarity index 100% rename from Nynja/Library/Model/messageEvent.swift rename to Nynja/ServerModel/Model/messageEvent.swift diff --git a/Nynja/Library/Model/muc.swift b/Nynja/ServerModel/Model/muc.swift similarity index 100% rename from Nynja/Library/Model/muc.swift rename to Nynja/ServerModel/Model/muc.swift diff --git a/Nynja/Library/Model/ok.swift b/Nynja/ServerModel/Model/ok.swift similarity index 100% rename from Nynja/Library/Model/ok.swift rename to Nynja/ServerModel/Model/ok.swift diff --git a/Nynja/Library/Model/ok2.swift b/Nynja/ServerModel/Model/ok2.swift similarity index 100% rename from Nynja/Library/Model/ok2.swift rename to Nynja/ServerModel/Model/ok2.swift diff --git a/Nynja/Library/Model/operation.swift b/Nynja/ServerModel/Model/operation.swift similarity index 100% rename from Nynja/Library/Model/operation.swift rename to Nynja/ServerModel/Model/operation.swift diff --git a/Nynja/Library/Model/p2p.swift b/Nynja/ServerModel/Model/p2p.swift similarity index 100% rename from Nynja/Library/Model/p2p.swift rename to Nynja/ServerModel/Model/p2p.swift diff --git a/Nynja/Library/Model/process.swift b/Nynja/ServerModel/Model/process.swift similarity index 100% rename from Nynja/Library/Model/process.swift rename to Nynja/ServerModel/Model/process.swift diff --git a/Nynja/Library/Model/push.swift b/Nynja/ServerModel/Model/push.swift similarity index 100% rename from Nynja/Library/Model/push.swift rename to Nynja/ServerModel/Model/push.swift diff --git a/Nynja/Library/Model/reader.swift b/Nynja/ServerModel/Model/reader.swift similarity index 100% rename from Nynja/Library/Model/reader.swift rename to Nynja/ServerModel/Model/reader.swift diff --git a/Nynja/Library/Model/receiveTask.swift b/Nynja/ServerModel/Model/receiveTask.swift similarity index 100% rename from Nynja/Library/Model/receiveTask.swift rename to Nynja/ServerModel/Model/receiveTask.swift diff --git a/Nynja/Library/Model/sequenceFlow.swift b/Nynja/ServerModel/Model/sequenceFlow.swift similarity index 100% rename from Nynja/Library/Model/sequenceFlow.swift rename to Nynja/ServerModel/Model/sequenceFlow.swift diff --git a/Nynja/Library/Model/serviceTask.swift b/Nynja/ServerModel/Model/serviceTask.swift similarity index 100% rename from Nynja/Library/Model/serviceTask.swift rename to Nynja/ServerModel/Model/serviceTask.swift diff --git a/Nynja/Library/Model/timeoutEvent.swift b/Nynja/ServerModel/Model/timeoutEvent.swift similarity index 100% rename from Nynja/Library/Model/timeoutEvent.swift rename to Nynja/ServerModel/Model/timeoutEvent.swift diff --git a/Nynja/Library/Model/userTask.swift b/Nynja/ServerModel/Model/userTask.swift similarity index 100% rename from Nynja/Library/Model/userTask.swift rename to Nynja/ServerModel/Model/userTask.swift diff --git a/Nynja/Library/Model/writer.swift b/Nynja/ServerModel/Model/writer.swift similarity index 100% rename from Nynja/Library/Model/writer.swift rename to Nynja/ServerModel/Model/writer.swift diff --git a/Nynja/Library/Source/Decoder.swift b/Nynja/ServerModel/Source/Decoder.swift similarity index 100% rename from Nynja/Library/Source/Decoder.swift rename to Nynja/ServerModel/Source/Decoder.swift diff --git a/Nynja/Library/Source/StringAtom.swift b/Nynja/ServerModel/Source/StringAtom.swift similarity index 100% rename from Nynja/Library/Source/StringAtom.swift rename to Nynja/ServerModel/Source/StringAtom.swift diff --git a/Nynja/Library/Source/TypeSpec.swift b/Nynja/ServerModel/Source/TypeSpec.swift similarity index 100% rename from Nynja/Library/Source/TypeSpec.swift rename to Nynja/ServerModel/Source/TypeSpec.swift diff --git a/Nynja/Library/Spec/Auth_Spec.swift b/Nynja/ServerModel/Spec/Auth_Spec.swift similarity index 100% rename from Nynja/Library/Spec/Auth_Spec.swift rename to Nynja/ServerModel/Spec/Auth_Spec.swift diff --git a/Nynja/Library/Spec/CDR_Spec.swift b/Nynja/ServerModel/Spec/CDR_Spec.swift similarity index 100% rename from Nynja/Library/Spec/CDR_Spec.swift rename to Nynja/ServerModel/Spec/CDR_Spec.swift diff --git a/Nynja/Library/Spec/Contact_Spec.swift b/Nynja/ServerModel/Spec/Contact_Spec.swift similarity index 100% rename from Nynja/Library/Spec/Contact_Spec.swift rename to Nynja/ServerModel/Spec/Contact_Spec.swift diff --git a/Nynja/Library/Spec/Cursor_Spec.swift b/Nynja/ServerModel/Spec/Cursor_Spec.swift similarity index 100% rename from Nynja/Library/Spec/Cursor_Spec.swift rename to Nynja/ServerModel/Spec/Cursor_Spec.swift diff --git a/Nynja/Library/Spec/Desc_Spec.swift b/Nynja/ServerModel/Spec/Desc_Spec.swift similarity index 100% rename from Nynja/Library/Spec/Desc_Spec.swift rename to Nynja/ServerModel/Spec/Desc_Spec.swift diff --git a/Nynja/Library/Spec/ExtendedStar_Spec.swift b/Nynja/ServerModel/Spec/ExtendedStar_Spec.swift similarity index 100% rename from Nynja/Library/Spec/ExtendedStar_Spec.swift rename to Nynja/ServerModel/Spec/ExtendedStar_Spec.swift diff --git a/Nynja/Library/Spec/Feature_Spec.swift b/Nynja/ServerModel/Spec/Feature_Spec.swift similarity index 100% rename from Nynja/Library/Spec/Feature_Spec.swift rename to Nynja/ServerModel/Spec/Feature_Spec.swift diff --git a/Nynja/Library/Spec/Friend_Spec.swift b/Nynja/ServerModel/Spec/Friend_Spec.swift similarity index 100% rename from Nynja/Library/Spec/Friend_Spec.swift rename to Nynja/ServerModel/Spec/Friend_Spec.swift diff --git a/Nynja/Library/Spec/History_Spec.swift b/Nynja/ServerModel/Spec/History_Spec.swift similarity index 100% rename from Nynja/Library/Spec/History_Spec.swift rename to Nynja/ServerModel/Spec/History_Spec.swift diff --git a/Nynja/Library/Spec/Index_Spec.swift b/Nynja/ServerModel/Spec/Index_Spec.swift similarity index 100% rename from Nynja/Library/Spec/Index_Spec.swift rename to Nynja/ServerModel/Spec/Index_Spec.swift diff --git a/Nynja/Library/Spec/Job_Spec.swift b/Nynja/ServerModel/Spec/Job_Spec.swift similarity index 100% rename from Nynja/Library/Spec/Job_Spec.swift rename to Nynja/ServerModel/Spec/Job_Spec.swift diff --git a/Nynja/Library/Spec/Loc_Spec.swift b/Nynja/ServerModel/Spec/Loc_Spec.swift similarity index 100% rename from Nynja/Library/Spec/Loc_Spec.swift rename to Nynja/ServerModel/Spec/Loc_Spec.swift diff --git a/Nynja/Library/Spec/Member_Spec.swift b/Nynja/ServerModel/Spec/Member_Spec.swift similarity index 100% rename from Nynja/Library/Spec/Member_Spec.swift rename to Nynja/ServerModel/Spec/Member_Spec.swift diff --git a/Nynja/Library/Spec/Message_Spec.swift b/Nynja/ServerModel/Spec/Message_Spec.swift similarity index 100% rename from Nynja/Library/Spec/Message_Spec.swift rename to Nynja/ServerModel/Spec/Message_Spec.swift diff --git a/Nynja/Library/Spec/Person_Spec.swift b/Nynja/ServerModel/Spec/Person_Spec.swift similarity index 100% rename from Nynja/Library/Spec/Person_Spec.swift rename to Nynja/ServerModel/Spec/Person_Spec.swift diff --git a/Nynja/Library/Spec/Profile_Spec.swift b/Nynja/ServerModel/Spec/Profile_Spec.swift similarity index 100% rename from Nynja/Library/Spec/Profile_Spec.swift rename to Nynja/ServerModel/Spec/Profile_Spec.swift diff --git a/Nynja/Library/Spec/Room_Spec.swift b/Nynja/ServerModel/Spec/Room_Spec.swift similarity index 100% rename from Nynja/Library/Spec/Room_Spec.swift rename to Nynja/ServerModel/Spec/Room_Spec.swift diff --git a/Nynja/Library/Spec/Roster_Spec.swift b/Nynja/ServerModel/Spec/Roster_Spec.swift similarity index 100% rename from Nynja/Library/Spec/Roster_Spec.swift rename to Nynja/ServerModel/Spec/Roster_Spec.swift diff --git a/Nynja/Library/Spec/Search_Spec.swift b/Nynja/ServerModel/Spec/Search_Spec.swift similarity index 100% rename from Nynja/Library/Spec/Search_Spec.swift rename to Nynja/ServerModel/Spec/Search_Spec.swift diff --git a/Nynja/Library/Spec/Service_Spec.swift b/Nynja/ServerModel/Spec/Service_Spec.swift similarity index 100% rename from Nynja/Library/Spec/Service_Spec.swift rename to Nynja/ServerModel/Spec/Service_Spec.swift diff --git a/Nynja/Library/Spec/Star_Spec.swift b/Nynja/ServerModel/Spec/Star_Spec.swift similarity index 100% rename from Nynja/Library/Spec/Star_Spec.swift rename to Nynja/ServerModel/Spec/Star_Spec.swift diff --git a/Nynja/Library/Spec/Tag_Spec.swift b/Nynja/ServerModel/Spec/Tag_Spec.swift similarity index 100% rename from Nynja/Library/Spec/Tag_Spec.swift rename to Nynja/ServerModel/Spec/Tag_Spec.swift diff --git a/Nynja/Library/Spec/Test_Spec.swift b/Nynja/ServerModel/Spec/Test_Spec.swift similarity index 100% rename from Nynja/Library/Spec/Test_Spec.swift rename to Nynja/ServerModel/Spec/Test_Spec.swift diff --git a/Nynja/Library/Spec/Typing_Spec.swift b/Nynja/ServerModel/Spec/Typing_Spec.swift similarity index 100% rename from Nynja/Library/Spec/Typing_Spec.swift rename to Nynja/ServerModel/Spec/Typing_Spec.swift diff --git a/Nynja/Library/Spec/Vox_Spec.swift b/Nynja/ServerModel/Spec/Vox_Spec.swift similarity index 100% rename from Nynja/Library/Spec/Vox_Spec.swift rename to Nynja/ServerModel/Spec/Vox_Spec.swift diff --git a/Nynja/Library/Spec/act_Spec.swift b/Nynja/ServerModel/Spec/act_Spec.swift similarity index 100% rename from Nynja/Library/Spec/act_Spec.swift rename to Nynja/ServerModel/Spec/act_Spec.swift diff --git a/Nynja/Library/Spec/boundaryEvent_Spec.swift b/Nynja/ServerModel/Spec/boundaryEvent_Spec.swift similarity index 100% rename from Nynja/Library/Spec/boundaryEvent_Spec.swift rename to Nynja/ServerModel/Spec/boundaryEvent_Spec.swift diff --git a/Nynja/Library/Spec/chain_Spec.swift b/Nynja/ServerModel/Spec/chain_Spec.swift similarity index 100% rename from Nynja/Library/Spec/chain_Spec.swift rename to Nynja/ServerModel/Spec/chain_Spec.swift diff --git a/Nynja/Library/Spec/container_Spec.swift b/Nynja/ServerModel/Spec/container_Spec.swift similarity index 100% rename from Nynja/Library/Spec/container_Spec.swift rename to Nynja/ServerModel/Spec/container_Spec.swift diff --git a/Nynja/Library/Spec/cur_Spec.swift b/Nynja/ServerModel/Spec/cur_Spec.swift similarity index 100% rename from Nynja/Library/Spec/cur_Spec.swift rename to Nynja/ServerModel/Spec/cur_Spec.swift diff --git a/Nynja/Library/Spec/error2_Spec.swift b/Nynja/ServerModel/Spec/error2_Spec.swift similarity index 100% rename from Nynja/Library/Spec/error2_Spec.swift rename to Nynja/ServerModel/Spec/error2_Spec.swift diff --git a/Nynja/Library/Spec/error_Spec.swift b/Nynja/ServerModel/Spec/error_Spec.swift similarity index 100% rename from Nynja/Library/Spec/error_Spec.swift rename to Nynja/ServerModel/Spec/error_Spec.swift diff --git a/Nynja/Library/Spec/io_Spec.swift b/Nynja/ServerModel/Spec/io_Spec.swift similarity index 100% rename from Nynja/Library/Spec/io_Spec.swift rename to Nynja/ServerModel/Spec/io_Spec.swift diff --git a/Nynja/Library/Spec/iter_Spec.swift b/Nynja/ServerModel/Spec/iter_Spec.swift similarity index 100% rename from Nynja/Library/Spec/iter_Spec.swift rename to Nynja/ServerModel/Spec/iter_Spec.swift diff --git a/Nynja/Library/Spec/iterator_Spec.swift b/Nynja/ServerModel/Spec/iterator_Spec.swift similarity index 100% rename from Nynja/Library/Spec/iterator_Spec.swift rename to Nynja/ServerModel/Spec/iterator_Spec.swift diff --git a/Nynja/Library/Spec/log_Spec.swift b/Nynja/ServerModel/Spec/log_Spec.swift similarity index 100% rename from Nynja/Library/Spec/log_Spec.swift rename to Nynja/ServerModel/Spec/log_Spec.swift diff --git a/Nynja/Library/Spec/messageEvent_Spec.swift b/Nynja/ServerModel/Spec/messageEvent_Spec.swift similarity index 100% rename from Nynja/Library/Spec/messageEvent_Spec.swift rename to Nynja/ServerModel/Spec/messageEvent_Spec.swift diff --git a/Nynja/Library/Spec/muc_Spec.swift b/Nynja/ServerModel/Spec/muc_Spec.swift similarity index 100% rename from Nynja/Library/Spec/muc_Spec.swift rename to Nynja/ServerModel/Spec/muc_Spec.swift diff --git a/Nynja/Library/Spec/ok2_Spec.swift b/Nynja/ServerModel/Spec/ok2_Spec.swift similarity index 100% rename from Nynja/Library/Spec/ok2_Spec.swift rename to Nynja/ServerModel/Spec/ok2_Spec.swift diff --git a/Nynja/Library/Spec/ok_Spec.swift b/Nynja/ServerModel/Spec/ok_Spec.swift similarity index 100% rename from Nynja/Library/Spec/ok_Spec.swift rename to Nynja/ServerModel/Spec/ok_Spec.swift diff --git a/Nynja/Library/Spec/operation_Spec.swift b/Nynja/ServerModel/Spec/operation_Spec.swift similarity index 100% rename from Nynja/Library/Spec/operation_Spec.swift rename to Nynja/ServerModel/Spec/operation_Spec.swift diff --git a/Nynja/Library/Spec/p2p_Spec.swift b/Nynja/ServerModel/Spec/p2p_Spec.swift similarity index 100% rename from Nynja/Library/Spec/p2p_Spec.swift rename to Nynja/ServerModel/Spec/p2p_Spec.swift diff --git a/Nynja/Library/Spec/process_Spec.swift b/Nynja/ServerModel/Spec/process_Spec.swift similarity index 100% rename from Nynja/Library/Spec/process_Spec.swift rename to Nynja/ServerModel/Spec/process_Spec.swift diff --git a/Nynja/Library/Spec/push_Spec.swift b/Nynja/ServerModel/Spec/push_Spec.swift similarity index 100% rename from Nynja/Library/Spec/push_Spec.swift rename to Nynja/ServerModel/Spec/push_Spec.swift diff --git a/Nynja/Library/Spec/reader_Spec.swift b/Nynja/ServerModel/Spec/reader_Spec.swift similarity index 100% rename from Nynja/Library/Spec/reader_Spec.swift rename to Nynja/ServerModel/Spec/reader_Spec.swift diff --git a/Nynja/Library/Spec/receiveTask_Spec.swift b/Nynja/ServerModel/Spec/receiveTask_Spec.swift similarity index 100% rename from Nynja/Library/Spec/receiveTask_Spec.swift rename to Nynja/ServerModel/Spec/receiveTask_Spec.swift diff --git a/Nynja/Library/Spec/sequenceFlow_Spec.swift b/Nynja/ServerModel/Spec/sequenceFlow_Spec.swift similarity index 100% rename from Nynja/Library/Spec/sequenceFlow_Spec.swift rename to Nynja/ServerModel/Spec/sequenceFlow_Spec.swift diff --git a/Nynja/Library/Spec/serviceTask_Spec.swift b/Nynja/ServerModel/Spec/serviceTask_Spec.swift similarity index 100% rename from Nynja/Library/Spec/serviceTask_Spec.swift rename to Nynja/ServerModel/Spec/serviceTask_Spec.swift diff --git a/Nynja/Library/Spec/task_Spec.swift b/Nynja/ServerModel/Spec/task_Spec.swift similarity index 100% rename from Nynja/Library/Spec/task_Spec.swift rename to Nynja/ServerModel/Spec/task_Spec.swift diff --git a/Nynja/Library/Spec/timeoutEvent_Spec.swift b/Nynja/ServerModel/Spec/timeoutEvent_Spec.swift similarity index 100% rename from Nynja/Library/Spec/timeoutEvent_Spec.swift rename to Nynja/ServerModel/Spec/timeoutEvent_Spec.swift diff --git a/Nynja/Library/Spec/userTask_Spec.swift b/Nynja/ServerModel/Spec/userTask_Spec.swift similarity index 100% rename from Nynja/Library/Spec/userTask_Spec.swift rename to Nynja/ServerModel/Spec/userTask_Spec.swift diff --git a/Nynja/Library/Spec/writer_Spec.swift b/Nynja/ServerModel/Spec/writer_Spec.swift similarity index 100% rename from Nynja/Library/Spec/writer_Spec.swift rename to Nynja/ServerModel/Spec/writer_Spec.swift -- GitLab From 0464825710d496f8d40d9cde859a7d44b4afd96b Mon Sep 17 00:00:00 2001 From: Volodymyr Hryhoriev Date: Tue, 13 Mar 2018 13:20:08 +0200 Subject: [PATCH 3/7] Correct prev commit. --- Nynja.xcodeproj/project.pbxproj | 10 ++++------ Nynja/{Library => ServerModel/Source}/Bert.swift | 0 2 files changed, 4 insertions(+), 6 deletions(-) rename Nynja/{Library => ServerModel/Source}/Bert.swift (100%) diff --git a/Nynja.xcodeproj/project.pbxproj b/Nynja.xcodeproj/project.pbxproj index e25e8c047..2b556e7af 100644 --- a/Nynja.xcodeproj/project.pbxproj +++ b/Nynja.xcodeproj/project.pbxproj @@ -152,7 +152,6 @@ 26035BA21F9A740A00003850 /* writer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 26035B6B1F9A73D800003850 /* writer.swift */; }; 26035BA41F9A740F00003850 /* TypeSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 26035B771F9A73EA00003850 /* TypeSpec.swift */; }; 26035BA51F9A740F00003850 /* StringAtom.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3A36E5231F4C6A0F001427DF /* StringAtom.swift */; }; - 26035BA61F9A740F00003850 /* Bert.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3A768DE51ECB3E8D00108F7C /* Bert.swift */; }; 26035BA71F9A741C00003850 /* Auth_Spec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 26035B4B1F9A73C900003850 /* Auth_Spec.swift */; }; 26035BA91F9A741C00003850 /* chain_Spec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 26035B411F9A73C700003850 /* chain_Spec.swift */; }; 26035BAA1F9A741C00003850 /* Contact_Spec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 26035B3E1F9A73C600003850 /* Contact_Spec.swift */; }; @@ -425,7 +424,6 @@ 359EB23D1F9A1BE600147437 /* Queue.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3A8045D91F60E18E00AED866 /* Queue.swift */; }; 359EB23F1F9A1CCA00147437 /* HandleService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3A1DC7381EF151C8006A8E9F /* HandleService.swift */; }; 359EB2401F9A1CCE00147437 /* IoHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3A1DC73E1EF15B65006A8E9F /* IoHandler.swift */; }; - 359EB2441F9A1CFE00147437 /* Bert.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3A768DE51ECB3E8D00108F7C /* Bert.swift */; }; 359EB2451F9A1D2600147437 /* (null) in Sources */ = {isa = PBXBuildFile; }; 359EB2461F9A1D3200147437 /* (null) in Sources */ = {isa = PBXBuildFile; }; 359EB2471F9A1D6100147437 /* (null) in Sources */ = {isa = PBXBuildFile; }; @@ -856,6 +854,7 @@ 99B9D27D2F0EFE051E6581ED /* CreateGroupProtocols.swift in Sources */ = {isa = PBXBuildFile; fileRef = FDE9DC6ADA0E71241C49A328 /* CreateGroupProtocols.swift */; }; 9E9DD4C7F700872D7CCEE227 /* ProfileInteractor.swift in Sources */ = {isa = PBXBuildFile; fileRef = EFF6A30BDE89BF7887B67DA0 /* ProfileInteractor.swift */; }; A1AD6864F4F49D9FC8997D59 /* SelectCountryPresenter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5522F1F73FC8C564BF0254BF /* SelectCountryPresenter.swift */; }; + A44A2CA02057EAB0009863B6 /* Bert.swift in Sources */ = {isa = PBXBuildFile; fileRef = A44A2C9F2057EAB0009863B6 /* Bert.swift */; }; A4569873060C49904EF8C555 /* EditGroupPhotoViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 40444524B52370D471DC9141 /* EditGroupPhotoViewController.swift */; }; A5FD5064B572D617D00F7FEE /* AudioRecorderViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0249B308AA479DBFE0C11BFC /* AudioRecorderViewController.swift */; }; A7285B8B56BFCA857AD9BA8A /* AddContactByUsernameWireframe.swift in Sources */ = {isa = PBXBuildFile; fileRef = EF74AC6D4879E4DA38B3C352 /* AddContactByUsernameWireframe.swift */; }; @@ -1570,7 +1569,6 @@ 3A3FD2821F39E0A000B6958F /* GetHistoryModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = GetHistoryModel.swift; path = Services/Models/GetHistoryModel.swift; sourceTree = ""; }; 3A62B7D71F4CB9D100F45B51 /* BaseMQTTModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = BaseMQTTModel.swift; path = Services/Models/BaseMQTTModel.swift; sourceTree = ""; }; 3A6DF16A1EFB5EAA0027F2D9 /* PhoneField.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PhoneField.swift; sourceTree = ""; }; - 3A768DE51ECB3E8D00108F7C /* Bert.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = Bert.swift; path = ../Bert.swift; sourceTree = ""; }; 3A768F061ED4987300108F7C /* VoxService.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = VoxService.swift; path = Services/VoxService.swift; sourceTree = ""; wrapsLines = 0; }; 3A771CA91F191B38008D968A /* ProfileHandler.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = ProfileHandler.swift; path = Services/HandleServices/ProfileHandler.swift; sourceTree = ""; }; 3A771CB11F193945008D968A /* UpdateRosterModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = UpdateRosterModel.swift; path = Services/Models/UpdateRosterModel.swift; sourceTree = ""; }; @@ -1843,6 +1841,7 @@ 9EDEA273EC821A0D4317436E /* Pods_Nynja_Nynja_Share.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_Nynja_Nynja_Share.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 9FB2678C74CCC58C8AAFADD6 /* AuthWireframe.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; path = AuthWireframe.swift; sourceTree = ""; }; A2D9E2484E2189F0E019FF3D /* GroupRulesViewController.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; path = GroupRulesViewController.swift; sourceTree = ""; }; + A44A2C9F2057EAB0009863B6 /* Bert.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Bert.swift; sourceTree = ""; }; A5724C69672981F75731E2E4 /* Pods_Nynja.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_Nynja.framework; sourceTree = BUILT_PRODUCTS_DIR; }; A5C381840446A90483844FB5 /* TutorialWireframe.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; path = TutorialWireframe.swift; sourceTree = ""; }; A709771A0DE7CF79A57E5F41 /* MapInteractor.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; path = MapInteractor.swift; sourceTree = ""; }; @@ -3349,10 +3348,10 @@ 3AA13C2B1F21821900BE5D8F /* Source */ = { isa = PBXGroup; children = ( + A44A2C9F2057EAB0009863B6 /* Bert.swift */, 262DAFE61F9AB72000EB9C01 /* Decoder.swift */, 26035B771F9A73EA00003850 /* TypeSpec.swift */, 3A36E5231F4C6A0F001427DF /* StringAtom.swift */, - 3A768DE51ECB3E8D00108F7C /* Bert.swift */, ); path = Source; sourceTree = ""; @@ -6593,7 +6592,6 @@ 35B1AB8B1FA3457100E65233 /* Contact.swift in Sources */, 35B1ABA31FA34A2B00E65233 /* io_Spec.swift in Sources */, 359EB2711F9A203800147437 /* (null) in Sources */, - 359EB2441F9A1CFE00147437 /* Bert.swift in Sources */, 359EB25C1F9A1E9D00147437 /* (null) in Sources */, 35B1ABA51FA34A4B00E65233 /* ok2_Spec.swift in Sources */, 26B32B941FE20B9700888A0A /* mucExtension+BERT.swift in Sources */, @@ -6818,7 +6816,6 @@ E75D2CF92004ED84001E6718 /* MessageTextView.swift in Sources */, 6D6234F61F1E150600EF375F /* HistoryTableDS.swift in Sources */, 32868DF61F334D540028B260 /* ALTextInputBarDelegate.swift in Sources */, - 26035BA61F9A740F00003850 /* Bert.swift in Sources */, 4B1D7E0F2029DB1100703228 /* ByUsernameItemsFactory.swift in Sources */, 4B8996C8204ECE9B00DCB183 /* ContactDAO.swift in Sources */, E7A3DAB81F9DF39400856133 /* HistoryServiceProtocol.swift in Sources */, @@ -7560,6 +7557,7 @@ 26060C961FFDCF4000E5C6F3 /* NSLog.swift in Sources */, E73315F01FB0B60E00C273FF /* ContainerViewController.swift in Sources */, E485DED76CE7933E643691D6 /* VideoPreviewInteractor.swift in Sources */, + A44A2CA02057EAB0009863B6 /* Bert.swift in Sources */, 85801C3F20342A2F00CC364C /* ActionsView.swift in Sources */, 4B8996CF204ED33D00DCB183 /* StarDAO.swift in Sources */, 26DAE5D41FFAF91100EDF412 /* DefaultBackgroundModeService.swift in Sources */, diff --git a/Nynja/Library/Bert.swift b/Nynja/ServerModel/Source/Bert.swift similarity index 100% rename from Nynja/Library/Bert.swift rename to Nynja/ServerModel/Source/Bert.swift -- GitLab From 57eb3fdaa69a34b948b87021fd743eadc2be5760 Mon Sep 17 00:00:00 2001 From: Volodymyr Hryhoriev Date: Tue, 13 Mar 2018 14:07:12 +0200 Subject: [PATCH 4/7] Implement 'fetch contact by phone' feature in ContactDAO, update 'AddContactViaPhone' module. --- Nynja.xcodeproj/project.pbxproj | 2 ++ Nynja/ContactDAO.swift | 12 ++++++++++ .../AddContactViaPhoneInteractor.swift | 23 ++++--------------- 3 files changed, 18 insertions(+), 19 deletions(-) diff --git a/Nynja.xcodeproj/project.pbxproj b/Nynja.xcodeproj/project.pbxproj index 2b556e7af..409b5d10d 100644 --- a/Nynja.xcodeproj/project.pbxproj +++ b/Nynja.xcodeproj/project.pbxproj @@ -856,6 +856,7 @@ A1AD6864F4F49D9FC8997D59 /* SelectCountryPresenter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5522F1F73FC8C564BF0254BF /* SelectCountryPresenter.swift */; }; A44A2CA02057EAB0009863B6 /* Bert.swift in Sources */ = {isa = PBXBuildFile; fileRef = A44A2C9F2057EAB0009863B6 /* Bert.swift */; }; A4569873060C49904EF8C555 /* EditGroupPhotoViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 40444524B52370D471DC9141 /* EditGroupPhotoViewController.swift */; }; + A45F59A82057EB2000EAA780 /* Bert.swift in Sources */ = {isa = PBXBuildFile; fileRef = A44A2C9F2057EAB0009863B6 /* Bert.swift */; }; A5FD5064B572D617D00F7FEE /* AudioRecorderViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0249B308AA479DBFE0C11BFC /* AudioRecorderViewController.swift */; }; A7285B8B56BFCA857AD9BA8A /* AddContactByUsernameWireframe.swift in Sources */ = {isa = PBXBuildFile; fileRef = EF74AC6D4879E4DA38B3C352 /* AddContactByUsernameWireframe.swift */; }; A81BC507BA308AEE05A9B5E1 /* TimeZoneSelectorInteractor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6849EE44C7121EB25C5421DB /* TimeZoneSelectorInteractor.swift */; }; @@ -6586,6 +6587,7 @@ 2648B1511FEAA8BA007F2AAE /* IdGenerator.swift in Sources */, 359EB23F1F9A1CCA00147437 /* HandleService.swift in Sources */, E7A77FDA1FACC564004AE609 /* UIDeviceExtension.swift in Sources */, + A45F59A82057EB2000EAA780 /* Bert.swift in Sources */, 264FFA981FC5917D0028243D /* WheelItemModel.swift in Sources */, 005886D82032023500FE2E89 /* process_Spec.swift in Sources */, 35B1AB9F1FA349FD00E65233 /* Star.swift in Sources */, diff --git a/Nynja/ContactDAO.swift b/Nynja/ContactDAO.swift index a8bced0b5..f4843b539 100644 --- a/Nynja/ContactDAO.swift +++ b/Nynja/ContactDAO.swift @@ -29,6 +29,18 @@ class ContactDAO: ContactDAOProtocol { } } + static func findContactBy(phone: String) -> Contact? { + let phoneIdColumn = Column(ContactTable.Column.phoneId.title) + + guard let contact = dbManager.fetch({ db in + return try DBContact.filter(phoneIdColumn.like("\(phone)%")).fetchOne(db) + }) else { + return nil + } + + return Contact(contact: contact) + } + static func findContactBy(phoneId: String) -> Contact? { do { guard let dbContact = try fetchContact(by: phoneId) else { return nil } diff --git a/Nynja/Modules/AddContactViaPhone/Interactor/AddContactViaPhoneInteractor.swift b/Nynja/Modules/AddContactViaPhone/Interactor/AddContactViaPhoneInteractor.swift index 899b26877..e54dc073e 100644 --- a/Nynja/Modules/AddContactViaPhone/Interactor/AddContactViaPhoneInteractor.swift +++ b/Nynja/Modules/AddContactViaPhone/Interactor/AddContactViaPhoneInteractor.swift @@ -19,31 +19,16 @@ class AddContactViaPhoneInteractor: AddContactViaPhoneInteractorInputProtocol, I func getContactByPhone(number: String) { currentNumer = number - let profile = StorageService.sharedInstance.profile - if profile.phone == number { + + if StorageService.sharedInstance.phone == number { self.presenter.getMyProfile() - } else if let contact = findContactInRoster(number: number) { + } else if let contact = ContactDAO.findContactBy(phone: number) { self.presenter.getContactByPhoneSuccess(contact: contact) } else { MQTTService.sharedInstance.tryFindContact(number: number) } } - - func findContactInRoster(number: String) -> Contact? { - if let rosters = (StorageService.sharedInstance.profile.rosters as? [Roster]) { - if rosters.count > 0 { - if let contacts = rosters[0].userlist { - for contact in contacts { - if contact.phoneNumber == number { - return Contact(contact: contact) - } - } - } - } - } - return nil - } - + func getContactSuccess(contact: Contact) { self.presenter.getContactByPhoneSuccess(contact: contact) } -- GitLab From 09574876112893058b6e1ab8be7fb1641ef2446e Mon Sep 17 00:00:00 2001 From: Volodymyr Hryhoriev Date: Tue, 13 Mar 2018 16:51:59 +0200 Subject: [PATCH 5/7] Implement 'fetch contacts with capability of filter by statuses' and 'fetch current contact' features in the ContactDAO. Update 'Add Participants' module. --- Nynja/ContactDAO.swift | 17 +++++ Nynja/ContactDAOProtocol.swift | 4 ++ .../AddParticipantsProtocols.swift | 1 - .../AddParticipantsInteractor.swift | 64 +++++++------------ .../Presenter/AddParticipantsPresenter.swift | 33 ++++------ .../View/AddParticipantsViewController.swift | 8 +-- .../WireFrame/AddParticipantsWireframe.swift | 10 +-- .../Presenter/SettingsGroupPresenter.swift | 6 +- .../WireFrame/SettingsGroupWireFrame.swift | 6 +- 9 files changed, 73 insertions(+), 76 deletions(-) diff --git a/Nynja/ContactDAO.swift b/Nynja/ContactDAO.swift index f4843b539..f65210b1d 100644 --- a/Nynja/ContactDAO.swift +++ b/Nynja/ContactDAO.swift @@ -17,6 +17,11 @@ class ContactDAO: ContactDAOProtocol { // MARK: - Fetch // MARK: -- Contact + static var currentContact: Contact? { + guard let phoneId = StorageService.sharedInstance.phoneId else { return nil } + return findContactBy(phoneId: phoneId) + } + static func fetchContact(by id: String) throws -> DBContact? { return dbManager.fetch { db in return try DBContact.contact(from: db, id: id) @@ -62,6 +67,18 @@ class ContactDAO: ContactDAOProtocol { return Contact(contact: contact) } + static func fetchContacts(with statuses: [ContactStatus]) -> [Contact] { + let statuses = statuses.map { $0.rawValue } + + let statusColumn = Column(ContactTable.Column.status.title) + + let contacts = dbManager.fetch { db in + return try DBContact.filter(statuses.contains(statusColumn)).fetchAll(db) + } + + return contacts.map { Contact(contact: $0) } + } + // MARK: -- Contacts static func fetchContacts() -> [Contact] { diff --git a/Nynja/ContactDAOProtocol.swift b/Nynja/ContactDAOProtocol.swift index 735aa2bb7..5a0c72871 100644 --- a/Nynja/ContactDAOProtocol.swift +++ b/Nynja/ContactDAOProtocol.swift @@ -10,6 +10,8 @@ protocol ContactDAOProtocol: DAOProtocol { // MARK: - Fetch // MARK: -- Contact + static var currentContact: Contact? { get } + static func fetchContact(by id: String) throws -> DBContact? static func fetchContact(by rowId: Int64) throws -> DBContact? @@ -20,6 +22,8 @@ protocol ContactDAOProtocol: DAOProtocol { static func fetchContacts() -> [Contact] static func fetchContacts(with phoneIds: [String]) -> [Contact] + static func fetchContacts(with statuses: [ContactStatus]) -> [Contact] + // MARK: -- Reader static func fetchReader(for phoneId: String) throws -> Int64? diff --git a/Nynja/Modules/AddParticipants/AddParticipantsProtocols.swift b/Nynja/Modules/AddParticipants/AddParticipantsProtocols.swift index a19d5b1ab..520759cbd 100644 --- a/Nynja/Modules/AddParticipants/AddParticipantsProtocols.swift +++ b/Nynja/Modules/AddParticipants/AddParticipantsProtocols.swift @@ -75,7 +75,6 @@ protocol AddParticipantsInteractorInputProtocol: class { /** * Add here your methods for communication PRESENTER -> INTERACTOR */ - func fetchParticipants() func filterParticipants(with text: String) func fetchParticipants(`for` mode: ParticipantsModeType) diff --git a/Nynja/Modules/AddParticipants/Interactor/AddParticipantsInteractor.swift b/Nynja/Modules/AddParticipants/Interactor/AddParticipantsInteractor.swift index 501d74c5a..36ed5a696 100644 --- a/Nynja/Modules/AddParticipants/Interactor/AddParticipantsInteractor.swift +++ b/Nynja/Modules/AddParticipants/Interactor/AddParticipantsInteractor.swift @@ -15,47 +15,28 @@ class AddParticipantsInteractor: AddParticipantsInteractorInputProtocol { var participants: [Participant] = [] - func getMySelf() -> Contact? { - return (StorageService.sharedInstance.profile.rosters?.first as? Roster)?.myContact - } - - // NOTE: Copied from ContactsInteractor - func fetchParticipants(`for` mode: ParticipantsModeType) { - let model = StorageService.sharedInstance.profile - if let firstProfile = model.rosters?.first as? Roster { - if let userlist = firstProfile.userlist { - var contacts = userlist.filter { $0.contactStatus == .added } - if mode == .Delete || mode == .Admins { - if let members = members { - contacts = members.contacts - } else { - contacts = [] - } - } else { - contacts = contacts.filter({ contact -> Bool in - if let isContains = (members?.contains(where: { (member) -> Bool in - return member.phone_id == contact.phone_id - })) { - return !isContains - } - return false - }) - } - getContactsSuccess(contacts: contacts, mode) - } - } - } - - func fetchParticipants() { - let model = StorageService.sharedInstance.profile - if let firstProfile = model.rosters?.first as? Roster { - if let userlist = firstProfile.userlist { - let contacts = userlist.filter { $0.contactStatus == .added } - getContactsSuccess(contacts: contacts) + var contacts = ContactDAO.fetchContacts(with: [.added]) + + if mode == .delete || mode == .admins { + if let members = members { + contacts = members.contacts + } else { + contacts = [] } + } else if mode != .create { + contacts = contacts.filter({ contact -> Bool in + if let isContains = (members?.contains(where: { (member) -> Bool in + return member.phone_id == contact.phone_id + })) { + return !isContains + } + return false + }) } + + getContactsSuccess(contacts: contacts, mode) } func filterParticipants(with text: String) { @@ -63,15 +44,18 @@ class AddParticipantsInteractor: AddParticipantsInteractorInputProtocol { self.presenter.participantsFiltered(filtered) } - func getContactsSuccess(contacts: [Contact], _ mode: ParticipantsModeType = .Create) { - self.participants = (mode == .Admins ? contacts : contacts.withoutSelf).map { (contact) -> Participant in + func getContactsSuccess(contacts: [Contact], _ mode: ParticipantsModeType = .create) { + self.participants = (mode == .admins ? contacts : contacts.withoutSelf).map { (contact) -> Participant in let participant = Participant(contact: contact) - participant.isEnable = contact.phoneId != self.getMySelf()?.phoneId + + participant.isEnable = contact.phoneId != StorageService.sharedInstance.phoneId participant.isSelected = (selectedContacts?.contains(where: { (contact) -> Bool in return contact.phoneId == participant.contact.phoneId })) ?? false + return participant } + presenter.participantsFetched(participants) } diff --git a/Nynja/Modules/AddParticipants/Presenter/AddParticipantsPresenter.swift b/Nynja/Modules/AddParticipants/Presenter/AddParticipantsPresenter.swift index 914e97c6e..66af11e42 100644 --- a/Nynja/Modules/AddParticipants/Presenter/AddParticipantsPresenter.swift +++ b/Nynja/Modules/AddParticipants/Presenter/AddParticipantsPresenter.swift @@ -9,7 +9,7 @@ class AddParticipantsPresenter: BasePresenter, AddParticipantsPresenterProtocol, AddParticipantsInteractorOutputProtocol { override var itemsFactory: WCItemsFactory? { - if participantsMode == .Create { + if participantsMode == .create { return CreateGroupItemsFactory() } else { return GroupOptionsItemsFactory() @@ -24,11 +24,7 @@ class AddParticipantsPresenter: BasePresenter, AddParticipantsPresenterProtocol, // MARK: AddParticipantsPresenterProtocol func shown() { - if participantsMode == .Create { - interactor.fetchParticipants() - } else { - interactor.fetchParticipants(for: participantsMode) - } + interactor.fetchParticipants(for: participantsMode) } func filter(with text: String) { @@ -36,29 +32,25 @@ class AddParticipantsPresenter: BasePresenter, AddParticipantsPresenterProtocol, } func hide(with contacts: [Contact]){ - if participantsMode == .Create { + if participantsMode == .create { wireFrame.showGroupDetails(contacts: contacts) - } else { - if participantsMode == .Delete { - if contacts.count > 0 { - let deleteAction = UIAlertAction(title: "remove".localized, style: .destructive) { [unowned self] _ in - self.wireFrame.hide(withSelectedContacts: contacts, mode: self.participantsMode) - } - let cancelAction = UIAlertAction(title: "cancel".localized, style: .cancel) - - AlertManager.sharedInstance.showActionSheet(title: "conf_remove".localized, message: nil, actions: [deleteAction, cancelAction]) - } else { - wireFrame.hide(withSelectedContacts: contacts, mode: participantsMode) + } else if participantsMode == .delete { + if contacts.count > 0 { + let deleteAction = UIAlertAction(title: "remove".localized, style: .destructive) { [unowned self] _ in + self.wireFrame.hide(withSelectedContacts: contacts, mode: self.participantsMode) } + let cancelAction = UIAlertAction(title: "cancel".localized, style: .cancel) + + AlertManager.sharedInstance.showActionSheet(title: "conf_remove".localized, message: nil, actions: [deleteAction, cancelAction]) } else { wireFrame.hide(withSelectedContacts: contacts, mode: participantsMode) } + } else { + wireFrame.hide(withSelectedContacts: contacts, mode: participantsMode) } } - // MARK: AddParticipantsInteractorOutputProtocol - func participantsFetched(_ participants: [Participant]) { view.setupParticipants(participants.groupedParticipant) } @@ -66,4 +58,5 @@ class AddParticipantsPresenter: BasePresenter, AddParticipantsPresenterProtocol, func participantsFiltered(_ participants: [Participant]) { view.updateParticipantsList(participants.groupedParticipant) } + } diff --git a/Nynja/Modules/AddParticipants/View/AddParticipantsViewController.swift b/Nynja/Modules/AddParticipants/View/AddParticipantsViewController.swift index 30ae47632..d744f213d 100644 --- a/Nynja/Modules/AddParticipants/View/AddParticipantsViewController.swift +++ b/Nynja/Modules/AddParticipants/View/AddParticipantsViewController.swift @@ -128,9 +128,9 @@ class AddParticipantsViewController: BaseVC, AddParticipantsViewProtocol { override func viewDidLoad() { super.viewDidLoad() - if presenter.participantsMode == .Delete { + if presenter.participantsMode == .delete { screenTitle = "delete_participants".localized.uppercased() - } else if presenter.participantsMode == .Admins { + } else if presenter.participantsMode == .admins { screenTitle = "admins".localized.uppercased() } else { screenTitle = "add_participants".localized.uppercased() @@ -155,7 +155,7 @@ class AddParticipantsViewController: BaseVC, AddParticipantsViewProtocol { filterField.placeholerImage = #imageLiteral(resourceName: "ic_participants_search") filterField.textField.addTarget(self, action: #selector(filterEdited(_:)), for: .editingChanged) - if presenter.participantsMode == .Delete { + if presenter.participantsMode == .delete { doneButton.setTitle("delete".localized.uppercased(), for: .normal) } else { doneButton.setTitle("done".localized.uppercased(), for: .normal) @@ -199,7 +199,7 @@ class AddParticipantsViewController: BaseVC, AddParticipantsViewProtocol { // MARK: Actions @objc private func doneTapped(_ button: UIButton) { self.view.endEditing(true) - if presenter.participantsMode == .Create { + if presenter.participantsMode == .create { if participantsDataSource.selectedParticipants.isEmpty { AlertManager.sharedInstance.showAlertOk(message: "please_choose_at_least_one_member".localized) } else { diff --git a/Nynja/Modules/AddParticipants/WireFrame/AddParticipantsWireframe.swift b/Nynja/Modules/AddParticipants/WireFrame/AddParticipantsWireframe.swift index 89a48411f..936801b68 100644 --- a/Nynja/Modules/AddParticipants/WireFrame/AddParticipantsWireframe.swift +++ b/Nynja/Modules/AddParticipants/WireFrame/AddParticipantsWireframe.swift @@ -9,10 +9,10 @@ import UIKit enum ParticipantsModeType { - case Create - case Update - case Delete - case Admins + case create + case update + case delete + case admins } class AddParticipantsWireFrame: AddParticipantsWireFrameProtocol { @@ -23,7 +23,7 @@ class AddParticipantsWireFrame: AddParticipantsWireFrameProtocol { var isEdit = false - func presentAddParticipants(navigation: UINavigationController, main: MainWireFrame?, selectedContacts: [Contact]?, delegate: EditParticipantsDelegate?, mode : ParticipantsModeType = .Create, members: [Member]? = nil) { + func presentAddParticipants(navigation: UINavigationController, main: MainWireFrame?, selectedContacts: [Contact]?, delegate: EditParticipantsDelegate?, mode : ParticipantsModeType = .create, members: [Member]? = nil) { self.delegate = delegate let view = AddParticipantsViewController() let presenter = AddParticipantsPresenter() diff --git a/Nynja/Modules/SettingsGroup/Presenter/SettingsGroupPresenter.swift b/Nynja/Modules/SettingsGroup/Presenter/SettingsGroupPresenter.swift index ed08ae361..62161063c 100644 --- a/Nynja/Modules/SettingsGroup/Presenter/SettingsGroupPresenter.swift +++ b/Nynja/Modules/SettingsGroup/Presenter/SettingsGroupPresenter.swift @@ -168,7 +168,7 @@ class SettingsGroupPresenter: BasePresenter, SettingsGroupPresenterProtocol, Cre func participantsUpdated(contacts: [Contact], forType type: ParticipantsModeType) { switch type { - case .Update: + case .update: let prepareToAddMembers = contacts.map { Member(contact: $0) } var notExistsMembers : [Member] = [] prepareToAddMembers.forEach({ member in @@ -182,7 +182,7 @@ class SettingsGroupPresenter: BasePresenter, SettingsGroupPresenterProtocol, Cre room?.members?.append(contentsOf: notExistsMembers) interactor.addMembers(room.id!, prepareToAddMembers) - case .Delete: + case .delete: let prepareToRemoveMembers = contacts.map { Member(contact: $0) } prepareToRemoveMembers.forEach({ member in if let mmbr = room?.members?.first(where: { $0.phone_id == member.phone_id }) { @@ -191,7 +191,7 @@ class SettingsGroupPresenter: BasePresenter, SettingsGroupPresenterProtocol, Cre }) interactor.removeMembers(room.id!, prepareToRemoveMembers) - case .Admins: + case .admins: let notRemovedAdmins = room?.onlyAdmins?.filter({ $0.phone_id != StorageService.sharedInstance.phoneId }) notRemovedAdmins?.forEach { $0.status = StringAtom(string: "removed") } diff --git a/Nynja/Modules/SettingsGroup/WireFrame/SettingsGroupWireFrame.swift b/Nynja/Modules/SettingsGroup/WireFrame/SettingsGroupWireFrame.swift index 58e3f2626..043ceb952 100644 --- a/Nynja/Modules/SettingsGroup/WireFrame/SettingsGroupWireFrame.swift +++ b/Nynja/Modules/SettingsGroup/WireFrame/SettingsGroupWireFrame.swift @@ -86,7 +86,7 @@ class SettingsGroupWireFrame: SettingsGroupWireframeProtocol { } func addParticipants(_ members: [Member]?) { - AddParticipantsWireFrame().presentAddParticipants(navigation: navigation!, main: main, selectedContacts: [], delegate: external, mode: .Update, members: members) + AddParticipantsWireFrame().presentAddParticipants(navigation: navigation!, main: main, selectedContacts: [], delegate: external, mode: .update, members: members) } func participants(_ members: [Member]?) { @@ -94,11 +94,11 @@ class SettingsGroupWireFrame: SettingsGroupWireframeProtocol { } func deleteParticipants(_ members: [Member]?) { - AddParticipantsWireFrame().presentAddParticipants(navigation: navigation!, main: main, selectedContacts: [], delegate: external, mode: .Delete, members: members) + AddParticipantsWireFrame().presentAddParticipants(navigation: navigation!, main: main, selectedContacts: [], delegate: external, mode: .delete, members: members) } func admins(_ admins:[Contact]?, _ allMembers: [Member]?) { - AddParticipantsWireFrame().presentAddParticipants(navigation: navigation!, main: main, selectedContacts: admins, delegate: external, mode: .Admins, members: allMembers) + AddParticipantsWireFrame().presentAddParticipants(navigation: navigation!, main: main, selectedContacts: admins, delegate: external, mode: .admins, members: allMembers) } func deleteAndLeave() { -- GitLab From 7a95a4c17d64c5a11d83b75d8b30f3f7c2b653e0 Mon Sep 17 00:00:00 2001 From: Volodymyr Hryhoriev Date: Tue, 13 Mar 2018 17:24:56 +0200 Subject: [PATCH 6/7] Correct 'NitificationManager'. --- Nynja/NitificationManager.swift | 37 ++++++++++++++++----------------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/Nynja/NitificationManager.swift b/Nynja/NitificationManager.swift index ca52056b3..78ef6cbd4 100644 --- a/Nynja/NitificationManager.swift +++ b/Nynja/NitificationManager.swift @@ -104,34 +104,33 @@ class NotificationManager { private func navigateToMessage(presenter: MainPresenterProtocol) { if let payload = NotificationManager.shared.tupleForNavigate { var msg: Message? = nil + if let room = get_Room().parse(bert: payload) as? Room { msg = room.last_msg - } - if let contact = get_Contact().parse(bert: payload) as? Contact { + } else if let contact = get_Contact().parse(bert: payload) as? Contact { msg = contact.last_msg } + if msg == nil { msg = get_Message().parse(bert: payload) as? Message } - guard let message = msg else { return } - NotificationManager.shared.typeForNavigate = nil - NotificationManager.shared.tupleForNavigate = nil - if (message.status as? StringAtom)?.string == "delete" { - return - } - let sender = message.from - if sender == StorageService.sharedInstance.phoneId { + + guard let message = msg, (message.status as? StringAtom)?.string != "delete", message.from != StorageService.sharedInstance.phoneId else { return } - var contact: Contact? = ContactDAO.fetchContacts().first(where: { - $0.phone_id == sender - }) + NotificationManager.shared.typeForNavigate = nil + NotificationManager.shared.tupleForNavigate = nil - // TODO: fetch room by id, fetch members by phone id - let room: Room? = RoomDAO.fetchRooms().first(where: { - $0.id == message.to - }) + var contact: Contact? + if let sender = message.from { + contact = ContactDAO.findContactBy(phoneId: sender) + } + + var room: Room? + if let receiver = message.to { + room = RoomDAO.findRoom(by: receiver) + } if let room = room { if let member = room.allMembers?.first(where: { @@ -146,12 +145,12 @@ class NotificationManager { return } - if let vc = ((UIApplication.shared.keyWindow?.rootViewController as? UINavigationController)?.viewControllers.first?.childViewControllers.first as? UINavigationController)?.viewControllers.last as? MessageVC { + if let vc = ((UIApplication.shared.keyWindow?.rootViewController as? UINavigationController)?.viewControllers.first?.childViewControllers.first as? UINavigationController)?.viewControllers.last as? MessageVC { if room != nil { if vc.room?.id != (message.feed_id as? muc)?.name { navToChat(message: message, presenter: presenter, cont: contact, room: room) } - } else { + } else if let sender = message.from { if vc.contact?.phone_id != sender && StorageService.sharedInstance.phoneId != sender { navToChat(message: message, presenter: presenter, cont: contact, room: room) } -- GitLab From 5823ceff00d72317ef11c5da9a4b3e19dd2919bd Mon Sep 17 00:00:00 2001 From: Volodymyr Hryhoriev Date: Tue, 13 Mar 2018 17:51:18 +0200 Subject: [PATCH 7/7] 1. Create 'RosterDAO'. 2. Update 'ContactDAO' with feature 'fetch contact by vox id'. 3. Update 'PushService' --- Nynja.xcodeproj/project.pbxproj | 16 ++++++++++++++ Nynja/ContactDAO.swift | 29 +++++++++++++++---------- Nynja/ContactDAOProtocol.swift | 7 +++--- Nynja/RosterDAO.swift | 37 ++++++++++++++++++++++++++++++++ Nynja/RosterDAOProtocol.swift | 19 ++++++++++++++++ Nynja/Services/PushService.swift | 24 ++++++--------------- 6 files changed, 100 insertions(+), 32 deletions(-) create mode 100644 Nynja/RosterDAO.swift create mode 100644 Nynja/RosterDAOProtocol.swift diff --git a/Nynja.xcodeproj/project.pbxproj b/Nynja.xcodeproj/project.pbxproj index 409b5d10d..5d067bf17 100644 --- a/Nynja.xcodeproj/project.pbxproj +++ b/Nynja.xcodeproj/project.pbxproj @@ -857,6 +857,8 @@ A44A2CA02057EAB0009863B6 /* Bert.swift in Sources */ = {isa = PBXBuildFile; fileRef = A44A2C9F2057EAB0009863B6 /* Bert.swift */; }; A4569873060C49904EF8C555 /* EditGroupPhotoViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 40444524B52370D471DC9141 /* EditGroupPhotoViewController.swift */; }; A45F59A82057EB2000EAA780 /* Bert.swift in Sources */ = {isa = PBXBuildFile; fileRef = A44A2C9F2057EAB0009863B6 /* Bert.swift */; }; + A45F59AB205825FC00EAA780 /* RosterDAOProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = A45F59AA205825FC00EAA780 /* RosterDAOProtocol.swift */; }; + A45F59AD2058263F00EAA780 /* RosterDAO.swift in Sources */ = {isa = PBXBuildFile; fileRef = A45F59AC2058263F00EAA780 /* RosterDAO.swift */; }; A5FD5064B572D617D00F7FEE /* AudioRecorderViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0249B308AA479DBFE0C11BFC /* AudioRecorderViewController.swift */; }; A7285B8B56BFCA857AD9BA8A /* AddContactByUsernameWireframe.swift in Sources */ = {isa = PBXBuildFile; fileRef = EF74AC6D4879E4DA38B3C352 /* AddContactByUsernameWireframe.swift */; }; A81BC507BA308AEE05A9B5E1 /* TimeZoneSelectorInteractor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6849EE44C7121EB25C5421DB /* TimeZoneSelectorInteractor.swift */; }; @@ -1843,6 +1845,8 @@ 9FB2678C74CCC58C8AAFADD6 /* AuthWireframe.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; path = AuthWireframe.swift; sourceTree = ""; }; A2D9E2484E2189F0E019FF3D /* GroupRulesViewController.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; path = GroupRulesViewController.swift; sourceTree = ""; }; A44A2C9F2057EAB0009863B6 /* Bert.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Bert.swift; sourceTree = ""; }; + A45F59AA205825FC00EAA780 /* RosterDAOProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RosterDAOProtocol.swift; sourceTree = ""; }; + A45F59AC2058263F00EAA780 /* RosterDAO.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RosterDAO.swift; sourceTree = ""; }; A5724C69672981F75731E2E4 /* Pods_Nynja.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_Nynja.framework; sourceTree = BUILT_PRODUCTS_DIR; }; A5C381840446A90483844FB5 /* TutorialWireframe.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; path = TutorialWireframe.swift; sourceTree = ""; }; A709771A0DE7CF79A57E5F41 /* MapInteractor.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; path = MapInteractor.swift; sourceTree = ""; }; @@ -3778,6 +3782,7 @@ children = ( 4B058F02204EA928004C7D9F /* DAOProtocol.swift */, 4B058EFF204EA762004C7D9F /* Profile */, + A45F59A9205825EC00EAA780 /* Roster */, 4B8996C6204ECE8500DCB183 /* Contact */, 4B058F09204EAEA7004C7D9F /* Room */, 2633EF6C205212DF00DB3868 /* Member */, @@ -4843,6 +4848,15 @@ path = ServerModel; sourceTree = ""; }; + A45F59A9205825EC00EAA780 /* Roster */ = { + isa = PBXGroup; + children = ( + A45F59AA205825FC00EAA780 /* RosterDAOProtocol.swift */, + A45F59AC2058263F00EAA780 /* RosterDAO.swift */, + ); + name = Roster; + sourceTree = ""; + }; A4D0787972A19641165C28B6 /* WireFrame */ = { isa = PBXGroup; children = ( @@ -7203,6 +7217,7 @@ 2646381E1FFFC5CB002590E6 /* RepliesProtocols.swift in Sources */, 38182BD2C2E0C783796C8AA1 /* QRCodeReaderInteractor.swift in Sources */, E75D2D012004EDA3001E6718 /* MessageVC+ContextMenuDelegate.swift in Sources */, + A45F59AB205825FC00EAA780 /* RosterDAOProtocol.swift in Sources */, 3AF8E26F1F42E33300D81390 /* ReturnToCallContentView.swift in Sources */, E75D2D002004EDA3001E6718 /* MessageVC+CellDelegate.swift in Sources */, 00102F45202C922F00A877A9 /* NynjaCalendarDataSource.swift in Sources */, @@ -7453,6 +7468,7 @@ E7229A4A1F8CAD72003AEE04 /* TutorialViewControllerLayout.swift in Sources */, E70402BD1FF6972B00182D81 /* BaseView.swift in Sources */, 005886D12031FFE000FE2E89 /* sequenceFlow.swift in Sources */, + A45F59AD2058263F00EAA780 /* RosterDAO.swift in Sources */, 855EF41B202CB9B900541BE3 /* ExtendedStar_Spec.swift in Sources */, 4C5EEA13EBC6A8398F08DCD1 /* MainWireframe.swift in Sources */, 005886C92030F13100FE2E89 /* NynjaTimeHoursDelegate.swift in Sources */, diff --git a/Nynja/ContactDAO.swift b/Nynja/ContactDAO.swift index f65210b1d..417ec78ff 100644 --- a/Nynja/ContactDAO.swift +++ b/Nynja/ContactDAO.swift @@ -22,13 +22,13 @@ class ContactDAO: ContactDAOProtocol { return findContactBy(phoneId: phoneId) } - static func fetchContact(by id: String) throws -> DBContact? { + static func fetchContact(by id: String) -> DBContact? { return dbManager.fetch { db in return try DBContact.contact(from: db, id: id) } } - static func fetchContact(by rowId: Int64) throws -> DBContact? { + static func fetchContact(by rowId: Int64) -> DBContact? { return dbManager.fetch { db in return try DBContact.contact(from: db, rowId: rowId) } @@ -47,12 +47,8 @@ class ContactDAO: ContactDAOProtocol { } static func findContactBy(phoneId: String) -> Contact? { - do { - guard let dbContact = try fetchContact(by: phoneId) else { return nil } - return Contact(contact: dbContact) - } catch { - return nil - } + guard let dbContact = fetchContact(by: phoneId) else { return nil } + return Contact(contact: dbContact) } static func findContactBy(username: String) -> Contact? { @@ -67,6 +63,19 @@ class ContactDAO: ContactDAOProtocol { return Contact(contact: contact) } + static func findContactBy(voxId: String) -> Contact? { + let voxIdColumn = Column(ContactTable.Column.voxId.title) + + guard let contact = dbManager.fetch({ db in + return try DBContact.filter(voxIdColumn == voxId).fetchOne(db) + }) else { + return nil + } + + return Contact(contact: contact) + } + + // MARK: -- Contacts static func fetchContacts(with statuses: [ContactStatus]) -> [Contact] { let statuses = statuses.map { $0.rawValue } @@ -79,8 +88,6 @@ class ContactDAO: ContactDAOProtocol { return contacts.map { Contact(contact: $0) } } - // MARK: -- Contacts - static func fetchContacts() -> [Contact] { let contacts = dbManager.fetch { db -> [DBContact] in return try DBContact.fetchAll(db) @@ -100,7 +107,7 @@ class ContactDAO: ContactDAOProtocol { // MARK: - Reader - static func fetchReader(for phoneId: String) throws -> Int64? { + static func fetchReader(for phoneId: String) -> Int64? { return dbManager.fetch { db in return try DBContact .filter(Column(ContactTable.Column.phoneId.title) == phoneId) diff --git a/Nynja/ContactDAOProtocol.swift b/Nynja/ContactDAOProtocol.swift index 5a0c72871..2c08b3579 100644 --- a/Nynja/ContactDAOProtocol.swift +++ b/Nynja/ContactDAOProtocol.swift @@ -12,11 +12,12 @@ protocol ContactDAOProtocol: DAOProtocol { // MARK: -- Contact static var currentContact: Contact? { get } - static func fetchContact(by id: String) throws -> DBContact? - static func fetchContact(by rowId: Int64) throws -> DBContact? + static func fetchContact(by id: String) -> DBContact? + static func fetchContact(by rowId: Int64) -> DBContact? static func findContactBy(phoneId: String) -> Contact? static func findContactBy(username: String) -> Contact? + static func findContactBy(voxId: String) -> Contact? // MARK: -- Contacts static func fetchContacts() -> [Contact] @@ -25,6 +26,6 @@ protocol ContactDAOProtocol: DAOProtocol { static func fetchContacts(with statuses: [ContactStatus]) -> [Contact] // MARK: -- Reader - static func fetchReader(for phoneId: String) throws -> Int64? + static func fetchReader(for phoneId: String) -> Int64? } diff --git a/Nynja/RosterDAO.swift b/Nynja/RosterDAO.swift new file mode 100644 index 000000000..cb5be4ddb --- /dev/null +++ b/Nynja/RosterDAO.swift @@ -0,0 +1,37 @@ +// +// RosterDAO.swift +// Nynja +// +// Created by Volodymyr Hryhoriev on 3/13/18. +// Copyright © 2018 TecSynt Solutions. All rights reserved. +// + +import GRDB + +class RosterDAO: RosterDAOProtocol { + + // MARK: - Fetch + static var currentRoster: Roster? { + guard let roster = currentDBRoster else { return nil } + return Roster(roster: roster) + } + + static var currentDBRoster: DBRoster? { + guard let rosterId = StorageService.sharedInstance.rosterId else { return nil } + return fetchRoster(by: rosterId) + } + + static func fetchRoster(by id: Int64) -> DBRoster? { + let idColumn = Column(RosterTable.Column.id.title) + + return dbManager.fetch { db in + return try DBRoster.filter(idColumn == id).fetchOne(db) + } + } + + static func findRosterBy(id: Int64) -> Roster? { + guard let roster = fetchRoster(by: id) else { return nil } + return Roster(roster: roster) + } + +} diff --git a/Nynja/RosterDAOProtocol.swift b/Nynja/RosterDAOProtocol.swift new file mode 100644 index 000000000..0f69a1339 --- /dev/null +++ b/Nynja/RosterDAOProtocol.swift @@ -0,0 +1,19 @@ +// +// RosterDAOProtocol.swift +// Nynja +// +// Created by Volodymyr Hryhoriev on 3/13/18. +// Copyright © 2018 TecSynt Solutions. All rights reserved. +// + +protocol RosterDAOProtocol: DAOProtocol { + + // MARK: - Fetch + static var currentRoster: Roster? { get } + static var currentDBRoster: DBRoster? { get } + + static func fetchRoster(by id: Int64) throws -> DBRoster? + + static func findRosterBy(id: Int64) -> Roster? + +} diff --git a/Nynja/Services/PushService.swift b/Nynja/Services/PushService.swift index 4696443fc..8e56c9f8e 100644 --- a/Nynja/Services/PushService.swift +++ b/Nynja/Services/PushService.swift @@ -62,10 +62,7 @@ class PushService: NSObject, PKPushRegistryDelegate { if let model = nynja["model"] as? String, let data = Data(base64Encoded: model), let bert = try? Bert.decode(data: data as NSData) as? BertTuple { if let payload = bert { if let room = get_Room().parse(bert: payload) as? Room { - try? StorageService.sharedInstance.writeInTransaction { db in - try DBRoom(room: room, rosterId: StorageService.sharedInstance.rosterId)?.saveAggregate(db) - return .commit - } + try? StorageService.sharedInstance.perform(action: .save, with: room) if let member = room.allMembers?.first(where: { $0.phone_id == StorageService.sharedInstance.phoneId @@ -81,10 +78,7 @@ class PushService: NSObject, PKPushRegistryDelegate { } if let contact = get_Contact().parse(bert: payload) as? Contact { - try? StorageService.sharedInstance.writeInTransaction { db in - try DBContact(contact: contact, rosterId: StorageService.sharedInstance.rosterId)?.saveAggregate(db) - return .commit - } + try? StorageService.sharedInstance.perform(action: .save, with: contact) if !contact.notifications { return @@ -108,6 +102,7 @@ class PushService: NSObject, PKPushRegistryDelegate { UIApplication.shared.scheduleLocalNotification(notif) return } + if let vox = payload.dictionaryPayload["voximplant"] as? Dictionary { voxID = (vox["display_name"] as? String) ?? nil } @@ -116,13 +111,7 @@ class PushService: NSObject, PKPushRegistryDelegate { } func showNotification() { - guard let contact = ProfileDAO.fetchProfile()?.rosters.first(where: { - $0.id == StorageService.sharedInstance.rosterId! - })?.contacts.first(where: { - $0.voxId == voxID - }) else { - return - } + guard let voxId = self.voxID, let contact = ContactDAO.findContactBy(voxId: voxId) else { return } showNotification(name: "\(contact.names) \(contact.surnames ?? "")") } @@ -136,9 +125,8 @@ class PushService: NSObject, PKPushRegistryDelegate { } private func calculateApplicationBadgeNumber() -> Int { - guard let dbProfile = ProfileDAO.fetchProfile(), let roster = dbProfile.rosters.first(where: { $0.id == StorageService.sharedInstance.rosterId }) else { - return 0 - } + guard let roster = RosterDAO.currentDBRoster else { return 0 } + let unreadContactsCount = roster.contacts.reduce(0) { $0 + $1.unread } let unreadRoomsCount = roster.rooms.reduce(0) { $0 + $1.unread } -- GitLab