Merge branch 'ismail/5068_design_tweaks' into ismail/5096_thread_notifications

This commit is contained in:
ismailgulek
2022-01-19 00:12:40 +03:00
102 changed files with 1607 additions and 771 deletions
@@ -28,7 +28,7 @@
</connections>
</tableView>
<view contentMode="scaleToFill" placeholderIntrinsicWidth="414" placeholderIntrinsicHeight="818" translatesAutoresizingMaskIntoConstraints="NO" id="7VY-m9-wCS" customClass="ThreadListEmptyView" customModule="Riot" customModuleProvider="target">
<rect key="frame" x="0.0" y="44" width="414" height="852"/>
<rect key="frame" x="0.0" y="0.0" width="414" height="896"/>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<connections>
<outlet property="delegate" destination="V8j-Lb-PgC" id="SQT-2N-wnf"/>
@@ -42,10 +42,10 @@
<constraint firstItem="X8K-NO-SQ3" firstAttribute="top" secondItem="bFg-jh-JZB" secondAttribute="top" id="Mfw-In-peq"/>
<constraint firstAttribute="bottom" secondItem="7VY-m9-wCS" secondAttribute="bottom" id="PkX-MO-5aO"/>
<constraint firstAttribute="bottom" secondItem="X8K-NO-SQ3" secondAttribute="bottom" id="SIG-7P-2CK"/>
<constraint firstItem="7VY-m9-wCS" firstAttribute="top" secondItem="EL9-GA-lwo" secondAttribute="top" id="aFs-kb-rJp"/>
<constraint firstItem="7VY-m9-wCS" firstAttribute="leading" secondItem="EL9-GA-lwo" secondAttribute="leading" id="acw-H6-LKX"/>
<constraint firstItem="X8K-NO-SQ3" firstAttribute="leading" secondItem="EL9-GA-lwo" secondAttribute="leading" id="ehI-Nc-6di"/>
<constraint firstAttribute="trailing" secondItem="X8K-NO-SQ3" secondAttribute="trailing" id="hbZ-R8-8kH"/>
<constraint firstItem="7VY-m9-wCS" firstAttribute="top" secondItem="bFg-jh-JZB" secondAttribute="top" id="obE-c9-v49"/>
</constraints>
</view>
<connections>
@@ -136,7 +136,7 @@ final class ThreadListViewModel: ThreadListViewModelProtocol {
return ThreadListEmptyViewModel(icon: Asset.Images.threadsIcon.image,
title: VectorL10n.threadsEmptyTitle,
info: VectorL10n.threadsEmptyInfoMy,
tip: VectorL10n.threadsEmptyTip,
tip: nil,
showAllThreadsButtonTitle: VectorL10n.threadsEmptyShowAllThreads,
showAllThreadsButtonHidden: false)
}
@@ -193,6 +193,7 @@ final class ThreadListViewModel: ThreadListViewModelProtocol {
rootMessageSenderAvatar: rootAvatarViewData,
rootMessageSenderDisplayName: rootMessageSender?.displayname,
rootMessageText: rootMessageText,
rootMessageRedacted: thread.rootMessage?.isRedactedEvent() ?? false,
lastMessageTime: lastMessageTime,
summaryViewModel: summaryViewModel,
notificationStatus: notificationStatus)
@@ -205,6 +206,23 @@ final class ThreadListViewModel: ThreadListViewModelProtocol {
guard let message = thread.rootMessage else {
return nil
}
if message.isReply(), let newMessage = message.copy() as? MXEvent {
var jsonDict = newMessage.isEncrypted ? newMessage.clear?.jsonDictionary() : newMessage.jsonDictionary()
if var content = jsonDict?["content"] as? [String: Any] {
content.removeValue(forKey: "format")
content.removeValue(forKey: "formatted_body")
content.removeValue(forKey: kMXEventRelationRelatesToKey)
if let replyText = MXReplyEventParser().parse(newMessage)?.bodyParts.replyText {
content["body"] = replyText
}
jsonDict?["content"] = content
}
let trimmedMessage = MXEvent(fromJSON: jsonDict)
let formatterError = UnsafeMutablePointer<MXKEventFormatterError>.allocate(capacity: 1)
return eventFormatter.attributedString(from: trimmedMessage,
with: roomState,
error: formatterError)
}
let formatterError = UnsafeMutablePointer<MXKEventFormatterError>.allocate(capacity: 1)
return eventFormatter.attributedString(from: message,
with: roomState,
@@ -22,6 +22,16 @@ class ThreadTableViewCell: UITableViewCell {
private enum Constants {
static let separatorInset: UIEdgeInsets = UIEdgeInsets(top: 0, left: 56, bottom: 0, right: 0)
}
private var theme: Theme = ThemeService.shared().theme
private var configuredSenderId: String?
private var configuredRootMessageRedacted: Bool = false
private var rootMessageColor: UIColor {
return configuredRootMessageRedacted ?
theme.colors.secondaryContent :
theme.colors.primaryContent
}
@IBOutlet private weak var rootMessageAvatarView: UserAvatarView!
@IBOutlet private weak var rootMessageSenderLabel: UILabel!
@@ -47,13 +57,15 @@ class ThreadTableViewCell: UITableViewCell {
} else {
rootMessageAvatarView.avatarImageView.image = nil
}
if let senderUserId = viewModel.rootMessageSenderUserId {
rootMessageSenderLabel.textColor = Self.usernameColorGenerator.color(from: senderUserId)
} else {
rootMessageSenderLabel.textColor = Self.usernameColorGenerator.defaultColor
}
configuredSenderId = viewModel.rootMessageSenderUserId
configuredRootMessageRedacted = viewModel.rootMessageRedacted
updateRootMessageSenderColor()
rootMessageSenderLabel.text = viewModel.rootMessageSenderDisplayName
rootMessageContentLabel.attributedText = viewModel.rootMessageText
if let rootMessageText = viewModel.rootMessageText {
updateRootMessageContentAttributes(rootMessageText, color: rootMessageColor)
} else {
rootMessageContentLabel.attributedText = nil
}
lastMessageTimeLabel.text = viewModel.lastMessageTime
if let summaryViewModel = viewModel.summaryViewModel {
summaryView.configure(withViewModel: summaryViewModel)
@@ -61,6 +73,22 @@ class ThreadTableViewCell: UITableViewCell {
notificationStatusView.status = viewModel.notificationStatus
}
private func updateRootMessageSenderColor() {
if let senderUserId = configuredSenderId {
rootMessageSenderLabel.textColor = Self.usernameColorGenerator.color(from: senderUserId)
} else {
rootMessageSenderLabel.textColor = Self.usernameColorGenerator.defaultColor
}
}
private func updateRootMessageContentAttributes(_ string: NSAttributedString, color: UIColor) {
let mutable = NSMutableAttributedString(attributedString: string)
mutable.addAttributes([
.foregroundColor: color
], range: NSRange(location: 0, length: mutable.length))
rootMessageContentLabel.attributedText = mutable
}
}
extension ThreadTableViewCell: NibReusable {}
@@ -68,10 +96,14 @@ extension ThreadTableViewCell: NibReusable {}
extension ThreadTableViewCell: Themable {
func update(theme: Theme) {
self.theme = theme
Self.usernameColorGenerator.defaultColor = theme.colors.primaryContent
Self.usernameColorGenerator.userNameColors = theme.colors.namesAndAvatars
updateRootMessageSenderColor()
rootMessageAvatarView.backgroundColor = .clear
rootMessageContentLabel.textColor = theme.colors.primaryContent
if let attributedText = rootMessageContentLabel.attributedText {
updateRootMessageContentAttributes(attributedText, color: rootMessageColor)
}
lastMessageTimeLabel.textColor = theme.colors.secondaryContent
summaryView.update(theme: theme)
summaryView.backgroundColor = .clear
@@ -58,7 +58,7 @@
<nil key="highlightedColor"/>
</label>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="Md3-uq-cSB" customClass="ThreadSummaryView" customModule="Riot" customModuleProvider="target">
<rect key="frame" x="47" y="56" width="245" height="32"/>
<rect key="frame" x="44" y="60" width="264" height="32"/>
<color key="backgroundColor" systemColor="systemBackgroundColor"/>
<constraints>
<constraint firstAttribute="height" constant="32" id="Pnm-yi-36O"/>
@@ -72,7 +72,7 @@
<constraint firstAttribute="trailing" secondItem="aUq-D2-1KM" secondAttribute="trailing" constant="10" id="Du2-UR-wBe"/>
<constraint firstAttribute="bottom" secondItem="Md3-uq-cSB" secondAttribute="bottom" constant="12" id="Ppd-HN-Ehg"/>
<constraint firstItem="I32-A5-WWw" firstAttribute="leading" secondItem="H2p-sc-9uM" secondAttribute="leading" constant="12" id="Trt-CK-Tly"/>
<constraint firstItem="Md3-uq-cSB" firstAttribute="leading" secondItem="H2p-sc-9uM" secondAttribute="leading" constant="47" id="Vpf-02-TgV"/>
<constraint firstItem="Md3-uq-cSB" firstAttribute="leading" secondItem="H2p-sc-9uM" secondAttribute="leading" constant="44" id="Vpf-02-TgV"/>
<constraint firstAttribute="trailing" secondItem="xzR-f9-3qV" secondAttribute="trailing" constant="28" id="Zz9-PK-l9b"/>
<constraint firstItem="C2U-Ih-4Oh" firstAttribute="leading" secondItem="108-Xh-aZf" secondAttribute="trailing" constant="8" id="bE8-Yy-3B9"/>
<constraint firstItem="xzR-f9-3qV" firstAttribute="leading" secondItem="I32-A5-WWw" secondAttribute="trailing" constant="12" id="g8i-lt-K8f"/>
@@ -80,7 +80,7 @@
<constraint firstItem="108-Xh-aZf" firstAttribute="leading" secondItem="I32-A5-WWw" secondAttribute="trailing" constant="12" id="sXf-FI-gD3"/>
<constraint firstItem="xzR-f9-3qV" firstAttribute="top" secondItem="108-Xh-aZf" secondAttribute="bottom" constant="4" id="tQN-Rr-MIS"/>
<constraint firstItem="C2U-Ih-4Oh" firstAttribute="top" secondItem="H2p-sc-9uM" secondAttribute="top" constant="14" id="u3s-nr-avO"/>
<constraint firstAttribute="trailing" secondItem="Md3-uq-cSB" secondAttribute="trailing" constant="28" id="vxt-vD-jy8"/>
<constraint firstAttribute="trailing" secondItem="Md3-uq-cSB" secondAttribute="trailing" constant="12" id="vxt-vD-jy8"/>
<constraint firstAttribute="trailing" secondItem="C2U-Ih-4Oh" secondAttribute="trailing" constant="27" id="wNc-xV-uIR"/>
</constraints>
</tableViewCellContentView>
@@ -21,6 +21,7 @@ struct ThreadViewModel {
var rootMessageSenderAvatar: AvatarViewDataProtocol?
var rootMessageSenderDisplayName: String?
var rootMessageText: NSAttributedString?
var rootMessageRedacted: Bool
var lastMessageTime: String?
var summaryViewModel: ThreadSummaryViewModel?
var notificationStatus: ThreadNotificationStatus