mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-04 05:26:48 +00:00
Poll improvements
This commit is contained in:
parent
d1fb481e82
commit
9ac0e6a2bf
@ -727,8 +727,8 @@ public func createPollController(context: AccountContext, peer: Peer, isQuiz: Bo
|
|||||||
} else {
|
} else {
|
||||||
kind = .poll(multipleAnswers: state.isMultipleChoice)
|
kind = .poll(multipleAnswers: state.isMultipleChoice)
|
||||||
}
|
}
|
||||||
completion(.message(text: "", attributes: [], mediaReference: .standalone(media: TelegramMediaPoll(pollId: MediaId(namespace: Namespaces.Media.LocalPoll, id: arc4random64()), publicity: publicity, kind: kind, text: processPollText(state.text), options: options, correctAnswers: correctAnswers, results: TelegramMediaPollResults(voters: nil, totalVoters: nil, recentVoters: []), isClosed: false)), replyToMessageId: nil, localGroupingKey: nil))
|
|
||||||
dismissImpl?()
|
dismissImpl?()
|
||||||
|
completion(.message(text: "", attributes: [], mediaReference: .standalone(media: TelegramMediaPoll(pollId: MediaId(namespace: Namespaces.Media.LocalPoll, id: arc4random64()), publicity: publicity, kind: kind, text: processPollText(state.text), options: options, correctAnswers: correctAnswers, results: TelegramMediaPollResults(voters: nil, totalVoters: nil, recentVoters: []), isClosed: false)), replyToMessageId: nil, localGroupingKey: nil))
|
||||||
})
|
})
|
||||||
|
|
||||||
let leftNavigationButton = ItemListNavigationButton(content: .text(presentationData.strings.Common_Cancel), style: .regular, enabled: true, action: {
|
let leftNavigationButton = ItemListNavigationButton(content: .text(presentationData.strings.Common_Cancel), style: .regular, enabled: true, action: {
|
||||||
@ -777,7 +777,6 @@ public func createPollController(context: AccountContext, peer: Peer, isQuiz: Bo
|
|||||||
controller?.present(c, in: .window(.root), with: a)
|
controller?.present(c, in: .window(.root), with: a)
|
||||||
}
|
}
|
||||||
dismissImpl = { [weak controller] in
|
dismissImpl = { [weak controller] in
|
||||||
//controller?.view.endEditing(true)
|
|
||||||
controller?.dismiss()
|
controller?.dismiss()
|
||||||
}
|
}
|
||||||
ensureTextVisibleImpl = { [weak controller] in
|
ensureTextVisibleImpl = { [weak controller] in
|
||||||
|
|||||||
@ -1247,6 +1247,7 @@ public class ItemListPeerItemNode: ItemListRevealOptionsItemNode, ItemListItemNo
|
|||||||
public final class ItemListPeerItemHeader: ListViewItemHeader {
|
public final class ItemListPeerItemHeader: ListViewItemHeader {
|
||||||
public let id: Int64
|
public let id: Int64
|
||||||
public let text: String
|
public let text: String
|
||||||
|
public let additionalText: String
|
||||||
public let stickDirection: ListViewItemHeaderStickDirection = .topEdge
|
public let stickDirection: ListViewItemHeaderStickDirection = .topEdge
|
||||||
public let theme: PresentationTheme
|
public let theme: PresentationTheme
|
||||||
public let strings: PresentationStrings
|
public let strings: PresentationStrings
|
||||||
@ -1255,8 +1256,9 @@ public final class ItemListPeerItemHeader: ListViewItemHeader {
|
|||||||
|
|
||||||
public let height: CGFloat = 28.0
|
public let height: CGFloat = 28.0
|
||||||
|
|
||||||
public init(theme: PresentationTheme, strings: PresentationStrings, text: String, actionTitle: String? = nil, id: Int64, action: (() -> Void)? = nil) {
|
public init(theme: PresentationTheme, strings: PresentationStrings, text: String, additionalText: String, actionTitle: String? = nil, id: Int64, action: (() -> Void)? = nil) {
|
||||||
self.text = text
|
self.text = text
|
||||||
|
self.additionalText = additionalText
|
||||||
self.id = id
|
self.id = id
|
||||||
self.theme = theme
|
self.theme = theme
|
||||||
self.strings = strings
|
self.strings = strings
|
||||||
@ -1265,11 +1267,11 @@ public final class ItemListPeerItemHeader: ListViewItemHeader {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public func node() -> ListViewItemHeaderNode {
|
public func node() -> ListViewItemHeaderNode {
|
||||||
return ItemListPeerItemHeaderNode(theme: self.theme, strings: self.strings, text: self.text, actionTitle: self.actionTitle, action: self.action)
|
return ItemListPeerItemHeaderNode(theme: self.theme, strings: self.strings, text: self.text, additionalText: self.additionalText, actionTitle: self.actionTitle, action: self.action)
|
||||||
}
|
}
|
||||||
|
|
||||||
public func updateNode(_ node: ListViewItemHeaderNode, previous: ListViewItemHeader?, next: ListViewItemHeader?) {
|
public func updateNode(_ node: ListViewItemHeaderNode, previous: ListViewItemHeader?, next: ListViewItemHeader?) {
|
||||||
(node as? ItemListPeerItemHeaderNode)?.update(text: self.text, actionTitle: self.actionTitle, action: self.action)
|
(node as? ItemListPeerItemHeaderNode)?.update(text: self.text, additionalText: self.additionalText, actionTitle: self.actionTitle, action: self.action)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1285,12 +1287,13 @@ public final class ItemListPeerItemHeaderNode: ListViewItemHeaderNode {
|
|||||||
private let snappedBackgroundNode: ASDisplayNode
|
private let snappedBackgroundNode: ASDisplayNode
|
||||||
private let separatorNode: ASDisplayNode
|
private let separatorNode: ASDisplayNode
|
||||||
private let textNode: ImmediateTextNode
|
private let textNode: ImmediateTextNode
|
||||||
|
private let additionalTextNode: ImmediateTextNode
|
||||||
private let actionTextNode: ImmediateTextNode
|
private let actionTextNode: ImmediateTextNode
|
||||||
private let actionButton: HighlightableButtonNode
|
private let actionButton: HighlightableButtonNode
|
||||||
|
|
||||||
private var stickDistanceFactor: CGFloat?
|
private var stickDistanceFactor: CGFloat?
|
||||||
|
|
||||||
public init(theme: PresentationTheme, strings: PresentationStrings, text: String, actionTitle: String?, action: (() -> Void)?) {
|
public init(theme: PresentationTheme, strings: PresentationStrings, text: String, additionalText: String, actionTitle: String?, action: (() -> Void)?) {
|
||||||
self.theme = theme
|
self.theme = theme
|
||||||
self.strings = strings
|
self.strings = strings
|
||||||
self.actionTitle = actionTitle
|
self.actionTitle = actionTitle
|
||||||
@ -1312,9 +1315,13 @@ public final class ItemListPeerItemHeaderNode: ListViewItemHeaderNode {
|
|||||||
self.textNode = ImmediateTextNode()
|
self.textNode = ImmediateTextNode()
|
||||||
self.textNode.displaysAsynchronously = false
|
self.textNode.displaysAsynchronously = false
|
||||||
self.textNode.maximumNumberOfLines = 1
|
self.textNode.maximumNumberOfLines = 1
|
||||||
self.textNode.truncationType = .middle
|
|
||||||
self.textNode.attributedText = NSAttributedString(string: text, font: titleFont, textColor: theme.list.sectionHeaderTextColor)
|
self.textNode.attributedText = NSAttributedString(string: text, font: titleFont, textColor: theme.list.sectionHeaderTextColor)
|
||||||
|
|
||||||
|
self.additionalTextNode = ImmediateTextNode()
|
||||||
|
self.additionalTextNode.displaysAsynchronously = false
|
||||||
|
self.additionalTextNode.maximumNumberOfLines = 1
|
||||||
|
self.additionalTextNode.attributedText = NSAttributedString(string: additionalText, font: titleFont, textColor: theme.list.sectionHeaderTextColor)
|
||||||
|
|
||||||
self.actionTextNode = ImmediateTextNode()
|
self.actionTextNode = ImmediateTextNode()
|
||||||
self.actionTextNode.displaysAsynchronously = false
|
self.actionTextNode.displaysAsynchronously = false
|
||||||
self.actionTextNode.maximumNumberOfLines = 1
|
self.actionTextNode.maximumNumberOfLines = 1
|
||||||
@ -1329,6 +1336,7 @@ public final class ItemListPeerItemHeaderNode: ListViewItemHeaderNode {
|
|||||||
self.addSubnode(self.snappedBackgroundNode)
|
self.addSubnode(self.snappedBackgroundNode)
|
||||||
self.addSubnode(self.separatorNode)
|
self.addSubnode(self.separatorNode)
|
||||||
self.addSubnode(self.textNode)
|
self.addSubnode(self.textNode)
|
||||||
|
self.addSubnode(self.additionalTextNode)
|
||||||
self.addSubnode(self.actionTextNode)
|
self.addSubnode(self.actionTextNode)
|
||||||
self.addSubnode(self.actionButton)
|
self.addSubnode(self.actionButton)
|
||||||
|
|
||||||
@ -1356,14 +1364,16 @@ public final class ItemListPeerItemHeaderNode: ListViewItemHeaderNode {
|
|||||||
let titleFont = Font.regular(13.0)
|
let titleFont = Font.regular(13.0)
|
||||||
|
|
||||||
self.textNode.attributedText = NSAttributedString(string: self.textNode.attributedText?.string ?? "", font: titleFont, textColor: theme.list.sectionHeaderTextColor)
|
self.textNode.attributedText = NSAttributedString(string: self.textNode.attributedText?.string ?? "", font: titleFont, textColor: theme.list.sectionHeaderTextColor)
|
||||||
|
self.additionalTextNode.attributedText = NSAttributedString(string: self.additionalTextNode.attributedText?.string ?? "", font: titleFont, textColor: theme.list.sectionHeaderTextColor)
|
||||||
self.actionTextNode.attributedText = NSAttributedString(string: self.actionTextNode.attributedText?.string ?? "", font: titleFont, textColor: theme.list.sectionHeaderTextColor)
|
self.actionTextNode.attributedText = NSAttributedString(string: self.actionTextNode.attributedText?.string ?? "", font: titleFont, textColor: theme.list.sectionHeaderTextColor)
|
||||||
}
|
}
|
||||||
|
|
||||||
public func update(text: String, actionTitle: String?, action: (() -> Void)?) {
|
public func update(text: String, additionalText: String, actionTitle: String?, action: (() -> Void)?) {
|
||||||
self.actionTitle = actionTitle
|
self.actionTitle = actionTitle
|
||||||
self.action = action
|
self.action = action
|
||||||
let titleFont = Font.regular(13.0)
|
let titleFont = Font.regular(13.0)
|
||||||
self.textNode.attributedText = NSAttributedString(string: text, font: titleFont, textColor: theme.list.sectionHeaderTextColor)
|
self.textNode.attributedText = NSAttributedString(string: text, font: titleFont, textColor: theme.list.sectionHeaderTextColor)
|
||||||
|
self.additionalTextNode.attributedText = NSAttributedString(string: additionalText, font: titleFont, textColor: theme.list.sectionHeaderTextColor)
|
||||||
self.actionTextNode.attributedText = NSAttributedString(string: actionTitle ?? "", font: titleFont, textColor: action == nil ? theme.list.sectionHeaderTextColor : theme.list.itemAccentColor)
|
self.actionTextNode.attributedText = NSAttributedString(string: actionTitle ?? "", font: titleFont, textColor: action == nil ? theme.list.sectionHeaderTextColor : theme.list.itemAccentColor)
|
||||||
self.actionButton.isUserInteractionEnabled = self.action != nil
|
self.actionButton.isUserInteractionEnabled = self.action != nil
|
||||||
if let (size, leftInset, rightInset) = self.validLayout {
|
if let (size, leftInset, rightInset) = self.validLayout {
|
||||||
@ -1380,9 +1390,12 @@ public final class ItemListPeerItemHeaderNode: ListViewItemHeaderNode {
|
|||||||
let sideInset: CGFloat = 15.0 + leftInset
|
let sideInset: CGFloat = 15.0 + leftInset
|
||||||
|
|
||||||
let actionTextSize = self.actionTextNode.updateLayout(CGSize(width: size.width - sideInset * 2.0, height: size.height))
|
let actionTextSize = self.actionTextNode.updateLayout(CGSize(width: size.width - sideInset * 2.0, height: size.height))
|
||||||
let textSize = self.textNode.updateLayout(CGSize(width: size.width - sideInset * 2.0 - actionTextSize.width - 8.0, height: size.height))
|
let additionalTextSize = self.additionalTextNode.updateLayout(CGSize(width: size.width - sideInset * 2.0 - actionTextSize.width - 8.0, height: size.height))
|
||||||
|
let textSize = self.textNode.updateLayout(CGSize(width: max(1.0, size.width - sideInset * 2.0 - actionTextSize.width - 8.0 - additionalTextSize.width), height: size.height))
|
||||||
|
|
||||||
self.textNode.frame = CGRect(origin: CGPoint(x: sideInset, y: 7.0), size: textSize)
|
let textFrame = CGRect(origin: CGPoint(x: sideInset, y: 7.0), size: textSize)
|
||||||
|
self.textNode.frame = textFrame
|
||||||
|
self.additionalTextNode.frame = CGRect(origin: CGPoint(x: textFrame.maxX, y: 7.0), size: additionalTextSize)
|
||||||
self.actionTextNode.frame = CGRect(origin: CGPoint(x: size.width - sideInset - actionTextSize.width, y: 7.0), size: actionTextSize)
|
self.actionTextNode.frame = CGRect(origin: CGPoint(x: size.width - sideInset - actionTextSize.width, y: 7.0), size: actionTextSize)
|
||||||
self.actionButton.frame = CGRect(origin: CGPoint(x: size.width - sideInset - actionTextSize.width, y: 0.0), size: CGSize(width: actionTextSize.width, height: size.height))
|
self.actionButton.frame = CGRect(origin: CGPoint(x: size.width - sideInset - actionTextSize.width, y: 0.0), size: CGSize(width: actionTextSize.width, height: size.height))
|
||||||
}
|
}
|
||||||
|
|||||||
@ -217,13 +217,17 @@ public final class TelegramMediaPoll: Media, Equatable {
|
|||||||
if min {
|
if min {
|
||||||
if let currentVoters = self.results.voters, let updatedVoters = results.voters {
|
if let currentVoters = self.results.voters, let updatedVoters = results.voters {
|
||||||
var selectedOpaqueIdentifiers = Set<Data>()
|
var selectedOpaqueIdentifiers = Set<Data>()
|
||||||
|
var correctOpaqueIdentifiers = Set<Data>()
|
||||||
for voters in currentVoters {
|
for voters in currentVoters {
|
||||||
if voters.selected {
|
if voters.selected {
|
||||||
selectedOpaqueIdentifiers.insert(voters.opaqueIdentifier)
|
selectedOpaqueIdentifiers.insert(voters.opaqueIdentifier)
|
||||||
}
|
}
|
||||||
|
if voters.isCorrect {
|
||||||
|
correctOpaqueIdentifiers.insert(voters.opaqueIdentifier)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
updatedResults = TelegramMediaPollResults(voters: updatedVoters.map({ voters in
|
updatedResults = TelegramMediaPollResults(voters: updatedVoters.map({ voters in
|
||||||
return TelegramMediaPollOptionVoters(selected: selectedOpaqueIdentifiers.contains(voters.opaqueIdentifier), opaqueIdentifier: voters.opaqueIdentifier, count: voters.count, isCorrect: voters.isCorrect)
|
return TelegramMediaPollOptionVoters(selected: selectedOpaqueIdentifiers.contains(voters.opaqueIdentifier), opaqueIdentifier: voters.opaqueIdentifier, count: voters.count, isCorrect: correctOpaqueIdentifiers.contains(voters.opaqueIdentifier))
|
||||||
}), totalVoters: results.totalVoters, recentVoters: results.recentVoters)
|
}), totalVoters: results.totalVoters, recentVoters: results.recentVoters)
|
||||||
} else {
|
} else {
|
||||||
updatedResults = TelegramMediaPollResults(voters: self.results.voters, totalVoters: results.totalVoters, recentVoters: results.recentVoters)
|
updatedResults = TelegramMediaPollResults(voters: self.results.voters, totalVoters: results.totalVoters, recentVoters: results.recentVoters)
|
||||||
|
|||||||
@ -21,12 +21,15 @@ public func requestMessageSelectPollOption(account: Account, messageId: MessageI
|
|||||||
return .generic
|
return .generic
|
||||||
}
|
}
|
||||||
|> mapToSignal { result -> Signal<TelegramMediaPoll?, RequestMessageSelectPollOptionError> in
|
|> mapToSignal { result -> Signal<TelegramMediaPoll?, RequestMessageSelectPollOptionError> in
|
||||||
|
return account.postbox.transaction { transaction -> TelegramMediaPoll? in
|
||||||
var resultPoll: TelegramMediaPoll?
|
var resultPoll: TelegramMediaPoll?
|
||||||
switch result {
|
switch result {
|
||||||
case let .updates(updates, _, _, _, _):
|
case let .updates(updates, _, _, _, _):
|
||||||
for update in updates {
|
for update in updates {
|
||||||
switch update {
|
switch update {
|
||||||
case let .updateMessagePoll(_, pollId, poll, results):
|
case let .updateMessagePoll(_, id, poll, results):
|
||||||
|
let pollId = MediaId(namespace: Namespaces.Media.CloudPoll, id: id)
|
||||||
|
resultPoll = transaction.getMedia(pollId) as? TelegramMediaPoll
|
||||||
if let poll = poll {
|
if let poll = poll {
|
||||||
switch poll {
|
switch poll {
|
||||||
case let .poll(id, flags, question, answers):
|
case let .poll(id, flags, question, answers):
|
||||||
@ -42,11 +45,22 @@ public func requestMessageSelectPollOption(account: Account, messageId: MessageI
|
|||||||
} else {
|
} else {
|
||||||
kind = .poll(multipleAnswers: (flags & (1 << 2)) != 0)
|
kind = .poll(multipleAnswers: (flags & (1 << 2)) != 0)
|
||||||
}
|
}
|
||||||
resultPoll = TelegramMediaPoll(pollId: MediaId(namespace: Namespaces.Media.CloudPoll, id: id), publicity: publicity, kind: kind, text: question, options: answers.map(TelegramMediaPollOption.init(apiOption:)), correctAnswers: nil, results: TelegramMediaPollResults(apiResults: results), isClosed: (flags & (1 << 0)) != 0)
|
resultPoll = TelegramMediaPoll(pollId: pollId, publicity: publicity, kind: kind, text: question, options: answers.map(TelegramMediaPollOption.init(apiOption:)), correctAnswers: nil, results: TelegramMediaPollResults(apiResults: results), isClosed: (flags & (1 << 0)) != 0)
|
||||||
default:
|
default:
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let resultsMin: Bool
|
||||||
|
switch results {
|
||||||
|
case let .pollResults(pollResults):
|
||||||
|
resultsMin = (pollResults.flags & (1 << 0)) != 0
|
||||||
|
}
|
||||||
|
resultPoll = resultPoll?.withUpdatedResults(TelegramMediaPollResults(apiResults: results), min: resultsMin)
|
||||||
|
|
||||||
|
if let resultPoll = resultPoll {
|
||||||
|
updateMessageMedia(transaction: transaction, id: pollId, media: resultPoll)
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
@ -56,7 +70,9 @@ public func requestMessageSelectPollOption(account: Account, messageId: MessageI
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
account.stateManager.addUpdates(result)
|
account.stateManager.addUpdates(result)
|
||||||
return .single(resultPoll)
|
return resultPoll
|
||||||
|
}
|
||||||
|
|> castError(RequestMessageSelectPollOptionError.self)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return .single(nil)
|
return .single(nil)
|
||||||
|
|||||||
@ -1636,7 +1636,10 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
if controllerInteraction.pollActionState.pollMessageIdsInProgress.removeValue(forKey: id) != nil {
|
if controllerInteraction.pollActionState.pollMessageIdsInProgress.removeValue(forKey: id) != nil {
|
||||||
|
Queue.mainQueue().after(1.0, {
|
||||||
|
|
||||||
strongSelf.chatDisplayNode.historyNode.requestMessageUpdate(id)
|
strongSelf.chatDisplayNode.historyNode.requestMessageUpdate(id)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}), forKey: id)
|
}), forKey: id)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2909,6 +2909,14 @@ class ChatMessageBubbleItemNode: ChatMessageItemView, ChatMessagePrevewItemNode
|
|||||||
}
|
}
|
||||||
|
|
||||||
func animateQuizInvalidOptionSelected() {
|
func animateQuizInvalidOptionSelected() {
|
||||||
|
if let supernode = self.supernode, let subnodes = supernode.subnodes {
|
||||||
|
for i in 0 ..< subnodes.count {
|
||||||
|
if subnodes[i] === self {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let duration: Double = 0.5
|
let duration: Double = 0.5
|
||||||
let minScale: CGFloat = -0.03
|
let minScale: CGFloat = -0.03
|
||||||
let scaleAnimation0 = self.layer.makeAnimation(from: 0.0 as NSNumber, to: minScale as NSNumber, keyPath: "transform.scale", timingFunction: CAMediaTimingFunctionName.linear.rawValue, duration: duration / 2.0, removeOnCompletion: false, additive: true, completion: { [weak self] _ in
|
let scaleAnimation0 = self.layer.makeAnimation(from: 0.0 as NSNumber, to: minScale as NSNumber, keyPath: "transform.scale", timingFunction: CAMediaTimingFunctionName.linear.rawValue, duration: duration / 2.0, removeOnCompletion: false, additive: true, completion: { [weak self] _ in
|
||||||
|
|||||||
@ -1361,7 +1361,7 @@ class ChatMessagePollBubbleContentNode: ChatMessageBubbleContentNode {
|
|||||||
if optionNode.frame.contains(point), case .tap = gesture {
|
if optionNode.frame.contains(point), case .tap = gesture {
|
||||||
if optionNode.isUserInteractionEnabled {
|
if optionNode.isUserInteractionEnabled {
|
||||||
return .ignore
|
return .ignore
|
||||||
} else if let result = optionNode.currentResult, let item = self.item, let poll = self.poll, let option = optionNode.option {
|
} else if let result = optionNode.currentResult, let item = self.item, !Namespaces.Message.allScheduled.contains(item.message.id.namespace), let poll = self.poll, let option = optionNode.option {
|
||||||
switch poll.publicity {
|
switch poll.publicity {
|
||||||
case .anonymous:
|
case .anonymous:
|
||||||
let string: String
|
let string: String
|
||||||
|
|||||||
@ -13,6 +13,23 @@ import StickerResources
|
|||||||
import PhotoResources
|
import PhotoResources
|
||||||
import TelegramStringFormatting
|
import TelegramStringFormatting
|
||||||
|
|
||||||
|
private func foldLineBreaks(_ text: String) -> String {
|
||||||
|
var lines = text.split { $0.isNewline }
|
||||||
|
var startedBothLines = false
|
||||||
|
var result = ""
|
||||||
|
for line in lines {
|
||||||
|
if line.isEmpty {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if result.isEmpty {
|
||||||
|
result += line
|
||||||
|
} else {
|
||||||
|
result += " " + line
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
final class ChatPinnedMessageTitlePanelNode: ChatTitleAccessoryPanelNode {
|
final class ChatPinnedMessageTitlePanelNode: ChatTitleAccessoryPanelNode {
|
||||||
private let context: AccountContext
|
private let context: AccountContext
|
||||||
private let tapButton: HighlightTrackingButtonNode
|
private let tapButton: HighlightTrackingButtonNode
|
||||||
@ -238,7 +255,7 @@ final class ChatPinnedMessageTitlePanelNode: ChatTitleAccessoryPanelNode {
|
|||||||
|
|
||||||
let (titleLayout, titleApply) = makeTitleLayout(TextNodeLayoutArguments(attributedString: NSAttributedString(string: titleString, font: Font.medium(15.0), textColor: theme.chat.inputPanel.panelControlAccentColor), backgroundColor: nil, maximumNumberOfLines: 1, truncationType: .end, constrainedSize: CGSize(width: width - textLineInset - contentLeftInset - rightInset - textRightInset, height: CGFloat.greatestFiniteMagnitude), alignment: .natural, cutout: nil, insets: UIEdgeInsets(top: 2.0, left: 0.0, bottom: 2.0, right: 0.0)))
|
let (titleLayout, titleApply) = makeTitleLayout(TextNodeLayoutArguments(attributedString: NSAttributedString(string: titleString, font: Font.medium(15.0), textColor: theme.chat.inputPanel.panelControlAccentColor), backgroundColor: nil, maximumNumberOfLines: 1, truncationType: .end, constrainedSize: CGSize(width: width - textLineInset - contentLeftInset - rightInset - textRightInset, height: CGFloat.greatestFiniteMagnitude), alignment: .natural, cutout: nil, insets: UIEdgeInsets(top: 2.0, left: 0.0, bottom: 2.0, right: 0.0)))
|
||||||
|
|
||||||
let (textLayout, textApply) = makeTextLayout(TextNodeLayoutArguments(attributedString: NSAttributedString(string: descriptionStringForMessage(contentSettings: context.currentContentSettings.with { $0 }, message: message, strings: strings, nameDisplayOrder: nameDisplayOrder, accountPeerId: accountPeerId).0, font: Font.regular(15.0), textColor: message.media.isEmpty || message.media.first is TelegramMediaWebpage ? theme.chat.inputPanel.primaryTextColor : theme.chat.inputPanel.secondaryTextColor), backgroundColor: nil, maximumNumberOfLines: 1, truncationType: .end, constrainedSize: CGSize(width: width - textLineInset - contentLeftInset - rightInset - textRightInset, height: CGFloat.greatestFiniteMagnitude), alignment: .natural, cutout: nil, insets: UIEdgeInsets(top: 2.0, left: 0.0, bottom: 2.0, right: 0.0)))
|
let (textLayout, textApply) = makeTextLayout(TextNodeLayoutArguments(attributedString: NSAttributedString(string: foldLineBreaks(descriptionStringForMessage(contentSettings: context.currentContentSettings.with { $0 }, message: message, strings: strings, nameDisplayOrder: nameDisplayOrder, accountPeerId: accountPeerId).0), font: Font.regular(15.0), textColor: message.media.isEmpty || message.media.first is TelegramMediaWebpage ? theme.chat.inputPanel.primaryTextColor : theme.chat.inputPanel.secondaryTextColor), backgroundColor: nil, maximumNumberOfLines: 1, truncationType: .end, constrainedSize: CGSize(width: width - textLineInset - contentLeftInset - rightInset - textRightInset, height: CGFloat.greatestFiniteMagnitude), alignment: .natural, cutout: nil, insets: UIEdgeInsets(top: 2.0, left: 0.0, bottom: 2.0, right: 0.0)))
|
||||||
|
|
||||||
Queue.mainQueue().async {
|
Queue.mainQueue().async {
|
||||||
if let strongSelf = self {
|
if let strongSelf = self {
|
||||||
|
|||||||
@ -61,7 +61,7 @@ private enum PollResultsItemTag: ItemListItemTag, Equatable {
|
|||||||
|
|
||||||
private enum PollResultsEntry: ItemListNodeEntry {
|
private enum PollResultsEntry: ItemListNodeEntry {
|
||||||
case text(String)
|
case text(String)
|
||||||
case optionPeer(optionId: Int, index: Int, peer: RenderedPeer, optionText: String, optionCount: Int32, optionExpanded: Bool, opaqueIdentifier: Data, shimmeringAlternation: Int?, isFirstInOption: Bool)
|
case optionPeer(optionId: Int, index: Int, peer: RenderedPeer, optionText: String, optionAdditionalText: String, optionCount: Int32, optionExpanded: Bool, opaqueIdentifier: Data, shimmeringAlternation: Int?, isFirstInOption: Bool)
|
||||||
case optionExpand(optionId: Int, opaqueIdentifier: Data, text: String, enabled: Bool)
|
case optionExpand(optionId: Int, opaqueIdentifier: Data, text: String, enabled: Bool)
|
||||||
|
|
||||||
var section: ItemListSectionId {
|
var section: ItemListSectionId {
|
||||||
@ -137,8 +137,8 @@ private enum PollResultsEntry: ItemListNodeEntry {
|
|||||||
switch self {
|
switch self {
|
||||||
case let .text(text):
|
case let .text(text):
|
||||||
return ItemListTextItem(presentationData: presentationData, text: .large(text), sectionId: self.section)
|
return ItemListTextItem(presentationData: presentationData, text: .large(text), sectionId: self.section)
|
||||||
case let .optionPeer(optionId, _, peer, optionText, optionCount, optionExpanded, opaqueIdentifier, shimmeringAlternation, isFirstInOption):
|
case let .optionPeer(optionId, _, peer, optionText, optionAdditionalText, optionCount, optionExpanded, opaqueIdentifier, shimmeringAlternation, isFirstInOption):
|
||||||
let header = ItemListPeerItemHeader(theme: presentationData.theme, strings: presentationData.strings, text: optionText, actionTitle: optionExpanded ? presentationData.strings.PollResults_Collapse : presentationData.strings.MessagePoll_VotedCount(optionCount), id: Int64(optionId), action: optionExpanded ? {
|
let header = ItemListPeerItemHeader(theme: presentationData.theme, strings: presentationData.strings, text: optionText, additionalText: optionAdditionalText, actionTitle: optionExpanded ? presentationData.strings.PollResults_Collapse : presentationData.strings.MessagePoll_VotedCount(optionCount), id: Int64(optionId), action: optionExpanded ? {
|
||||||
arguments.collapseOption(opaqueIdentifier)
|
arguments.collapseOption(opaqueIdentifier)
|
||||||
} : nil)
|
} : nil)
|
||||||
return ItemListPeerItem(presentationData: presentationData, dateTimeFormat: PresentationDateTimeFormat(timeFormat: .regular, dateFormat: .dayFirst, dateSeparator: ".", decimalSeparator: ".", groupingSeparator: ""), nameDisplayOrder: .firstLast, context: arguments.context, peer: peer.peers[peer.peerId]!, presence: nil, text: .none, label: .none, editing: ItemListPeerItemEditing(editable: false, editing: false, revealed: false), switchValue: nil, enabled: true, selectable: shimmeringAlternation == nil, sectionId: self.section, action: {
|
return ItemListPeerItem(presentationData: presentationData, dateTimeFormat: PresentationDateTimeFormat(timeFormat: .regular, dateFormat: .dayFirst, dateSeparator: ".", decimalSeparator: ".", groupingSeparator: ""), nameDisplayOrder: .firstLast, context: arguments.context, peer: peer.peers[peer.peerId]!, presence: nil, text: .none, label: .none, editing: ItemListPeerItemEditing(editable: false, editing: false, revealed: false), switchValue: nil, enabled: true, selectable: shimmeringAlternation == nil, sectionId: self.section, action: {
|
||||||
@ -193,7 +193,8 @@ private func pollResultsControllerEntries(presentationData: PresentationData, po
|
|||||||
for i in 0 ..< poll.options.count {
|
for i in 0 ..< poll.options.count {
|
||||||
let percentage = optionPercentage.count > i ? optionPercentage[i] : 0
|
let percentage = optionPercentage.count > i ? optionPercentage[i] : 0
|
||||||
let option = poll.options[i]
|
let option = poll.options[i]
|
||||||
let optionTextHeader = option.text.uppercased() + " — \(percentage)%"
|
let optionTextHeader = option.text.uppercased()
|
||||||
|
let optionAdditionalTextHeader = " — \(percentage)%"
|
||||||
if isEmpty {
|
if isEmpty {
|
||||||
if let voterCount = optionVoterCount[i], voterCount != 0 {
|
if let voterCount = optionVoterCount[i], voterCount != 0 {
|
||||||
let displayCount: Int
|
let displayCount: Int
|
||||||
@ -205,7 +206,7 @@ private func pollResultsControllerEntries(presentationData: PresentationData, po
|
|||||||
for peerIndex in 0 ..< displayCount {
|
for peerIndex in 0 ..< displayCount {
|
||||||
let fakeUser = TelegramUser(id: PeerId(namespace: -1, id: 0), accessHash: nil, firstName: "", lastName: "", username: nil, phone: nil, photo: [], botInfo: nil, restrictionInfo: nil, flags: [])
|
let fakeUser = TelegramUser(id: PeerId(namespace: -1, id: 0), accessHash: nil, firstName: "", lastName: "", username: nil, phone: nil, photo: [], botInfo: nil, restrictionInfo: nil, flags: [])
|
||||||
let peer = RenderedPeer(peer: fakeUser)
|
let peer = RenderedPeer(peer: fakeUser)
|
||||||
entries.append(.optionPeer(optionId: i, index: peerIndex, peer: peer, optionText: optionTextHeader, optionCount: voterCount, optionExpanded: false, opaqueIdentifier: option.opaqueIdentifier, shimmeringAlternation: peerIndex % 2, isFirstInOption: peerIndex == 0))
|
entries.append(.optionPeer(optionId: i, index: peerIndex, peer: peer, optionText: optionTextHeader, optionAdditionalText: optionAdditionalTextHeader, optionCount: voterCount, optionExpanded: false, opaqueIdentifier: option.opaqueIdentifier, shimmeringAlternation: peerIndex % 2, isFirstInOption: peerIndex == 0))
|
||||||
}
|
}
|
||||||
if displayCount < Int(voterCount) {
|
if displayCount < Int(voterCount) {
|
||||||
let remainingCount = Int(voterCount) - displayCount
|
let remainingCount = Int(voterCount) - displayCount
|
||||||
@ -248,7 +249,7 @@ private func pollResultsControllerEntries(presentationData: PresentationData, po
|
|||||||
if peerIndex >= displayCount {
|
if peerIndex >= displayCount {
|
||||||
break inner
|
break inner
|
||||||
}
|
}
|
||||||
entries.append(.optionPeer(optionId: i, index: peerIndex, peer: peer, optionText: optionTextHeader, optionCount: Int32(count), optionExpanded: optionExpandedAtCount != nil, opaqueIdentifier: option.opaqueIdentifier, shimmeringAlternation: nil, isFirstInOption: peerIndex == 0))
|
entries.append(.optionPeer(optionId: i, index: peerIndex, peer: peer, optionText: optionTextHeader, optionAdditionalText: optionAdditionalTextHeader, optionCount: Int32(count), optionExpanded: optionExpandedAtCount != nil, opaqueIdentifier: option.opaqueIdentifier, shimmeringAlternation: nil, isFirstInOption: peerIndex == 0))
|
||||||
peerIndex += 1
|
peerIndex += 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user