Skip to content

Commit

Permalink
Release 1.5.3 (220)
Browse files Browse the repository at this point in the history
  • Loading branch information
denis15yo committed Jan 26, 2024
1 parent 5e026b1 commit 1cd6417
Show file tree
Hide file tree
Showing 51 changed files with 16,649 additions and 6,851 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@ private enum DoubleBottomControllerEntry: ItemListNodeEntry {
}

public func doubleBottomListController(context: AccountContext, presentationData: PresentationData, accountsContexts: [(AccountContext, EnginePeer)]) -> ViewController {
let locale = presentationData.strings.baseLanguageCode
var pushControllerImpl: ((ViewController) -> Void)?
var getRootControllerImpl: (() -> UIViewController?)?

Expand All @@ -141,7 +140,7 @@ public func doubleBottomListController(context: AccountContext, presentationData
let signal = combineLatest(context.sharedContext.presentationData, transactionStatus) |> map { presentationData, contextStatus -> (ItemListControllerState, (ItemListNodeState, Any)) in

let entries = doubleBottomListControllerEntries(presentationData: presentationData, contextStatus: contextStatus, accountsContexts: accountsContexts)
let controllerState = ItemListControllerState(presentationData: ItemListPresentationData(presentationData), title: .text(l("DoubleBottom.Title", locale)), leftNavigationButton: nil, rightNavigationButton: nil, backNavigationButton: ItemListBackButton(title: presentationData.strings.Common_Back))
let controllerState = ItemListControllerState(presentationData: ItemListPresentationData(presentationData), title: .text(l("DoubleBottom.Title")), leftNavigationButton: nil, rightNavigationButton: nil, backNavigationButton: ItemListBackButton(title: presentationData.strings.Common_Back))
let listState = ItemListNodeState(presentationData: ItemListPresentationData(presentationData), entries: entries, style: .blocks)
return (controllerState, (listState, arguments))
}
Expand All @@ -160,10 +159,9 @@ public func doubleBottomListController(context: AccountContext, presentationData
// MARK: Entries list

private func doubleBottomListControllerEntries(presentationData: PresentationData, contextStatus: (Bool, Bool), accountsContexts: [(AccountContext, EnginePeer)]) -> [DoubleBottomControllerEntry] {
let locale = presentationData.strings.baseLanguageCode
var entries: [DoubleBottomControllerEntry] = []
entries.append(.isOn(l("DoubleBottom.Title", locale), VarSystemNGSettings.isDoubleBottomOn, VarSystemNGSettings.isDoubleBottomOn || (contextStatus.0 && contextStatus.1)))
entries.append(.info(l("DoubleBottom.Description", locale)))
entries.append(.isOn(l("DoubleBottom.Title"), VarSystemNGSettings.isDoubleBottomOn, VarSystemNGSettings.isDoubleBottomOn || (contextStatus.0 && contextStatus.1)))
entries.append(.info(l("DoubleBottom.Description")))

return entries
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,17 +142,15 @@ private struct QuickRepliesControllerState: Equatable {
}

private func quickRepliesControllerEntries(presentationData: PresentationData, state: QuickRepliesControllerState) -> [QuickRepliesControllerEntry] {
let locale = presentationData.strings.baseLanguageCode

var entries: [QuickRepliesControllerEntry] = []

entries.append(.replyPresetsHeader(l("NiceFeatures.QuickReplies.Description", locale)))
entries.append(.replyPresetsHeader(l("NiceFeatures.QuickReplies.Description")))

entries.append(.addNewPreset(l("NiceFeatures.QuickReplies.AddNew", locale)))
entries.append(.addNewPreset(l("NiceFeatures.QuickReplies.AddNew")))

let customPresets = state.items
for (index, preset) in customPresets.enumerated() {
entries.append(.replyPreset(preset.id, l("NiceFeatures.QuickReplies.Placeholder", locale), preset.text, index))
entries.append(.replyPreset(preset.id, l("NiceFeatures.QuickReplies.Placeholder"), preset.text, index))
}

return entries
Expand Down Expand Up @@ -246,8 +244,6 @@ public func quickRepliesController(context: AccountContext) -> ViewController {
let signal = combineLatest(context.sharedContext.presentationData, statePromise.get())
|> deliverOnMainQueue
|> map { presentationData, state -> (ItemListControllerState, (ItemListNodeState, Any)) in
let locale = presentationData.strings.baseLanguageCode

let focusItemTag: ItemListItemTag?
if let focusPresetId = state.focusPresetId {
focusItemTag = QuickRepliesControllerEntryTag.preset(focusPresetId)
Expand All @@ -256,7 +252,7 @@ public func quickRepliesController(context: AccountContext) -> ViewController {
}
let ensureVisibleItemTag = focusItemTag

let controllerState = ItemListControllerState(presentationData: ItemListPresentationData(presentationData), title: .text(l("NiceFeatures.QuickReplies", locale)), leftNavigationButton: nil, rightNavigationButton: nil, backNavigationButton: ItemListBackButton(title: presentationData.strings.Common_Back), animateChanges: false)
let controllerState = ItemListControllerState(presentationData: ItemListPresentationData(presentationData), title: .text(l("NiceFeatures.QuickReplies")), leftNavigationButton: nil, rightNavigationButton: nil, backNavigationButton: ItemListBackButton(title: presentationData.strings.Common_Back), animateChanges: false)
let listState = ItemListNodeState(presentationData: ItemListPresentationData(presentationData), entries: quickRepliesControllerEntries(presentationData: presentationData, state: state), style: .blocks, focusItemTag: focusItemTag, ensureVisibleItemTag: ensureVisibleItemTag, animateChanges: true)

return (controllerState, (listState, arguments))
Expand Down
8 changes: 4 additions & 4 deletions Nicegram/NGStrings/Sources/Strings.swift
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import Foundation
import NGLocalization

public func l(_ key: String, _ locale: String? = nil) -> String {
let code = locale ?? ng_getTgLangCode()
public func l(_ key: String) -> String {
let code = ng_getTgLangCode()
let table = "NiceLocalizable"

let bundle = localizationBundle(code: code)
Expand All @@ -21,8 +21,8 @@ public func l(_ key: String, _ locale: String? = nil) -> String {
) ?? enString
}

public func l(_ key: String, _ locale: String? = nil, with args: CVarArg...) -> String {
return String(format: l(key, locale), args)
public func l(_ key: String, with args: CVarArg...) -> String {
return String(format: l(key), args)
}

private func localizationBundle(
Expand Down
10 changes: 4 additions & 6 deletions Nicegram/NGTranslate/Sources/GTranslate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,17 @@ public func setPreferredTranslationTargetLanguage(code: String) {
}

public func getTranslateUrl(_ message: String,_ toLang: String) -> String {
var sanitizedMessage = message.replaceCharactersFromSet(characterSet:CharacterSet.newlines, replacementString: "¦")

if let dotRange = sanitizedMessage.range(of: "\n\n" + gTranslateSeparator) {
sanitizedMessage.removeSubrange(dotRange.lowerBound..<sanitizedMessage.endIndex)
}
let sanitizedMessage = message.replacingOccurrences(of: "\n", with: "<br>")

var queryCharSet = NSCharacterSet.urlQueryAllowed
queryCharSet.remove(charactersIn: "+&")
return "https://translate.google.com/m?hl=en&tl=\(toLang)&sl=auto&q=\(sanitizedMessage.addingPercentEncoding(withAllowedCharacters: queryCharSet) ?? "")"
}

func prepareResultString(_ str: String) -> String {
return str.htmlDecoded.replacingOccurrences(of: " ¦", with: "\n").replacingOccurrences(of: "¦ ", with: "\n").replacingOccurrences(of: "¦", with: "\n")
str
.htmlDecoded
.replacingOccurrences(of: "<br>", with: "\n")
}

public func parseTranslateResponse(_ data: String) -> String {
Expand Down
21 changes: 21 additions & 0 deletions Nicegram/NGTranslate/Sources/GTranslateTgHelper.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import AccountContext
import Postbox

public extension Message {
func hasNicegramTranslation() -> Bool {
hasTextBlock(.ngTranslation)
}

func addNicegramTranslation(
_ text: String,
context: AccountContext
) {
addTextBlock(text: text, block: .ngTranslation, context: context)
}

func removeNicegramTranslation(
context: AccountContext
) {
removeTextBlock(block: .ngTranslation, context: context)
}
}
13 changes: 0 additions & 13 deletions Nicegram/NGTranslate/Sources/SpeechToText/TelegramHelpers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -66,19 +66,6 @@ private func updateAudioTranscriptionMessageAttribute(message: Message, text: St
}).start()
}

private func updateMessageText(message: Message, newMessageText: String, context: AccountContext) {
let _ = (context.account.postbox.transaction { transaction -> Void in
transaction.updateMessage(message.id, update: { currentMessage in
var storeForwardInfo: StoreMessageForwardInfo?
if let forwardInfo = currentMessage.forwardInfo {
storeForwardInfo = StoreMessageForwardInfo(authorId: forwardInfo.author?.id, sourceId: forwardInfo.source?.id, sourceMessageId: forwardInfo.sourceMessageId, date: forwardInfo.date, authorSignature: forwardInfo.authorSignature, psaType: forwardInfo.psaType, flags: forwardInfo.flags)
}

return .update(StoreMessage(id: currentMessage.id, globallyUniqueId: currentMessage.globallyUniqueId, groupingKey: currentMessage.groupingKey, threadId: currentMessage.threadId, timestamp: currentMessage.timestamp, flags: StoreMessageFlags(currentMessage.flags), tags: currentMessage.tags, globalTags: currentMessage.globalTags, localTags: currentMessage.localTags, forwardInfo: storeForwardInfo, authorId: currentMessage.author?.id, text: newMessageText, attributes: currentMessage.attributes, media: currentMessage.media))
})
}).start()
}

private extension String {
func appendingSpeechToTextLoading() -> String {
return self.removingSpeechToTextMeta() + "\(speechToTextSeparator)\(speechToTextLoading)"
Expand Down
10 changes: 1 addition & 9 deletions Nicegram/NGUI/Sources/AiChatSettingsController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,18 @@ private enum AiChatSettingsControllerSection: Int32 {

@available(iOS 13.0, *)
private enum AiChatSettingsControllerEntry: ItemListNodeEntry {
case showInDialogs(Bool)
case showInChat(Bool)
case clearHistory

var section: ItemListSectionId {
switch self {
case .showInDialogs, .showInChat, .clearHistory:
case .showInChat, .clearHistory:
return AiChatSettingsControllerSection.main.rawValue
}
}

var stableId: Int32 {
switch self {
case .showInDialogs:
return 0
case .showInChat:
return 1
case .clearHistory:
Expand All @@ -41,10 +38,6 @@ private enum AiChatSettingsControllerEntry: ItemListNodeEntry {

func item(presentationData: ItemListPresentationData, arguments: Any) -> ListViewItem {
switch self {
case let .showInDialogs(value):
return ItemListSwitchItem(presentationData: presentationData, title: AiChatUITgHelper.settingsShowInDialogs, value: value, sectionId: self.section, style: .blocks) { value in
RepoUserTgHelper.resolvePreferencesRepository().displayAiBotInChatsList = value
}
case let .showInChat(value):
return ItemListSwitchItem(presentationData: presentationData, title: AiChatUITgHelper.settingsShowInChat, value: value, sectionId: self.section, style: .blocks) { value in
RepoUserTgHelper.resolvePreferencesRepository().displayAiBotInChat = value
Expand All @@ -63,7 +56,6 @@ private func controllerEntries() -> [AiChatSettingsControllerEntry] {

var entries: [AiChatSettingsControllerEntry] = []

entries.append(.showInDialogs(preferencesRepository.displayAiBotInChatsList))
entries.append(.showInChat(preferencesRepository.displayAiBotInChat))
entries.append(.clearHistory)

Expand Down
9 changes: 4 additions & 5 deletions Nicegram/NGUI/Sources/IgnoreTranslateController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -117,16 +117,15 @@ private func ignoreTranslateControllerEntries(presentationData: PresentationData
var entries: [Entry] = []
let theme = presentationData.theme
let _ = presentationData.strings
let locale = presentationData.strings.baseLanguageCode

let ignoredTranslations = NGSettings.ignoreTranslate
entries.append(.useIgnoreLanguages(theme, l("Premium.OnetapTranslate.UseIgnoreLanguages", locale), NGSettings.useIgnoreLanguages))
entries.append(.useIgnoreLanguagesNote(theme, l("Premium.OnetapTranslate.UseIgnoreLanguages.Note", locale)))
entries.append(.useIgnoreLanguages(theme, l("Premium.OnetapTranslate.UseIgnoreLanguages"), NGSettings.useIgnoreLanguages))
entries.append(.useIgnoreLanguagesNote(theme, l("Premium.OnetapTranslate.UseIgnoreLanguages.Note")))
if !NGSettings.useIgnoreLanguages {
return entries
}

entries.append(.header(theme, l("Premium.IgnoreTranslate.Header", locale)))
entries.append(.header(theme, l("Premium.IgnoreTranslate.Header")))

let pre = Locale.preferredLanguages
var preLangs: [String] = []
Expand Down Expand Up @@ -234,7 +233,7 @@ public func ignoreTranslateController(context: AccountContext) -> ViewController

var scrollToItem: ListViewScrollToItem?

let controllerState = ItemListControllerState(presentationData: ItemListPresentationData(presentationData), title: .text(l("Premium.IgnoreTranslate.Title", presentationData.strings.baseLanguageCode)), leftNavigationButton: nil, rightNavigationButton: nil, backNavigationButton: ItemListBackButton(title: presentationData.strings.Common_Back))
let controllerState = ItemListControllerState(presentationData: ItemListPresentationData(presentationData), title: .text(l("Premium.IgnoreTranslate.Title")), leftNavigationButton: nil, rightNavigationButton: nil, backNavigationButton: ItemListBackButton(title: presentationData.strings.Common_Back))
let listState = ItemListNodeState(presentationData: ItemListPresentationData(presentationData), entries: entries, style: .blocks, ensureVisibleItemTag: nil, initialScrollToItem: scrollToItem, animateChanges: false)

return (controllerState, (listState, arguments))
Expand Down

0 comments on commit 1cd6417

Please sign in to comment.