mirror of
https://github.com/ichmagmaus111/ghostgram.git
synced 2026-05-11 08:07:14 +02:00
Update Ghostgram features
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
load("@build_bazel_rules_swift//swift:swift.bzl", "swift_library")
|
||||
|
||||
sgdeps = ["//Swiftgram/SGSimpleSettings:SGSimpleSettings"]
|
||||
|
||||
swift_library(
|
||||
name = "TelegramStringFormatting",
|
||||
module_name = "TelegramStringFormatting",
|
||||
@@ -9,7 +11,7 @@ swift_library(
|
||||
copts = [
|
||||
"-warnings-as-errors",
|
||||
],
|
||||
deps = [
|
||||
deps = sgdeps + [
|
||||
"//submodules/TelegramCore:TelegramCore",
|
||||
"//submodules/Display:Display",
|
||||
"//submodules/PlatformRestrictionMatching:PlatformRestrictionMatching",
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import SGSimpleSettings
|
||||
import Foundation
|
||||
import TelegramPresentationData
|
||||
import TelegramUIPreferences
|
||||
@@ -46,8 +47,11 @@ public func stringForMessageTimestamp(timestamp: Int32, dateTimeFormat: Presenta
|
||||
} else {
|
||||
gmtime_r(&t, &timeinfo)
|
||||
}
|
||||
|
||||
return stringForShortTimestamp(hours: timeinfo.tm_hour, minutes: timeinfo.tm_min, dateTimeFormat: dateTimeFormat)
|
||||
if SGSimpleSettings.shared.secondsInMessages {
|
||||
return stringForShortTimestampWithSeconds(hours: timeinfo.tm_hour, minutes: timeinfo.tm_min, seconds: timeinfo.tm_sec, dateTimeFormat: dateTimeFormat)
|
||||
} else {
|
||||
return stringForShortTimestamp(hours: timeinfo.tm_hour, minutes: timeinfo.tm_min, dateTimeFormat: dateTimeFormat)
|
||||
}
|
||||
}
|
||||
|
||||
public func getDateTimeComponents(timestamp: Int32) -> (day: Int32, month: Int32, year: Int32, hour: Int32, minutes: Int32) {
|
||||
@@ -193,3 +197,69 @@ public func roundDateToDays(_ timestamp: Int32) -> Int32 {
|
||||
}
|
||||
return Int32(date.timeIntervalSince1970)
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// MARK: Swiftgram
|
||||
public func stringForDateWithoutDay(date: Date, timeZone: TimeZone? = TimeZone(secondsFromGMT: 0), strings: PresentationStrings) -> String {
|
||||
let formatter = DateFormatter()
|
||||
formatter.timeStyle = .none
|
||||
formatter.timeZone = timeZone
|
||||
formatter.locale = localeWithStrings(strings)
|
||||
formatter.setLocalizedDateFormatFromTemplate("MMMMyyyy")
|
||||
return formatter.string(from: date)
|
||||
}
|
||||
|
||||
|
||||
public func stringForDateWithoutDayAndMonth(date: Date, timeZone: TimeZone? = TimeZone(secondsFromGMT: 0), strings: PresentationStrings) -> String {
|
||||
let formatter = DateFormatter()
|
||||
formatter.timeStyle = .none
|
||||
formatter.timeZone = timeZone
|
||||
formatter.locale = localeWithStrings(strings)
|
||||
formatter.setLocalizedDateFormatFromTemplate("yyyy")
|
||||
return formatter.string(from: date)
|
||||
}
|
||||
|
||||
// MARK: Swiftgram
|
||||
public func stringForShortTimestampWithSeconds(hours: Int32, minutes: Int32, seconds: Int32, dateTimeFormat: PresentationDateTimeFormat) -> String {
|
||||
switch dateTimeFormat.timeFormat {
|
||||
case .regular:
|
||||
let hourString: String
|
||||
if hours == 0 {
|
||||
hourString = "12"
|
||||
} else if hours > 12 {
|
||||
hourString = "\(hours - 12)"
|
||||
} else {
|
||||
hourString = "\(hours)"
|
||||
}
|
||||
|
||||
let periodString: String
|
||||
if hours >= 12 {
|
||||
periodString = "PM"
|
||||
} else {
|
||||
periodString = "AM"
|
||||
}
|
||||
|
||||
let minuteString: String
|
||||
if minutes >= 10 {
|
||||
minuteString = "\(minutes)"
|
||||
} else {
|
||||
minuteString = "0\(minutes)"
|
||||
}
|
||||
if seconds >= 10 {
|
||||
return "\(hourString):\(minuteString):\(seconds)\u{00a0}\(periodString)"
|
||||
} else {
|
||||
return "\(hourString):\(minuteString):0\(seconds)\u{00a0}\(periodString)"
|
||||
}
|
||||
case .military:
|
||||
return String(format: "%02d:%02d:%02d", arguments: [Int(hours), Int(minutes), Int(seconds)])
|
||||
}
|
||||
}
|
||||
//
|
||||
|
||||
@@ -148,6 +148,8 @@ public func universalServiceMessageString(presentationData: (PresentationTheme,
|
||||
attributedString = addAttributesToStringWithRanges(strings.Notification_CreatedChatWithTitle(authorName, title)._tuple, body: bodyAttributes, argumentAttributes: peerMentionsAttributes(primaryTextColor: primaryTextColor, peerIds: [(0, message.author?.id)]))
|
||||
}
|
||||
}
|
||||
case .groupCreatorChange:
|
||||
attributedString = NSAttributedString(string: message.text, font: titleFont, textColor: primaryTextColor)
|
||||
case let .addedMembers(peerIds):
|
||||
if let peerId = peerIds.first, peerId == message.author?.id {
|
||||
if let peer = message.peers[message.id.peerId] as? TelegramChannel, case .broadcast = peer.info {
|
||||
@@ -791,7 +793,7 @@ public func universalServiceMessageString(presentationData: (PresentationTheme,
|
||||
if case let .unique(uniqueGift) = starGift {
|
||||
giftTitle = "\(uniqueGift.title) #\(formatCollectibleNumber(uniqueGift.number, dateTimeFormat: dateTimeFormat))"
|
||||
for attribute in uniqueGift.attributes {
|
||||
if case let .model(_, fileValue, _) = attribute {
|
||||
if case let .model(_, fileValue, _, _) = attribute {
|
||||
file = fileValue
|
||||
break
|
||||
}
|
||||
@@ -1262,7 +1264,7 @@ public func universalServiceMessageString(presentationData: (PresentationTheme,
|
||||
attributedString = addAttributesToStringWithRanges(strings.Notification_StarsGift_Sent(authorName, starsPrice)._tuple, body: bodyAttributes, argumentAttributes: attributes)
|
||||
}
|
||||
}
|
||||
case let .starGiftUnique(gift, isUpgrade, _, _, _, _, _, isPrepaidUpgrade, peerId, senderId, _, resaleStars, _, _, _, assigned, fromOffer):
|
||||
case let .starGiftUnique(gift, isUpgrade, _, _, _, _, _, isPrepaidUpgrade, peerId, senderId, _, resaleStars, _, _, _, assigned, fromOffer, _, _):
|
||||
if case let .unique(gift) = gift {
|
||||
if !forAdditionalServiceMessage && !"".isEmpty {
|
||||
attributedString = NSAttributedString(string: "\(gift.title) #\(presentationStringsFormattedNumber(gift.number, dateTimeFormat.groupingSeparator))", font: titleFont, textColor: primaryTextColor)
|
||||
|
||||
Reference in New Issue
Block a user