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
105 lines
5.0 KiB
Swift
105 lines
5.0 KiB
Swift
//
|
|
// Copyright 2019 Signal Messenger, LLC
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
//
|
|
|
|
import Foundation
|
|
import XCTest
|
|
@testable import SignalServiceKit
|
|
|
|
class InteractionFinderTest: SSKBaseTestSwift {
|
|
func testInteractions() {
|
|
let address1 = SignalServiceAddress(phoneNumber: "+fake-id")
|
|
// Threads
|
|
let contactThread1 = TSContactThread(contactAddress: SignalServiceAddress(phoneNumber: "+13213334444"))
|
|
let contactThread2 = TSContactThread(contactAddress: SignalServiceAddress(phoneNumber: "+13213334445"))
|
|
// Attachments
|
|
let attachmentData1 = Randomness.generateRandomBytes(1024)
|
|
let attachment1 = TSAttachmentStream(contentType: OWSMimeTypeImageGif,
|
|
byteCount: UInt32(attachmentData1.count),
|
|
sourceFilename: "some.gif",
|
|
caption: nil,
|
|
albumMessageId: nil)
|
|
let attachmentData2 = Randomness.generateRandomBytes(2048)
|
|
let attachment2 = TSAttachmentStream(contentType: OWSMimeTypePdf,
|
|
byteCount: UInt32(attachmentData2.count),
|
|
sourceFilename: "some.df", caption: nil, albumMessageId: nil)
|
|
// Messages
|
|
let outgoingMessage1 = TSOutgoingMessage(in: contactThread1, messageBody: "good heavens", attachmentId: attachment1.uniqueId)
|
|
let outgoingMessage2 = TSOutgoingMessage(in: contactThread2, messageBody: "land's sakes", attachmentId: attachment2.uniqueId)
|
|
let outgoingMessage3 = TSOutgoingMessage(in: contactThread2, messageBody: "oh my word", attachmentId: nil)
|
|
let errorMessage1 = TSErrorMessage.nonblockingIdentityChange(in: contactThread1,
|
|
address: address1,
|
|
wasIdentityVerified: false)
|
|
let errorMessage2 = TSErrorMessageBuilder(thread: contactThread1,
|
|
errorType: .groupCreationFailed).build()
|
|
// Non-message interactions
|
|
let missedCall = TSCall(callType: .incomingMissed,
|
|
offerType: .audio,
|
|
thread: contactThread1,
|
|
sentAtTimestamp: NSDate.ows_millisecondTimeStamp())
|
|
|
|
let finder1 = InteractionFinder(threadUniqueId: contactThread1.uniqueId)
|
|
let finder2 = InteractionFinder(threadUniqueId: contactThread2.uniqueId)
|
|
self.read { transaction in
|
|
XCTAssertEqual(0, finder1.count(transaction: transaction))
|
|
XCTAssertEqual(0, finder2.count(transaction: transaction))
|
|
}
|
|
|
|
self.write { transaction in
|
|
// Threads
|
|
contactThread1.anyInsert(transaction: transaction)
|
|
contactThread2.anyInsert(transaction: transaction)
|
|
// Attachments
|
|
attachment1.anyInsert(transaction: transaction)
|
|
attachment2.anyInsert(transaction: transaction)
|
|
// Messages
|
|
outgoingMessage1.anyInsert(transaction: transaction)
|
|
outgoingMessage2.anyInsert(transaction: transaction)
|
|
outgoingMessage3.anyInsert(transaction: transaction)
|
|
errorMessage1.anyInsert(transaction: transaction)
|
|
errorMessage2.anyInsert(transaction: transaction)
|
|
// Non-message interactions
|
|
missedCall.anyInsert(transaction: transaction)
|
|
}
|
|
|
|
self.read { transaction in
|
|
XCTAssertEqual(4, finder1.count(transaction: transaction))
|
|
XCTAssertEqual(2, finder2.count(transaction: transaction))
|
|
}
|
|
}
|
|
|
|
func testUnreadInArchiveIsIgnored() {
|
|
func makeThread(withUnreadMessages unreadCount: UInt, transaction: SDSAnyWriteTransaction) -> TSContactThread {
|
|
let thread = ContactThreadFactory().create(transaction: transaction)
|
|
|
|
if unreadCount > 0 {
|
|
let messageFactory = IncomingMessageFactory()
|
|
messageFactory.threadCreator = { _ in return thread }
|
|
_ = messageFactory.create(count: unreadCount, transaction: transaction)
|
|
}
|
|
|
|
return thread
|
|
}
|
|
|
|
let unarchivedCount = UInt(10)
|
|
let archivedCount = UInt(3)
|
|
|
|
write { transaction in
|
|
_ = makeThread(withUnreadMessages: unarchivedCount, transaction: transaction)
|
|
|
|
let archivedWithMessages = makeThread(withUnreadMessages: archivedCount, transaction: transaction)
|
|
ThreadAssociatedData
|
|
.fetchOrDefault(for: archivedWithMessages, transaction: transaction)
|
|
.updateWith(isArchived: true, updateStorageService: false, transaction: transaction)
|
|
}
|
|
|
|
// Unread count should be just the unarchived threads
|
|
|
|
read { transaction in
|
|
let unreadCount = InteractionFinder.unreadCountInAllThreads(transaction: transaction.unwrapGrdbRead)
|
|
XCTAssertEqual(unarchivedCount, unreadCount)
|
|
}
|
|
}
|
|
}
|