Commit 989e443a authored by shigemi miura's avatar shigemi miura

チャットリセット処理追加

Sign Out時にアプリをリセット Warning表示対応
parent 71f416a7
...@@ -1307,7 +1307,7 @@ ...@@ -1307,7 +1307,7 @@
CODE_SIGN_ENTITLEMENTS = Sailassist/Sailassist.entitlements; CODE_SIGN_ENTITLEMENTS = Sailassist/Sailassist.entitlements;
CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic; CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 40; CURRENT_PROJECT_VERSION = 41;
DEVELOPMENT_ASSET_PATHS = "\"Sailassist/Preview Content\""; DEVELOPMENT_ASSET_PATHS = "\"Sailassist/Preview Content\"";
DEVELOPMENT_TEAM = D2DC7QNNJ8; DEVELOPMENT_TEAM = D2DC7QNNJ8;
ENABLE_PREVIEWS = YES; ENABLE_PREVIEWS = YES;
...@@ -1353,7 +1353,7 @@ ...@@ -1353,7 +1353,7 @@
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
CODE_SIGN_ENTITLEMENTS = Sailassist/Sailassist.entitlements; CODE_SIGN_ENTITLEMENTS = Sailassist/Sailassist.entitlements;
CODE_SIGN_STYLE = Automatic; CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 40; CURRENT_PROJECT_VERSION = 41;
DEVELOPMENT_ASSET_PATHS = "\"Sailassist/Preview Content\""; DEVELOPMENT_ASSET_PATHS = "\"Sailassist/Preview Content\"";
DEVELOPMENT_TEAM = D2DC7QNNJ8; DEVELOPMENT_TEAM = D2DC7QNNJ8;
ENABLE_PREVIEWS = YES; ENABLE_PREVIEWS = YES;
...@@ -1536,7 +1536,7 @@ ...@@ -1536,7 +1536,7 @@
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
CODE_SIGN_ENTITLEMENTS = Sailassist/Sailassist.entitlements; CODE_SIGN_ENTITLEMENTS = Sailassist/Sailassist.entitlements;
CODE_SIGN_STYLE = Automatic; CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 40; CURRENT_PROJECT_VERSION = 41;
DEVELOPMENT_ASSET_PATHS = "\"Sailassist/Preview Content\""; DEVELOPMENT_ASSET_PATHS = "\"Sailassist/Preview Content\"";
DEVELOPMENT_TEAM = D2DC7QNNJ8; DEVELOPMENT_TEAM = D2DC7QNNJ8;
ENABLE_PREVIEWS = YES; ENABLE_PREVIEWS = YES;
......
...@@ -57,6 +57,10 @@ struct ChatView: View { ...@@ -57,6 +57,10 @@ struct ChatView: View {
withAnimation { withAnimation {
if let id = message.messages.last?.messageId { if let id = message.messages.last?.messageId {
proxy.scrollTo(id, anchor: .bottom) proxy.scrollTo(id, anchor: .bottom)
let getMessage = GetMessage()
getMessage.readNotification()
message.viewCnt = 0 message.viewCnt = 0
} }
} }
......
...@@ -90,7 +90,7 @@ struct ChatInputView: View { ...@@ -90,7 +90,7 @@ struct ChatInputView: View {
.padding(.leading, 20) .padding(.leading, 20)
Button{ Button{
sendChatMessage(message: inputText) sendChatMessage()
} label: { } label: {
Image("send") Image("send")
.resizable() .resizable()
...@@ -167,23 +167,49 @@ struct ChatInputView: View { ...@@ -167,23 +167,49 @@ struct ChatInputView: View {
/** /**
* チャット送信 * チャット送信
*/ */
func sendChatMessage(message: String) { func sendChatMessage() {
if !SharingData.message.sendInf {
let signalRService = SignalR() let signalRService = SignalR()
signalRService.chatMessage(message: inputText, completion: responseChatMessage) signalRService.chatMessage(message: inputText, completion: responseChatMessage)
SharingData.message.sendInf = true
DispatchQueue.main.asyncAfter(deadline: .now() + 3.0) {
restartChatMessage()
}
}
} }
/** /**
* チャットレスポンス * チャットレスポンス
*/ */
func responseChatMessage(error: Error?) { func responseChatMessage(error: Error?) {
SharingData.message.sendInf = false
if let e = error { if let e = error {
msg.messages.removeLast() //最後に追加したメッセージを削除 print(debug: "chat error \(e)")
// msg.messages.removeLast() //最後に追加したメッセージを削除
isChatAlert = true isChatAlert = true
} else { } else {
isKeyboard = false isKeyboard = false
inputText = "" inputText = ""
} }
} }
/**
* チャットレスポンスが無かった場合
*/
func restartChatMessage() {
if SharingData.message.sendInf {
let signalRService = SignalR()
signalRService.stopConnection()
Thread.sleep(forTimeInterval: 1.0)
signalRService.startConnection()
Thread.sleep(forTimeInterval: 2.0)
// signalRService.chatMessage(message: inputText, completion: responseChatMessage)
}
}
} }
#Preview { #Preview {
......
...@@ -11,7 +11,6 @@ struct MyChatContentView: View { ...@@ -11,7 +11,6 @@ struct MyChatContentView: View {
var message : ChatMessage var message : ChatMessage
var body: some View { var body: some View {
HStack { HStack {
Spacer() Spacer()
VStack(alignment: .trailing, spacing: 6) { VStack(alignment: .trailing, spacing: 6) {
Group { Group {
...@@ -70,12 +69,15 @@ struct MyChatContentView: View { ...@@ -70,12 +69,15 @@ struct MyChatContentView: View {
var shipViewer = 0 var shipViewer = 0
var companyViewr = 0 var companyViewr = 0
for viewer in message.viewer { for viewer in message.viewer {
//船のIDは全て同じ
// if viewer.id != String(SharingData.my.id) {
if viewer.location == 1 { if viewer.location == 1 {
companyViewr += 1 companyViewr += 1
} else { } else {
shipViewer += 1 shipViewer += 1
} }
} }
// }
return (shipViewer, companyViewr) return (shipViewer, companyViewr)
} }
} }
......
...@@ -55,8 +55,8 @@ struct FuelSwitchingView: View { ...@@ -55,8 +55,8 @@ struct FuelSwitchingView: View {
if let ecaArea = taskViewModel.edittingEcaArea { if let ecaArea = taskViewModel.edittingEcaArea {
var newData = ecaArea var newData = ecaArea
newData.isRunning = false newData.isRunning = false
newData.status = EcaState.cancel newData.status = EcaState.end
ecaData.editEcaArea(key: ecaArea.areaId, value: newData, type: EcaOperation.Cancel) ecaData.editEcaArea(key: ecaArea.areaId, value: newData, type: EcaOperation.End)
} }
taskViewModel.edittingEcaArea = nil taskViewModel.edittingEcaArea = nil
} }
......
...@@ -233,6 +233,11 @@ struct MenuView: View { ...@@ -233,6 +233,11 @@ struct MenuView: View {
SharingData.map.starboardLine = [] SharingData.map.starboardLine = []
connection!.stop() connection!.stop()
UIControl().sendAction(#selector(URLSessionTask.suspend), to: UIApplication.shared, for: nil)
Timer.scheduledTimer(withTimeInterval: 0.2, repeats: false) { _ in
exit(0)
}
} }
Button("No") {} Button("No") {}
} message: { Text("Are you sure?") } } message: { Text("Are you sure?") }
......
...@@ -121,8 +121,6 @@ class AppDelegate: NSObject, UIApplicationDelegate ,MSNotificationHubDelegate, M ...@@ -121,8 +121,6 @@ class AppDelegate: NSObject, UIApplicationDelegate ,MSNotificationHubDelegate, M
.build() .build()
if let r_connection = connection { if let r_connection = connection {
// r_connection.stop()
//callbackが作成されない?
r_connection.on(method: "ChatMessage", callback: { (message: ResChatMessage) in r_connection.on(method: "ChatMessage", callback: { (message: ResChatMessage) in
self.handleChatMessage(message: message) self.handleChatMessage(message: message)
}) })
...@@ -206,6 +204,9 @@ class AppDelegate: NSObject, UIApplicationDelegate ,MSNotificationHubDelegate, M ...@@ -206,6 +204,9 @@ class AppDelegate: NSObject, UIApplicationDelegate ,MSNotificationHubDelegate, M
} else { } else {
self.msg.mode = false self.msg.mode = false
} }
let message = GetMessage()
message.start()
} }
//アプリ終了時 //アプリ終了時
...@@ -282,6 +283,17 @@ class SignalR: NSObject { ...@@ -282,6 +283,17 @@ class SignalR: NSObject {
} }
connection!.invoke(method: "ChatMode", request, invocationDidComplete: completion) connection!.invoke(method: "ChatMode", request, invocationDidComplete: completion)
} }
func stopConnection() {
let test = connection.debugDescription
print(debug: "Test: Chat Message \(test)")
connection!.stop()
}
func startConnection() {
connection!.start()
}
} }
class ChatHubConnectionDelegate: HubConnectionDelegate { class ChatHubConnectionDelegate: HubConnectionDelegate {
...@@ -333,8 +345,7 @@ extension AppDelegate: UNUserNotificationCenterDelegate { ...@@ -333,8 +345,7 @@ extension AppDelegate: UNUserNotificationCenterDelegate {
} }
let subtitle = arrAlert["subtitle"] as? String ?? "" //送信先名称 let subtitle = arrAlert["subtitle"] as? String ?? "" //送信先名称
let strTitle = arrAlert["title"] as? String ?? "" //船名 let strTitle = arrAlert["title"] as? String ?? "" //船名
let strBody = arrAlert["body"] as? String ?? "" //送信内容 // let strBody = arrAlert["body"] as? String ?? "" //送信内容
// print(debug: "called \(subtitle) \(strTitle) \(strBody)") // print(debug: "called \(subtitle) \(strTitle) \(strBody)")
if strTitle == "Chat Warning" { if strTitle == "Chat Warning" {
...@@ -392,10 +403,9 @@ extension AppDelegate: UNUserNotificationCenterDelegate { ...@@ -392,10 +403,9 @@ extension AppDelegate: UNUserNotificationCenterDelegate {
completionHandler() completionHandler()
return return
} }
let subtitle = arrAlert["subtitle"] as? String ?? "" //送信内容 // let subtitle = arrAlert["subtitle"] as? String ?? "" //送信内容
let strTitle = arrAlert["title"] as? String ?? "" //船名 // let strTitle = arrAlert["title"] as? String ?? "" //船名
let strBody = arrAlert["body"] as? String ?? "" //送信先名称 // let strBody = arrAlert["body"] as? String ?? "" //送信先名称
// print(debug: "called \(subtitle) \(strTitle) \(strBody)") // print(debug: "called \(subtitle) \(strTitle) \(strBody)")
case "sailassist": case "sailassist":
print(debug: "sailassist") print(debug: "sailassist")
......
...@@ -358,6 +358,7 @@ class SharingData{ ...@@ -358,6 +358,7 @@ class SharingData{
@Published var messages: [ChatMessage] = [] @Published var messages: [ChatMessage] = []
@Published var users: [ChatUser] = [] @Published var users: [ChatUser] = []
@Published var viewCnt: Int = 0 //未読数 @Published var viewCnt: Int = 0 //未読数
@Published var sendInf: Bool = false
func changeMode(){ func changeMode(){
self.mode.toggle() self.mode.toggle()
......
...@@ -129,6 +129,7 @@ struct CustomTabBar: View { ...@@ -129,6 +129,7 @@ struct CustomTabBar: View {
location.focusOwnShip = true location.focusOwnShip = true
} else if tab == .chat { } else if tab == .chat {
let message = GetMessage() let message = GetMessage()
message.start()
message.readNotification() message.readNotification()
message.checkUnreadMessages() message.checkUnreadMessages()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment