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

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

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