mirror of https://github.com/oxen-io/session-ios
Merge remote-tracking branch 'upstream/dev' into dev
commit
a7895d6581
@ -1,74 +0,0 @@
|
||||
import UIKit
|
||||
|
||||
/// Shown over a media message if it has a message body.
|
||||
final class MediaTextOverlayView : UIView {
|
||||
private let viewItem: ConversationViewItem
|
||||
private let albumViewWidth: CGFloat
|
||||
private let delegate: MessageCellDelegate
|
||||
private let textColor: UIColor
|
||||
var readMoreButton: UIButton?
|
||||
|
||||
// MARK: Settings
|
||||
private static let maxHeight: CGFloat = 88;
|
||||
|
||||
// MARK: Lifecycle
|
||||
init(viewItem: ConversationViewItem, albumViewWidth: CGFloat, textColor: UIColor, delegate: MessageCellDelegate) {
|
||||
self.viewItem = viewItem
|
||||
self.albumViewWidth = albumViewWidth
|
||||
self.delegate = delegate
|
||||
self.textColor = textColor
|
||||
super.init(frame: CGRect.zero)
|
||||
setUpViewHierarchy()
|
||||
}
|
||||
|
||||
override init(frame: CGRect) {
|
||||
preconditionFailure("Use init(text:) instead.")
|
||||
}
|
||||
|
||||
required init?(coder: NSCoder) {
|
||||
preconditionFailure("Use init(text:) instead.")
|
||||
}
|
||||
|
||||
private func setUpViewHierarchy() {
|
||||
guard let message = viewItem.interaction as? TSMessage, let body = message.body, body.count > 0 else { return }
|
||||
// Body label
|
||||
let bodyLabel = UILabel()
|
||||
bodyLabel.numberOfLines = 0
|
||||
bodyLabel.lineBreakMode = .byTruncatingTail
|
||||
bodyLabel.text = given(body) { MentionUtilities.highlightMentions(in: $0, threadID: viewItem.interaction.uniqueThreadId) }
|
||||
bodyLabel.textColor = self.textColor
|
||||
bodyLabel.font = .systemFont(ofSize: Values.mediumFontSize)
|
||||
// Content stack view
|
||||
let contentStackView = UIStackView(arrangedSubviews: [ bodyLabel ])
|
||||
contentStackView.axis = .horizontal
|
||||
contentStackView.spacing = Values.smallSpacing
|
||||
addSubview(contentStackView)
|
||||
let inset: CGFloat = 12
|
||||
contentStackView.pin(.left, to: .left, of: self, withInset: inset)
|
||||
contentStackView.pin(.top, to: .top, of: self)
|
||||
contentStackView.pin(.right, to: .right, of: self, withInset: -inset)
|
||||
// Max height
|
||||
bodyLabel.heightAnchor.constraint(lessThanOrEqualToConstant: MediaTextOverlayView.maxHeight).isActive = true
|
||||
// Overflow button
|
||||
let bodyLabelTargetSize = bodyLabel.sizeThatFits(CGSize(width: albumViewWidth - 2 * inset, height: .greatestFiniteMagnitude))
|
||||
if bodyLabelTargetSize.height > MediaTextOverlayView.maxHeight {
|
||||
let readMoreButton = UIButton()
|
||||
self.readMoreButton = readMoreButton
|
||||
readMoreButton.setTitle("Read More", for: UIControl.State.normal)
|
||||
readMoreButton.titleLabel!.font = .boldSystemFont(ofSize: Values.smallFontSize)
|
||||
readMoreButton.setTitleColor(self.textColor, for: UIControl.State.normal)
|
||||
readMoreButton.addTarget(self, action: #selector(readMore), for: UIControl.Event.touchUpInside)
|
||||
addSubview(readMoreButton)
|
||||
readMoreButton.pin(.left, to: .left, of: self, withInset: inset)
|
||||
readMoreButton.pin(.top, to: .bottom, of: contentStackView, withInset: Values.smallSpacing)
|
||||
readMoreButton.pin(.bottom, to: .bottom, of: self, withInset: -Values.smallSpacing)
|
||||
} else {
|
||||
contentStackView.pin(.bottom, to: .bottom, of: self, withInset: -inset)
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: Interaction
|
||||
@objc private func readMore() {
|
||||
delegate.showFullText(viewItem)
|
||||
}
|
||||
}
|
@ -1,7 +1,25 @@
|
||||
import Foundation
|
||||
|
||||
public enum General {
|
||||
public enum Cache {
|
||||
public static var cachedEncodedPublicKey: String? = nil
|
||||
}
|
||||
}
|
||||
|
||||
@objc(SNGeneralUtilities)
|
||||
public class GeneralUtilities: NSObject {
|
||||
@objc public static func getUserPublicKey() -> String {
|
||||
return getUserHexEncodedPublicKey()
|
||||
}
|
||||
}
|
||||
|
||||
public func getUserHexEncodedPublicKey() -> String {
|
||||
if let cachedKey: String = General.Cache.cachedEncodedPublicKey { return cachedKey }
|
||||
|
||||
if let keyPair = OWSIdentityManager.shared().identityKeyPair() { // Can be nil under some circumstances
|
||||
General.Cache.cachedEncodedPublicKey = keyPair.hexEncodedPublicKey
|
||||
return keyPair.hexEncodedPublicKey
|
||||
}
|
||||
|
||||
return ""
|
||||
}
|
||||
|
@ -1,11 +0,0 @@
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface SNGeneralUtilities : NSObject
|
||||
|
||||
+ (NSString *)getUserPublicKey;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
@ -1,16 +0,0 @@
|
||||
#import <SessionUtilitiesKit/SessionUtilitiesKit.h>
|
||||
#import "GeneralUtilities.h"
|
||||
#import "OWSIdentityManager.h"
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@implementation SNGeneralUtilities
|
||||
|
||||
+ (NSString *)getUserPublicKey
|
||||
{
|
||||
return OWSIdentityManager.sharedManager.identityKeyPair.hexEncodedPublicKey;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
Loading…
Reference in New Issue