Commit 6062359d authored by shigemi miura's avatar shigemi miura

チャット・ワーニングモード変更時のエラー処理変更

parent 61d961f1
...@@ -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 = 46; CURRENT_PROJECT_VERSION = 47;
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 = 46; CURRENT_PROJECT_VERSION = 47;
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 = 46; CURRENT_PROJECT_VERSION = 47;
DEVELOPMENT_ASSET_PATHS = "\"Sailassist/Preview Content\""; DEVELOPMENT_ASSET_PATHS = "\"Sailassist/Preview Content\"";
DEVELOPMENT_TEAM = D2DC7QNNJ8; DEVELOPMENT_TEAM = D2DC7QNNJ8;
ENABLE_PREVIEWS = YES; ENABLE_PREVIEWS = YES;
......
...@@ -58,13 +58,23 @@ struct ChatView: View { ...@@ -58,13 +58,23 @@ struct ChatView: View {
if let id = message.messages.last?.messageId { if let id = message.messages.last?.messageId {
proxy.scrollTo(id, anchor: .bottom) proxy.scrollTo(id, anchor: .bottom)
//Warrningモードは既読は返さない
if message.messages.last?.message != nil {
let getMessage = GetMessage() let getMessage = GetMessage()
getMessage.readNotification() getMessage.readNotification()
}
message.viewCnt = 0 message.viewCnt = 0
} }
} }
} }
.onChange(of: message.mode) { newValue in
withAnimation {
if let id = message.messages.last?.messageId {
proxy.scrollTo(id, anchor: .bottom)
}
}
}
.onReceive(message.$messages) { (value) in .onReceive(message.$messages) { (value) in
withAnimation { withAnimation {
guard !value.isEmpty else {return} guard !value.isEmpty else {return}
...@@ -112,25 +122,29 @@ struct AlertChatMessage: View { ...@@ -112,25 +122,29 @@ struct AlertChatMessage: View {
var body: some View { var body: some View {
if message.mode == 1 { if message.mode == 1 {
HStack() {
Rectangle() Rectangle()
.fill(colorScheme == .light ? .black : .white) .fill(colorScheme == .light ? .black : .white)
.frame(width: 300, height: 1) .frame(width: 20, height: 1)
.overlay( Text("Warrning mode start " + DateTextLib.ISO86012FormatText(message.time, format: "yyyy/MM/dd HH:mm", errFormat: ""))
Text(" Warrning mode start " + DateTextLib.ISO86012FormatText(message.time, format: "yyyy/MM/dd HH:mm ", errFormat: ""))
.font(FontStyle.DateText.font) .font(FontStyle.DateText.font)
.foregroundColor(ColorSet.BodyDescriptiion.color) .foregroundColor(ColorSet.BodyDescriptiion.color)
.background(ColorSet.BackgroundPrimary.color) Rectangle()
) .fill(colorScheme == .light ? .black : .white)
.frame(width: 20, height: 1)
}
} else { } else {
HStack() {
Rectangle() Rectangle()
.fill(colorScheme == .light ? .black : .white) .fill(colorScheme == .light ? .black : .white)
.frame(width: 300, height: 1) .frame(width: 20, height: 1)
.overlay( Text("Warrning mode end " + DateTextLib.ISO86012FormatText(message.time, format: "yyyy/MM/dd HH:mm", errFormat: ""))
Text(" Warrning mode end " + DateTextLib.ISO86012FormatText(message.time, format: "yyyy/MM/dd HH:mm ", errFormat: ""))
.font(FontStyle.DateText.font) .font(FontStyle.DateText.font)
.foregroundColor(ColorSet.BodyDescriptiion.color) .foregroundColor(ColorSet.BodyDescriptiion.color)
.background(ColorSet.BackgroundPrimary.color) Rectangle()
) .fill(colorScheme == .light ? .black : .white)
.frame(width: 20, height: 1)
}
} }
} }
} }
......
...@@ -23,6 +23,7 @@ struct ChatInputView: View { ...@@ -23,6 +23,7 @@ struct ChatInputView: View {
@State var isActionSheet = false @State var isActionSheet = false
@State var isImagePicker = false @State var isImagePicker = false
@FocusState var isKeyboard: Bool @FocusState var isKeyboard: Bool
@State var isSignalrRestert = false
@Binding var isFocus: Bool @Binding var isFocus: Bool
var body: some View { var body: some View {
...@@ -96,9 +97,11 @@ struct ChatInputView: View { ...@@ -96,9 +97,11 @@ struct ChatInputView: View {
.resizable() .resizable()
.frame(width: 24, height: 24) .frame(width: 24, height: 24)
.padding(10) .padding(10)
.opacity(inputText.isEmpty ? 0.5 : 1.0)
} }
.padding(.vertical, 6) .padding(.vertical, 6)
.padding(.trailing, 11) .padding(.trailing, 11)
.disabled(inputText.isEmpty)
} }
.background(ColorSet.BackgroundSecondary.color) .background(ColorSet.BackgroundSecondary.color)
.fullScreenCover(isPresented: .constant(isImagePicker), onDismiss: { .fullScreenCover(isPresented: .constant(isImagePicker), onDismiss: {
...@@ -136,7 +139,13 @@ struct ChatInputView: View { ...@@ -136,7 +139,13 @@ struct ChatInputView: View {
} }
.frame(maxHeight: 55) .frame(maxHeight: 55)
.alert("Error", isPresented: $isChatAlert) { .alert("Error", isPresented: $isChatAlert) {
Button("OK") {} Button("OK") {
if self.isSignalrRestert {
let signalRService = SignalR()
signalRService.startConnection()
self.isSignalrRestert = false
}
}
} message: { } message: {
Text("The message could not be sent.") Text("The message could not be sent.")
} }
...@@ -187,7 +196,6 @@ struct ChatInputView: View { ...@@ -187,7 +196,6 @@ struct ChatInputView: View {
if let e = error { if let e = error {
print(debug: "chat error \(e)") print(debug: "chat error \(e)")
// msg.messages.removeLast() //最後に追加したメッセージを削除
isChatAlert = true isChatAlert = true
} else { } else {
isKeyboard = false isKeyboard = false
...@@ -204,10 +212,7 @@ struct ChatInputView: View { ...@@ -204,10 +212,7 @@ struct ChatInputView: View {
signalRService.stopConnection() signalRService.stopConnection()
Thread.sleep(forTimeInterval: 1.0) Thread.sleep(forTimeInterval: 1.0)
signalRService.startConnection() self.isSignalrRestert = true
Thread.sleep(forTimeInterval: 2.0)
// signalRService.chatMessage(message: inputText, completion: responseChatMessage)
} }
} }
} }
......
...@@ -205,8 +205,8 @@ class AppDelegate: NSObject, UIApplicationDelegate ,MSNotificationHubDelegate, M ...@@ -205,8 +205,8 @@ class AppDelegate: NSObject, UIApplicationDelegate ,MSNotificationHubDelegate, M
self.msg.mode = false self.msg.mode = false
} }
let message = GetMessage() let ownMsg = ChatMessage(shipId: message.shipId, messageId: UUID().uuidString, type: 3, time: DateTextLib.Date2ISO8601Text(Date()), location: message.location, from: nil, fromId: nil, mode: message.mode, message: nil, stampId: 0, viewer: [])
message.start() self.msg.messages.append(ownMsg)
} }
//アプリ終了時 //アプリ終了時
...@@ -273,10 +273,11 @@ class SignalR: NSObject { ...@@ -273,10 +273,11 @@ class SignalR: NSObject {
} }
func chatMode(mode: Bool, completion: @escaping (_ error: Error?) -> Void) { func chatMode(mode: Bool, completion: @escaping (_ error: Error?) -> Void) {
print(debug: "chatMode \(mode)")
var request = ReqChatModeMessage(shipId: Preferences.shipId) var request = ReqChatModeMessage(shipId: Preferences.shipId)
request.location = 2 //1:Shore , 2:Ship request.location = 2 //1:Shore , 2:Ship
request.fromeId = String(SharingData.my.id) //ユーザーID request.fromeId = String(SharingData.my.id) //ユーザーID
if mode == true{ if mode == true {
request.mode = 1 request.mode = 1
} else { } else {
request.mode = 0 request.mode = 0
...@@ -344,16 +345,10 @@ extension AppDelegate: UNUserNotificationCenterDelegate { ...@@ -344,16 +345,10 @@ extension AppDelegate: UNUserNotificationCenterDelegate {
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)")
if strTitle == "Chat Warning" {
if SharingData.message.mode {
return
}
}
//送信先名称が同一の場合は通知を出さない //送信先名称が同一の場合は通知を出さない
if subtitle == Preferences.UserName { if subtitle == Preferences.UserName {
return return
......
...@@ -362,7 +362,7 @@ class SharingData{ ...@@ -362,7 +362,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 @Published var sendInf: Bool = false //送信状態
func changeMode(){ func changeMode(){
self.mode.toggle() self.mode.toggle()
......
...@@ -109,12 +109,14 @@ struct MainTabView: View { ...@@ -109,12 +109,14 @@ struct MainTabView: View {
struct CustomTabBar: View { struct CustomTabBar: View {
@EnvironmentObject private var selectedTabModel: SelectedTabModel @EnvironmentObject private var selectedTabModel: SelectedTabModel
@State private var isModeAlert: Bool = false
@State var isLocationAlert = false @State var isLocationAlert = false
@Environment(\.openURL) var openURL @Environment(\.openURL) var openURL
@ObservedObject var my = SharingData.my @ObservedObject var my = SharingData.my
@ObservedObject var message = SharingData.message @ObservedObject var message = SharingData.message
@ObservedObject var location = SharingData.location @ObservedObject var location = SharingData.location
@ObservedObject var pushHistory = SharingData.pushHistory @ObservedObject var pushHistory = SharingData.pushHistory
@State var isSignalrRestert = false
var body: some View { var body: some View {
VStack(spacing: 0){ VStack(spacing: 0){
...@@ -211,15 +213,18 @@ struct CustomTabBar: View { ...@@ -211,15 +213,18 @@ struct CustomTabBar: View {
} }
.background(ColorSet.BottomNav.color) .background(ColorSet.BottomNav.color)
.alert("", isPresented: $selectedTabModel.isShowChangeEmrMode) { .alert("", isPresented: $selectedTabModel.isShowChangeEmrMode) {
Button("Yes"){ Button("Yes") {
var chatMode = SharingData.message.mode var chatMode = SharingData.message.mode
chatMode.toggle() chatMode.toggle()
let signalRService = SignalR() let signalRService = SignalR()
signalRService.chatMode(mode: chatMode, completion: responseChatMode) signalRService.chatMode(mode: chatMode, completion: responseChatMode)
} SharingData.message.sendInf = true
Button("No"){
DispatchQueue.main.asyncAfter(deadline: .now() + 3.0) {
restartChatMode()
}
} }
Button("No") {}
} message: { } message: {
Text("Do you change an warning mode?") Text("Do you change an warning mode?")
} }
...@@ -241,18 +246,46 @@ struct CustomTabBar: View { ...@@ -241,18 +246,46 @@ struct CustomTabBar: View {
} message: { } message: {
Text("A new version of this app is available.") Text("A new version of this app is available.")
} }
.alert("Error", isPresented: $isModeAlert) {
Button("OK") {
if self.isSignalrRestert {
let signalRService = SignalR()
signalRService.startConnection()
isSignalrRestert = false
}
}
} message: {
Text("The mode did not change.")
}
} }
/** /**
* Warninngモードレスポンス * Warninngモードレスポンス
*/ */
func responseChatMode(error: Error?) { func responseChatMode(error: Error?) {
print(debug: "responseChatMode")
SharingData.message.sendInf = false
if let e = error { if let e = error {
print(debug: "Error chat:\(e)") print(debug: "Error chat:\(e)")
isModeAlert = true
} else { } else {
SharingData.message.changeMode() SharingData.message.changeMode()
} }
} }
/**
* モード変更レスポンスが無かった場合
*/
func restartChatMode() {
if SharingData.message.sendInf {
let signalRService = SignalR()
signalRService.stopConnection()
Thread.sleep(forTimeInterval: 1.0)
self.isSignalrRestert = true
}
}
} }
#Preview { #Preview {
......
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