MESSENGER-5706 change appearance and use wellknown

This commit is contained in:
JanNiklas Grabowski
2024-02-27 14:36:30 +01:00
parent d15d8e9f76
commit 3ddb4e4d04
8 changed files with 87 additions and 21 deletions

View File

@@ -495,13 +495,14 @@ class AllChatsViewController: HomeViewController {
// bwi: 5706 show federation announcement promt
func bwiCheckForFederationAnnouncementPromt() {
if AppConfigService.shared.shouldShowFederationAnnouncement() {
if self.mainSession.homeserverWellknown.shouldShowFederationAnnouncement() {
let sharedSettings = RiotSharedSettings(session: self.mainSession)
if sharedSettings.shouldShowFederationAnnouncement() {
let viewController = FederationAnnouncementSheet().makeViewController()
viewController.modalPresentationStyle = .formSheet
self.present(viewController, animated: true, completion: nil)
sharedSettings.setFederationAnnouncement()
self.present(viewController, animated: true) {
sharedSettings.setFederationAnnouncement()
}
}
}
}

View File

@@ -24,5 +24,4 @@ struct AppConfig: Codable, Equatable {
var pusherUrl: String? = nil
var permalinkUrl: String? = nil
var externalUrlScheme: String? = nil
var shouldShowFederationAnnouncement: Bool? = false
}

View File

@@ -148,9 +148,6 @@ extension UserDefaults
if let externalUrlScheme = dict[externalUrlSchemeKey] as? String {
config.externalUrlScheme = externalUrlScheme
}
if let shouldShowFederationAnnouncement = dict[federationAnnouncementKey] as? Bool {
config.shouldShowFederationAnnouncement = shouldShowFederationAnnouncement
}
// app config needs at least a valid server url
if let serverUrl = config.serverUrl {
@@ -206,7 +203,4 @@ extension UserDefaults
return appConfig.externalUrlScheme
}
func shouldShowFederationAnnouncement() -> Bool {
return appConfig.shouldShowFederationAnnouncement ?? false
}
}

View File

@@ -48,7 +48,8 @@ struct FederationAnnouncementView: View {
let imageStackScale = 0.30
let imageStackShift = 5.0
let lineWith = 7.0
let outerLineWith = 5.0
let innerLineWith = 1.0
let spacing = 16.0
var announcementText: AttributedString {
@@ -69,14 +70,19 @@ struct FederationAnnouncementView: View {
ZStack(alignment: .center) {
Circle()
.fill(Color(theme.colors.quinaryContent))
.overlay(Circle()
.stroke(Color(theme.colors.background), lineWidth: lineWith))
.padding(outerLineWith)
.offset(x:((getImageSize(width: geo.size.width, height: geo.size.height) * imageStackScale) / imageStackShift))
Image("welcome_experience_1")
Image(uiImage: Asset.SharedImages.loginFlowLogo.image)
.resizable()
.aspectRatio(contentMode: .fill)
.clipShape(Circle())
.padding(innerLineWith)
.background(Color(theme.colors.quinaryContent))
.clipShape(Circle())
.padding(outerLineWith)
.background(Color(ThemeService.shared().theme.backgroundColor))
.clipShape(Circle())
.overlay(Circle()
.stroke(Color(theme.colors.background), lineWidth: lineWith))
.offset(x:-((getImageSize(width: geo.size.width, height: geo.size.height) * imageStackScale) / imageStackShift))
}
.frame(width: getImageSize(width: geo.size.width, height: geo.size.height) * imageStackScale, height: getImageSize(width: geo.size.width, height: geo.size.height) * imageStackScale)

View File

@@ -59,7 +59,8 @@ struct RoomFederationDecisionView: View {
var roomAvatarImage: UIImage
let imageStackScale = 0.30
let imageStackShift = 5.0
let lineWith = 7.0
let outerLineWith = 5.0
let innerLineWith = 1.0
let spacing = 16.0
@@ -73,14 +74,17 @@ struct RoomFederationDecisionView: View {
ZStack(alignment: .center) {
Circle()
.fill(Color(theme.colors.quinaryContent))
.overlay(Circle()
.stroke(Color(theme.colors.background), lineWidth: lineWith))
.padding(outerLineWith)
.offset(x:((getImageSize(width: geo.size.width, height: geo.size.height) * imageStackScale) / imageStackShift))
Image(uiImage: roomAvatarImage)
.resizable()
.clipShape(Circle())
.overlay(Circle()
.stroke(Color(theme.colors.background), lineWidth: lineWith))
.padding(innerLineWith)
.background(Color(theme.colors.quinaryContent))
.clipShape(Circle())
.padding(outerLineWith)
.background(Color(ThemeService.shared().theme.backgroundColor))
.clipShape(Circle())
.offset(x:-((getImageSize(width: geo.size.width, height: geo.size.height) * imageStackScale) / imageStackShift))
}
.frame(width: getImageSize(width: geo.size.width, height: geo.size.height) * imageStackScale, height: getImageSize(width: geo.size.width, height: geo.size.height) * imageStackScale)

View File

@@ -112,4 +112,22 @@ public extension MXWellKnown {
return nil
}
}
@objc func shouldShowFederationAnnouncement() -> Bool {
do {
guard let bwiDict = self.jsonDictionary()["de.bwi"] as? [String : Any] else {
return false
}
let bwi = try WellknownBWI(dict: bwiDict)
if let federation = bwi.federation {
return federation.showAnnouncement ?? false
} else {
return false
}
}
catch {
return false
}
}
}

View File

@@ -20,6 +20,7 @@ import Foundation
struct WellknownBWI {
let dataPrivacyURL: String?
let imprintURL: String?
let federation: WellknownFederation?
init(dict: [String: Any]) throws {
let jsonData = try JSONSerialization.data(withJSONObject: dict, options: [])
@@ -32,5 +33,6 @@ extension WellknownBWI: Decodable {
enum CodingKeys: String, CodingKey {
case dataPrivacyURL = "data_privacy_url"
case imprintURL = "imprint_url"
case federation = "federation"
}
}

View File

@@ -0,0 +1,42 @@
//
/*
* Copyright (c) 2024 BWI GmbH
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import Foundation
struct WellknownFederation {
/// show federation announcement
let showAnnouncement: Bool?
/// show federation tutorial (3 screens)
let showIntroduction: Bool
/// enables the federation feature for the app - show federation views, activate invitation rules, show federation settings
let enable: Bool
init(dict: [String: Any]) throws {
let jsonData = try JSONSerialization.data(withJSONObject: dict, options: [])
let decoder = JSONDecoder()
self = try decoder.decode(Self.self, from: jsonData)
}
}
extension WellknownFederation: Decodable {
enum CodingKeys: String, CodingKey {
case showAnnouncement = "show_announcement"
case showIntroduction = "show_introduction"
case enable = "enable"
}
}