mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-04 01:20:12 +00:00
Improvements to logging (#457)
* Use `.info` logging in most places. * Remove old objc logging support. * Fix table view controller. * Make sure timeline item content isn't logged. * Add tests.
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
//
|
||||
// Copyright 2022 New Vector Ltd
|
||||
//
|
||||
// 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
|
||||
|
||||
/// Represents all reactions of the same type for a single event.
|
||||
struct AggregatedReaction: Hashable {
|
||||
/// The reaction that was sent.
|
||||
let key: String
|
||||
/// The number of times this reactions was sent.
|
||||
let count: Int
|
||||
/// Whether to highlight the reaction, indicating that the current user sent this reaction.
|
||||
let isHighlighted: Bool
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
//
|
||||
// Copyright 2023 New Vector Ltd
|
||||
//
|
||||
// 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 MatrixRustSDK
|
||||
|
||||
// MARK: Redact message content from logs
|
||||
|
||||
extension EmoteMessageContent: CustomStringConvertible {
|
||||
public var description: String {
|
||||
String(describing: Self.self)
|
||||
}
|
||||
}
|
||||
|
||||
extension FileMessageContent: CustomStringConvertible {
|
||||
public var description: String {
|
||||
String(describing: Self.self)
|
||||
}
|
||||
}
|
||||
|
||||
extension ImageMessageContent: CustomStringConvertible {
|
||||
public var description: String {
|
||||
String(describing: Self.self)
|
||||
}
|
||||
}
|
||||
|
||||
extension NoticeMessageContent: CustomStringConvertible {
|
||||
public var description: String {
|
||||
String(describing: Self.self)
|
||||
}
|
||||
}
|
||||
|
||||
extension TextMessageContent: CustomStringConvertible {
|
||||
public var description: String {
|
||||
String(describing: Self.self)
|
||||
}
|
||||
}
|
||||
|
||||
extension VideoMessageContent: CustomStringConvertible {
|
||||
public var description: String {
|
||||
String(describing: Self.self)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,151 @@
|
||||
//
|
||||
// Copyright 2022 New Vector Ltd
|
||||
//
|
||||
// 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 CoreGraphics
|
||||
import Foundation
|
||||
import MatrixRustSDK
|
||||
|
||||
/// A protocol that contains the base `m.room.message` event content properties.
|
||||
/// The `CustomStringConvertible` conformance is to redact specific properties from the logs.
|
||||
protocol MessageContentProtocol: RoomMessageEventContentProtocol, CustomStringConvertible {
|
||||
var body: String { get }
|
||||
}
|
||||
|
||||
/// A timeline item that represents an `m.room.message` event.
|
||||
struct MessageTimelineItem<Content: MessageContentProtocol> {
|
||||
let item: MatrixRustSDK.EventTimelineItem
|
||||
let content: Content
|
||||
|
||||
var id: String {
|
||||
switch item.key() {
|
||||
case .transactionId(let txnID):
|
||||
return txnID
|
||||
case .eventId(let eventID):
|
||||
return eventID
|
||||
}
|
||||
}
|
||||
|
||||
var body: String {
|
||||
content.body
|
||||
}
|
||||
|
||||
var isEdited: Bool {
|
||||
item.content().asMessage()?.isEdited() == true
|
||||
}
|
||||
|
||||
var inReplyTo: String? {
|
||||
item.content().asMessage()?.inReplyTo()
|
||||
}
|
||||
|
||||
var sender: String {
|
||||
item.sender()
|
||||
}
|
||||
|
||||
var timestamp: Date {
|
||||
Date(timeIntervalSince1970: TimeInterval(item.timestamp() / 1000))
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Formatted Text
|
||||
|
||||
/// A protocol that contains the expected event content properties for a formatted message.
|
||||
protocol FormattedMessageContentProtocol: MessageContentProtocol {
|
||||
var formatted: FormattedBody? { get }
|
||||
}
|
||||
|
||||
extension MatrixRustSDK.TextMessageContent: FormattedMessageContentProtocol { }
|
||||
extension MatrixRustSDK.EmoteMessageContent: FormattedMessageContentProtocol { }
|
||||
extension MatrixRustSDK.NoticeMessageContent: FormattedMessageContentProtocol { }
|
||||
|
||||
/// A timeline item that represents an `m.room.message` event where
|
||||
/// the `msgtype` would likely contain a formatted body.
|
||||
extension MessageTimelineItem where Content: FormattedMessageContentProtocol {
|
||||
var htmlBody: String? {
|
||||
guard content.formatted?.format == .html else { return nil }
|
||||
return content.formatted?.body
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Media
|
||||
|
||||
extension MatrixRustSDK.ImageMessageContent: MessageContentProtocol { }
|
||||
|
||||
/// A timeline item that represents an `m.room.message` event with a `msgtype` of `m.image`.
|
||||
extension MessageTimelineItem where Content == MatrixRustSDK.ImageMessageContent {
|
||||
var source: MediaSourceProxy {
|
||||
.init(source: content.source)
|
||||
}
|
||||
|
||||
var width: CGFloat? {
|
||||
content.info?.width.map(CGFloat.init)
|
||||
}
|
||||
|
||||
var height: CGFloat? {
|
||||
content.info?.height.map(CGFloat.init)
|
||||
}
|
||||
|
||||
var blurhash: String? {
|
||||
content.info?.blurhash
|
||||
}
|
||||
}
|
||||
|
||||
extension MatrixRustSDK.VideoMessageContent: MessageContentProtocol { }
|
||||
|
||||
/// A timeline item that represents an `m.room.message` event with a `msgtype` of `m.video`.
|
||||
extension MessageTimelineItem where Content == MatrixRustSDK.VideoMessageContent {
|
||||
var source: MediaSourceProxy {
|
||||
.init(source: content.source)
|
||||
}
|
||||
|
||||
var thumbnailSource: MediaSourceProxy? {
|
||||
guard let src = content.info?.thumbnailSource else {
|
||||
return nil
|
||||
}
|
||||
return .init(source: src)
|
||||
}
|
||||
|
||||
var duration: UInt64 {
|
||||
content.info?.duration ?? 0
|
||||
}
|
||||
|
||||
var width: CGFloat? {
|
||||
content.info?.width.map(CGFloat.init)
|
||||
}
|
||||
|
||||
var height: CGFloat? {
|
||||
content.info?.height.map(CGFloat.init)
|
||||
}
|
||||
|
||||
var blurhash: String? {
|
||||
content.info?.blurhash
|
||||
}
|
||||
}
|
||||
|
||||
extension MatrixRustSDK.FileMessageContent: MessageContentProtocol { }
|
||||
|
||||
/// A timeline item that represents an `m.room.message` event with a `msgtype` of `m.file`.
|
||||
extension MessageTimelineItem where Content == MatrixRustSDK.FileMessageContent {
|
||||
var source: MediaSourceProxy {
|
||||
.init(source: content.source)
|
||||
}
|
||||
|
||||
var thumbnailSource: MediaSourceProxy? {
|
||||
guard let src = content.info?.thumbnailSource else {
|
||||
return nil
|
||||
}
|
||||
return .init(source: src)
|
||||
}
|
||||
}
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
//
|
||||
// Copyright 2022 New Vector Ltd
|
||||
//
|
||||
// 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
|
||||
|
||||
/// Properties of a matrix event that are common between all timeline items.
|
||||
struct RoomTimelineItemProperties: Hashable {
|
||||
/// Whether the item has been edited.
|
||||
var isEdited = false
|
||||
/// The aggregated reactions that have been sent for this item.
|
||||
var reactions: [AggregatedReaction] = []
|
||||
/// The delivery status for this item.
|
||||
var deliveryStatus: TimelineItemDeliveryStatus = .unknown
|
||||
}
|
||||
Reference in New Issue
Block a user