Change license to AGPL
This commit:
- Updates the `LICENSE` file
- Start every file with something like:
// Copyright YEAR_FIRST_PUBLISHED Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
---
First, I removed existing license headers with this Ruby 3.1.2 script:
require 'set'
EXTENSIONS_TO_CHECK = Set['.h', '.hpp', '.cpp', '.m', '.mm', '.pch', '.swift']
same = 0
different = 0
all_files = `git ls-files`.lines.map { |line| line.strip }
all_files.each do |relative_path|
if relative_path == 'Pods'
next
end
unless EXTENSIONS_TO_CHECK.include? File.extname(relative_path)
next
end
path = File.expand_path(relative_path)
contents = File.read(path)
new_contents = contents.sub(/\/\/\n\/\/ Copyright .*\n\/\/\n\n/, '')
if contents == new_contents
same += 1
else
different += 1
end
File.write(path, new_contents)
end
puts "updated #{different} file(s), left #{same} untouched"
I'm sure this script could be improved, but it worked well enough.
Then, I created `Scripts/lint/lint-license-headers` and ran it to auto-
fix a lot of files. This changed the mode of some files, but I think
that's actually desirable. For example,
`SignalServiceKit/src/Util/AppContext.m` previously had a mode of
`0755/-rwxr-xr-x`, and it's now `0644/-rw-r--r--`.
Then I fixed some stragglers and updated the precommit script.
See [a similar change in the Desktop app][0].
[0]: 8bfaf598af
234 lines
12 KiB
Swift
234 lines
12 KiB
Swift
//
|
|
// Copyright 2018 Signal Messenger, LLC
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
//
|
|
|
|
import Foundation
|
|
|
|
@objc
|
|
protocol MessageActionsDelegate: AnyObject {
|
|
func messageActionsShowDetailsForItem(_ itemViewModel: CVItemViewModelImpl)
|
|
func messageActionsReplyToItem(_ itemViewModel: CVItemViewModelImpl)
|
|
func messageActionsForwardItem(_ itemViewModel: CVItemViewModelImpl)
|
|
func messageActionsStartedSelect(initialItem itemViewModel: CVItemViewModelImpl)
|
|
func messageActionsDeleteItem(_ itemViewModel: CVItemViewModelImpl)
|
|
func messageActionsSpeakItem(_ itemViewModel: CVItemViewModelImpl)
|
|
func messageActionsStopSpeakingItem(_ itemViewModel: CVItemViewModelImpl)
|
|
}
|
|
|
|
// MARK: -
|
|
|
|
struct MessageActionBuilder {
|
|
static func reply(itemViewModel: CVItemViewModelImpl, delegate: MessageActionsDelegate) -> MessageAction {
|
|
return MessageAction(.reply,
|
|
accessibilityLabel: NSLocalizedString("MESSAGE_ACTION_REPLY", comment: "Action sheet button title"),
|
|
accessibilityIdentifier: UIView.accessibilityIdentifier(containerName: "message_action", name: "reply"),
|
|
contextMenuTitle: NSLocalizedString("CONTEXT_MENU_REPLY", comment: "Context menu button title"),
|
|
contextMenuAttributes: [],
|
|
block: { [weak delegate] (_) in
|
|
delegate?.messageActionsReplyToItem(itemViewModel)
|
|
|
|
})
|
|
}
|
|
|
|
static func copyText(itemViewModel: CVItemViewModelImpl, delegate: MessageActionsDelegate) -> MessageAction {
|
|
return MessageAction(.copy,
|
|
accessibilityLabel: NSLocalizedString("MESSAGE_ACTION_COPY_TEXT", comment: "Action sheet button title"),
|
|
accessibilityIdentifier: UIView.accessibilityIdentifier(containerName: "message_action", name: "copy_text"),
|
|
contextMenuTitle: NSLocalizedString("CONTEXT_MENU_COPY", comment: "Context menu button title"),
|
|
contextMenuAttributes: [],
|
|
block: { (_) in
|
|
itemViewModel.copyTextAction()
|
|
})
|
|
}
|
|
|
|
static func showDetails(itemViewModel: CVItemViewModelImpl, delegate: MessageActionsDelegate) -> MessageAction {
|
|
return MessageAction(.info,
|
|
accessibilityLabel: NSLocalizedString("MESSAGE_ACTION_DETAILS", comment: "Action sheet button title"),
|
|
accessibilityIdentifier: UIView.accessibilityIdentifier(containerName: "message_action", name: "show_details"),
|
|
contextMenuTitle: NSLocalizedString("CONTEXT_MENU_DETAILS", comment: "Context menu button title"),
|
|
contextMenuAttributes: [],
|
|
block: { [weak delegate] (_) in
|
|
delegate?.messageActionsShowDetailsForItem(itemViewModel)
|
|
})
|
|
}
|
|
|
|
static func deleteMessage(itemViewModel: CVItemViewModelImpl, delegate: MessageActionsDelegate) -> MessageAction {
|
|
return MessageAction(.delete,
|
|
accessibilityLabel: NSLocalizedString("MESSAGE_ACTION_DELETE_MESSAGE", comment: "Action sheet button title"),
|
|
accessibilityIdentifier: UIView.accessibilityIdentifier(containerName: "message_action", name: "delete_message"),
|
|
contextMenuTitle: NSLocalizedString("CONTEXT_MENU_DELETE_MESSAGE", comment: "Context menu button title"),
|
|
contextMenuAttributes: [.destructive],
|
|
block: { [weak delegate] (_) in
|
|
delegate?.messageActionsDeleteItem(itemViewModel)
|
|
})
|
|
}
|
|
|
|
static func shareMedia(itemViewModel: CVItemViewModelImpl, delegate: MessageActionsDelegate) -> MessageAction {
|
|
return MessageAction(.share,
|
|
accessibilityLabel: NSLocalizedString("MESSAGE_ACTION_SHARE_MEDIA", comment: "Action sheet button title"),
|
|
accessibilityIdentifier: UIView.accessibilityIdentifier(containerName: "message_action", name: "share_media"),
|
|
contextMenuTitle: NSLocalizedString("CONTEXT_MENU_SHARE_MEDIA", comment: "Context menu button title"),
|
|
contextMenuAttributes: [],
|
|
block: { sender in
|
|
itemViewModel.shareMediaAction(sender: sender)
|
|
})
|
|
}
|
|
|
|
static func forwardMessage(itemViewModel: CVItemViewModelImpl, delegate: MessageActionsDelegate) -> MessageAction {
|
|
return MessageAction(.forward,
|
|
accessibilityLabel: NSLocalizedString("MESSAGE_ACTION_FORWARD_MESSAGE", comment: "Action sheet button title"),
|
|
accessibilityIdentifier: UIView.accessibilityIdentifier(containerName: "message_action", name: "forward_message"),
|
|
contextMenuTitle: NSLocalizedString("CONTEXT_MENU_FORWARD_MESSAGE", comment: "Context menu button title"),
|
|
contextMenuAttributes: [],
|
|
block: { [weak delegate] (_) in
|
|
delegate?.messageActionsForwardItem(itemViewModel)
|
|
})
|
|
}
|
|
|
|
static func selectMessage(itemViewModel: CVItemViewModelImpl, delegate: MessageActionsDelegate) -> MessageAction {
|
|
return MessageAction(.select,
|
|
accessibilityLabel: NSLocalizedString("MESSAGE_ACTION_SELECT_MESSAGE", comment: "Action sheet accessibility label"),
|
|
accessibilityIdentifier: UIView.accessibilityIdentifier(containerName: "message_action", name: "select_message"),
|
|
contextMenuTitle: NSLocalizedString("CONTEXT_MENU_SELECT_MESSAGE", comment: "Context menu button title"),
|
|
contextMenuAttributes: [],
|
|
block: { [weak delegate] (_) in
|
|
delegate?.messageActionsStartedSelect(initialItem: itemViewModel)
|
|
})
|
|
}
|
|
|
|
static func speakMessage(itemViewModel: CVItemViewModelImpl, delegate: MessageActionsDelegate) -> MessageAction {
|
|
MessageAction(
|
|
.speak,
|
|
accessibilityLabel: NSLocalizedString("MESSAGE_ACTION_SPEAK_MESSAGE", comment: "Action sheet accessibility label"),
|
|
accessibilityIdentifier: UIView.accessibilityIdentifier(containerName: "message_action", name: "speak_message"),
|
|
contextMenuTitle: NSLocalizedString("CONTEXT_MENU_SPEAK_MESSAGE", comment: "Context menu button title"),
|
|
contextMenuAttributes: [],
|
|
block: { [weak delegate] _ in
|
|
delegate?.messageActionsSpeakItem(itemViewModel)
|
|
}
|
|
)
|
|
}
|
|
|
|
static func stopSpeakingMessage(itemViewModel: CVItemViewModelImpl, delegate: MessageActionsDelegate) -> MessageAction {
|
|
MessageAction(
|
|
.stopSpeaking,
|
|
accessibilityLabel: NSLocalizedString("MESSAGE_ACTION_STOP_SPEAKING_MESSAGE", comment: "Action sheet accessibility label"),
|
|
accessibilityIdentifier: UIView.accessibilityIdentifier(containerName: "message_action", name: "stop_speaking_message"),
|
|
contextMenuTitle: NSLocalizedString("CONTEXT_MENU_STOP_SPEAKING_MESSAGE", comment: "Context menu button title"),
|
|
contextMenuAttributes: [],
|
|
block: { [weak delegate] _ in
|
|
delegate?.messageActionsStopSpeakingItem(itemViewModel)
|
|
}
|
|
)
|
|
}
|
|
}
|
|
|
|
@objc
|
|
class MessageActions: NSObject {
|
|
|
|
@objc
|
|
class func textActions(itemViewModel: CVItemViewModelImpl, shouldAllowReply: Bool, delegate: MessageActionsDelegate) -> [MessageAction] {
|
|
var actions: [MessageAction] = []
|
|
|
|
let showDetailsAction = MessageActionBuilder.showDetails(itemViewModel: itemViewModel, delegate: delegate)
|
|
actions.append(showDetailsAction)
|
|
|
|
let deleteAction = MessageActionBuilder.deleteMessage(itemViewModel: itemViewModel, delegate: delegate)
|
|
actions.append(deleteAction)
|
|
|
|
if itemViewModel.canCopyOrShareOrSpeakText {
|
|
let copyTextAction = MessageActionBuilder.copyText(itemViewModel: itemViewModel, delegate: delegate)
|
|
actions.append(copyTextAction)
|
|
}
|
|
|
|
if shouldAllowReply {
|
|
let replyAction = MessageActionBuilder.reply(itemViewModel: itemViewModel, delegate: delegate)
|
|
actions.append(replyAction)
|
|
}
|
|
|
|
if itemViewModel.canForwardMessage {
|
|
actions.append(MessageActionBuilder.forwardMessage(itemViewModel: itemViewModel, delegate: delegate))
|
|
}
|
|
|
|
let selectAction = MessageActionBuilder.selectMessage(itemViewModel: itemViewModel, delegate: delegate)
|
|
actions.append(selectAction)
|
|
|
|
if itemViewModel.canCopyOrShareOrSpeakText {
|
|
// If the user started speaking a message and then turns of the "speak selection" OS setting,
|
|
// we still want to let them turn it off.
|
|
if self.speechManager.isSpeaking {
|
|
let stopSpeakingAction = MessageActionBuilder.stopSpeakingMessage(itemViewModel: itemViewModel, delegate: delegate)
|
|
actions.append(stopSpeakingAction)
|
|
} else if UIAccessibility.isSpeakSelectionEnabled {
|
|
let speakAction = MessageActionBuilder.speakMessage(itemViewModel: itemViewModel, delegate: delegate)
|
|
actions.append(speakAction)
|
|
}
|
|
}
|
|
|
|
return actions
|
|
}
|
|
|
|
@objc
|
|
class func mediaActions(itemViewModel: CVItemViewModelImpl, shouldAllowReply: Bool, delegate: MessageActionsDelegate) -> [MessageAction] {
|
|
var actions: [MessageAction] = []
|
|
|
|
let showDetailsAction = MessageActionBuilder.showDetails(itemViewModel: itemViewModel, delegate: delegate)
|
|
actions.append(showDetailsAction)
|
|
|
|
let deleteAction = MessageActionBuilder.deleteMessage(itemViewModel: itemViewModel, delegate: delegate)
|
|
actions.append(deleteAction)
|
|
|
|
if itemViewModel.canShareMedia {
|
|
let shareMediaAction = MessageActionBuilder.shareMedia(itemViewModel: itemViewModel, delegate: delegate)
|
|
actions.append(shareMediaAction)
|
|
}
|
|
|
|
if shouldAllowReply {
|
|
let replyAction = MessageActionBuilder.reply(itemViewModel: itemViewModel, delegate: delegate)
|
|
actions.append(replyAction)
|
|
}
|
|
|
|
if itemViewModel.canForwardMessage {
|
|
actions.append(MessageActionBuilder.forwardMessage(itemViewModel: itemViewModel, delegate: delegate))
|
|
}
|
|
|
|
let selectAction = MessageActionBuilder.selectMessage(itemViewModel: itemViewModel, delegate: delegate)
|
|
actions.append(selectAction)
|
|
|
|
return actions
|
|
}
|
|
|
|
@objc
|
|
class func quotedMessageActions(itemViewModel: CVItemViewModelImpl, shouldAllowReply: Bool, delegate: MessageActionsDelegate) -> [MessageAction] {
|
|
var actions: [MessageAction] = []
|
|
|
|
let showDetailsAction = MessageActionBuilder.showDetails(itemViewModel: itemViewModel, delegate: delegate)
|
|
actions.append(showDetailsAction)
|
|
|
|
let deleteAction = MessageActionBuilder.deleteMessage(itemViewModel: itemViewModel, delegate: delegate)
|
|
actions.append(deleteAction)
|
|
|
|
if shouldAllowReply {
|
|
let replyAction = MessageActionBuilder.reply(itemViewModel: itemViewModel, delegate: delegate)
|
|
actions.append(replyAction)
|
|
}
|
|
|
|
if itemViewModel.canForwardMessage {
|
|
actions.append(MessageActionBuilder.forwardMessage(itemViewModel: itemViewModel, delegate: delegate))
|
|
}
|
|
|
|
let selectAction = MessageActionBuilder.selectMessage(itemViewModel: itemViewModel, delegate: delegate)
|
|
actions.append(selectAction)
|
|
|
|
return actions
|
|
}
|
|
|
|
@objc
|
|
class func infoMessageActions(itemViewModel: CVItemViewModelImpl, delegate: MessageActionsDelegate) -> [MessageAction] {
|
|
let deleteAction = MessageActionBuilder.deleteMessage(itemViewModel: itemViewModel, delegate: delegate)
|
|
let selectAction = MessageActionBuilder.selectMessage(itemViewModel: itemViewModel, delegate: delegate)
|
|
return [deleteAction, selectAction]
|
|
}
|
|
}
|