More permissive sticker-attachment rendering

This commit is contained in:
Sasha Weiss 2025-02-12 12:10:08 -08:00 committed by GitHub
parent 0d0c82eb96
commit edca6e0db9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 8 additions and 34 deletions

View File

@ -39,12 +39,6 @@ public class CVComponentStateWrapper: NSObject, CVItemViewModel {
return componentState.stickerAttachment
}
public var stickerInfo: StickerInfo? {
AssertIsOnMainThread()
return componentState.stickerInfo
}
public var linkPreview: OWSLinkPreview? {
AssertIsOnMainThread()
@ -317,10 +311,6 @@ public extension CVComponentState {
sticker?.attachmentStream?.attachmentStream
}
var stickerInfo: StickerInfo? {
sticker?.stickerMetadata?.stickerInfo
}
var linkPreviewModel: OWSLinkPreview? {
linkPreview?.linkPreview
}

View File

@ -1305,24 +1305,11 @@ fileprivate extension CVComponentState.Builder {
throw OWSAssertionError("Missing sticker attachment.")
}
if let attachmentStream = attachment.asReferencedStream {
switch attachmentStream.attachmentStream.contentType {
case .image(let pixelSize), .animatedImage(let pixelSize):
guard pixelSize.isNonEmpty else {
fallthrough
}
default:
throw OWSAssertionError("Invalid sticker.")
}
let stickerType = StickerManager.stickerType(forContentType: attachmentStream.attachment.mimeType)
guard
let stickerMetadata = attachmentStream.attachmentStream.asStickerMetadata(
stickerInfo: messageSticker.info,
stickerType: stickerType,
emojiString: messageSticker.emoji
)
else {
throw OWSAssertionError("Invalid sticker.")
}
let stickerMetadata = attachmentStream.attachmentStream.asStickerMetadata(
stickerInfo: messageSticker.info,
stickerType: StickerManager.stickerType(forContentType: attachmentStream.attachment.mimeType),
emojiString: messageSticker.emoji
)
self.sticker = .available(
stickerMetadata: stickerMetadata,
attachmentStream: attachmentStream

View File

@ -20,9 +20,6 @@ public class CVComponentSticker: CVComponentBase, CVComponent {
private var attachmentPointer: ReferencedAttachmentPointer? {
sticker.attachmentPointer
}
private var stickerInfo: StickerInfo? {
stickerMetadata?.stickerInfo
}
init(itemModel: CVItemModel, sticker: CVComponentState.Sticker) {
self.sticker = sticker

View File

@ -82,8 +82,9 @@ public class MessageStickerManagerImpl: MessageStickerManager {
tx: DBWriteTransaction
) throws -> OwnedAttachmentBuilder<Void> {
do {
// If the content type is missing or generic, assume it's a webp.
let proto: SSKProtoAttachmentPointer
if dataProto.contentType == MimeType.applicationOctetStream.rawValue {
if dataProto.contentType == nil || dataProto.contentType == MimeType.applicationOctetStream.rawValue {
let builder = dataProto.asBuilder()
builder.setContentType(MimeType.imageWebp.rawValue)
proto = builder.buildInfallibly()

View File

@ -11,7 +11,7 @@ extension AttachmentStream {
stickerInfo: StickerInfo,
stickerType: StickerType,
emojiString: String?
) -> (any StickerMetadata)? {
) -> any StickerMetadata {
return EncryptedStickerMetadata.from(
attachment: self,
stickerInfo: stickerInfo,

View File

@ -9,7 +9,6 @@ public protocol CVItemViewModel: AnyObject {
var interaction: TSInteraction { get }
var contactShare: ContactShareViewModel? { get }
var linkPreview: OWSLinkPreview? { get }
var stickerInfo: StickerInfo? { get }
var stickerAttachment: AttachmentStream? { get }
var stickerMetadata: (any StickerMetadata)? { get }
var isGiftBadge: Bool { get }