Skip to content
This repository was archived by the owner on Sep 20, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Classes/Issues/Comments/Details/IssueCommentDetailCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ final class IssueCommentDetailCell: IssueCommentBaseCell, ListBindable {
private let loginLabel = UILabel()
private let dateLabel = ShowMoreDetailsLabel()
private let editedLabel = ShowMoreDetailsLabel()
private let badgeView = IssueDetailBadgeView()
private var login = ""

override init(frame: CGRect) {
Expand Down Expand Up @@ -72,6 +73,12 @@ final class IssueCommentDetailCell: IssueCommentBaseCell, ListBindable {
make.left.equalTo(loginLabel.snp.right).offset(Styles.Sizes.columnSpacing/2)
make.centerY.equalTo(loginLabel)
}

contentView.addSubview(badgeView)
badgeView.snp.makeConstraints { make in
make.centerY.equalTo(dateLabel)
make.right.equalTo(dateLabel.snp.left).offset(-Styles.Sizes.columnSpacing)
}
}

required init?(coder aDecoder: NSCoder) {
Expand All @@ -96,6 +103,7 @@ final class IssueCommentDetailCell: IssueCommentBaseCell, ListBindable {
imageView.sd_setImage(with: viewModel.avatarURL)
dateLabel.setText(date: viewModel.date, format: .short)
loginLabel.text = viewModel.login
badgeView.isHidden = !viewModel.sentWithGitHawk

if let editedLogin = viewModel.editedBy, let editedDate = viewModel.editedAt {
editedLabel.isHidden = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,24 @@ final class IssueCommentDetailsViewModel: ListDiffable {
let didAuthor: Bool
let editedBy: String?
let editedAt: Date?
let sentWithGitHawk: Bool

init(
date: Date,
login: String,
avatarURL: URL,
didAuthor: Bool,
editedBy: String?,
editedAt: Date?
editedAt: Date?,
sentWithGitHawk: Bool
) {
self.date = date
self.login = login
self.avatarURL = avatarURL
self.didAuthor = didAuthor
self.editedBy = editedBy
self.editedAt = editedAt
self.sentWithGitHawk = sentWithGitHawk
}

func diffIdentifier() -> NSObjectProtocol {
Expand Down
53 changes: 53 additions & 0 deletions Classes/Issues/Comments/Details/IssueDetailBadgeView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
//
// IssueDetailBadgeView.swift
// Freetime
//
// Created by Ryan Nystrom on 7/29/18.
// Copyright © 2018 Ryan Nystrom. All rights reserved.
//

import UIKit

final class IssueDetailBadgeView: UIImageView {

init() {
super.init(frame: .zero)
image = UIImage(named: "githawk-badge")?.withRenderingMode(.alwaysTemplate)
tintColor = Styles.Colors.Blue.medium.color

isUserInteractionEnabled = true

let tap = UITapGestureRecognizer(
target: self,
action: #selector(ShowMoreDetailsLabel.showMenu(recognizer:))
)
addGestureRecognizer(tap)
}

required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

override var canBecomeFirstResponder: Bool {
return true
}

// MARK: Private API

@objc func showMenu(recognizer: UITapGestureRecognizer) {
becomeFirstResponder()

let menu = UIMenuController.shared
menu.menuItems = [
UIMenuItem(
title: NSLocalizedString("Sent with GitHawk", comment: ""),
action: #selector(IssueDetailBadgeView.empty)
)
]
menu.setTargetRect(bounds, in: self)
menu.setMenuVisible(true, animated: trueUnlessReduceMotionEnabled)
}

@objc func empty() {}

}
18 changes: 18 additions & 0 deletions Classes/Issues/Comments/Markdown/CheckIfSentWithGitHawk.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//
// CheckIfSentWithGitHawk.swift
// Freetime
//
// Created by Ryan Nystrom on 7/29/18.
// Copyright © 2018 Ryan Nystrom. All rights reserved.
//

import Foundation

func CheckIfSentWithGitHawk(markdown: String) -> (sentWithGitHawk: Bool, markdown: String) {
let nsstring = markdown as NSString
let range = nsstring.range(of: Signature.signature, options: .backwards)
if range.location != NSNotFound && range.location + range.length == nsstring.length {
return (true, nsstring.replacingCharacters(in: range, with: ""))
}
return (false, markdown)
}
7 changes: 5 additions & 2 deletions Classes/Issues/IssueViewModels.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,17 +65,20 @@ func createCommentModel(
let avatarURL = URL(string: author.avatarUrl)
else { return nil }

let checkedMarkdown = CheckIfSentWithGitHawk(markdown: commentFields.body)

let details = IssueCommentDetailsViewModel(
date: date,
login: author.login,
avatarURL: avatarURL,
didAuthor: commentFields.viewerDidAuthor,
editedBy: commentFields.editor?.login,
editedAt: commentFields.lastEditedAt?.githubDate
editedAt: commentFields.lastEditedAt?.githubDate,
sentWithGitHawk: checkedMarkdown.sentWithGitHawk
)

let bodies = MarkdownModels(
commentFields.body,
checkedMarkdown.markdown,
owner: owner,
repo: repo,
width: width,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,18 +177,21 @@ private func createReviewComment(
contentSizeCategory: UIContentSizeCategory,
width: CGFloat
) -> IssueCommentModel {
let checkedMarkdown = CheckIfSentWithGitHawk(markdown: model.body)

let details = IssueCommentDetailsViewModel(
date: model.created,
login: model.author,
avatarURL: model.authorAvatarURL,
didAuthor: model.author == viewer,
editedBy: nil,
editedAt: nil
editedAt: nil,
sentWithGitHawk: checkedMarkdown.sentWithGitHawk
)

let reactions = IssueCommentReactionViewModel(models: [])
let bodies = MarkdownModels(
model.body,
checkedMarkdown.markdown,
owner: owner,
repo: repo,
width: width,
Expand Down
10 changes: 7 additions & 3 deletions Classes/Systems/Signature.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,15 @@ enum Signature {
}
}

static func signed(text: String) -> String {
guard enabled else { return text }
static var signature: String {
let format = NSLocalizedString("Sent with %@", comment: "")
let signature = String(format: format, "<a href=\"http://githawk.com\">GitHawk</a>")
return text + "\n\n<sub>\(signature)</sub>"
return "\n\n<sub>\(signature)</sub>"
}

static func signed(text: String) -> String {
guard enabled else { return text }
return text + signature
}

}
2 changes: 1 addition & 1 deletion Classes/Views/ShowMoreDetailsLabel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ final class ShowMoreDetailsLabel: UILabel {

// MARK: Private API

@objc func showMenu(recognizer: UITapGestureRecognizer) {
@objc func showMenu(recognizer: UILongPressGestureRecognizer) {
guard recognizer.state == .began,
!detailText.isEmpty else { return }

Expand Down
8 changes: 8 additions & 0 deletions Freetime.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,8 @@
2965F3702071508C003CC92F /* StyledTextBuilder+Checkbox.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2965F36F2071508C003CC92F /* StyledTextBuilder+Checkbox.swift */; };
2965F37220715161003CC92F /* StyledTextBuilder+NewBase.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2965F37120715161003CC92F /* StyledTextBuilder+NewBase.swift */; };
29693EE520FAA05F00336200 /* IssueAutocomplete.swift in Sources */ = {isa = PBXBuildFile; fileRef = 29693EE420FAA05F00336200 /* IssueAutocomplete.swift */; };
296A4960210E7B9A00BBBF2B /* IssueDetailBadgeView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 296A495F210E7B9A00BBBF2B /* IssueDetailBadgeView.swift */; };
296A4962210E7E0E00BBBF2B /* CheckIfSentWithGitHawk.swift in Sources */ = {isa = PBXBuildFile; fileRef = 296A4961210E7E0E00BBBF2B /* CheckIfSentWithGitHawk.swift */; };
296B4E311F7C805600C16887 /* GraphQLIDDecode.swift in Sources */ = {isa = PBXBuildFile; fileRef = 296B4E301F7C805600C16887 /* GraphQLIDDecode.swift */; };
296B4E341F7C80B800C16887 /* GraphQLIDDecodeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 296B4E331F7C80B800C16887 /* GraphQLIDDecodeTests.swift */; };
2971722B1F069E6B005E43AC /* SpinnerSectionController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2971722A1F069E6B005E43AC /* SpinnerSectionController.swift */; };
Expand Down Expand Up @@ -715,6 +717,8 @@
2965F36F2071508C003CC92F /* StyledTextBuilder+Checkbox.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "StyledTextBuilder+Checkbox.swift"; sourceTree = "<group>"; };
2965F37120715161003CC92F /* StyledTextBuilder+NewBase.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "StyledTextBuilder+NewBase.swift"; sourceTree = "<group>"; };
29693EE420FAA05F00336200 /* IssueAutocomplete.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IssueAutocomplete.swift; sourceTree = "<group>"; };
296A495F210E7B9A00BBBF2B /* IssueDetailBadgeView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = IssueDetailBadgeView.swift; sourceTree = "<group>"; };
296A4961210E7E0E00BBBF2B /* CheckIfSentWithGitHawk.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CheckIfSentWithGitHawk.swift; sourceTree = "<group>"; };
296B4E301F7C805600C16887 /* GraphQLIDDecode.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GraphQLIDDecode.swift; sourceTree = "<group>"; };
296B4E331F7C80B800C16887 /* GraphQLIDDecodeTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GraphQLIDDecodeTests.swift; sourceTree = "<group>"; };
2971722A1F069E6B005E43AC /* SpinnerSectionController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SpinnerSectionController.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1239,6 +1243,7 @@
292FCACD1EDFCC510026635E /* Details */ = {
isa = PBXGroup;
children = (
296A495F210E7B9A00BBBF2B /* IssueDetailBadgeView.swift */,
292FCACE1EDFCC510026635E /* IssueCommentDetailCell.swift */,
292FCACF1EDFCC510026635E /* IssueCommentDetailsViewModel.swift */,
);
Expand Down Expand Up @@ -1464,6 +1469,7 @@
2965F37120715161003CC92F /* StyledTextBuilder+NewBase.swift */,
29921BCB1EF624D400C1E848 /* UIFont+MutableTraits.swift */,
2977788720B0DAD500F2AFC2 /* ViewMarkdownViewController.swift */,
296A4961210E7E0E00BBBF2B /* CheckIfSentWithGitHawk.swift */,
);
path = Markdown;
sourceTree = "<group>";
Expand Down Expand Up @@ -2919,6 +2925,7 @@
29136BDB200A626D007317BE /* FixedRefreshControl.swift in Sources */,
2980033E1F51E93500BE90F4 /* RatingSectionController.swift in Sources */,
29FF85A51EE1EA7A007B8762 /* ReactionContent+ReactionType.swift in Sources */,
296A4960210E7B9A00BBBF2B /* IssueDetailBadgeView.swift in Sources */,
292FCB1D1EDFCD3D0026635E /* ReactionViewModel.swift in Sources */,
29DAA7AF20202BEA0029277A /* PullRequestReviewReplyModel.swift in Sources */,
29B94E691FCB36A000715D7E /* File+ListDiffable.swift in Sources */,
Expand Down Expand Up @@ -3003,6 +3010,7 @@
DCA5ED121FAEE3AE0072F074 /* Store.swift in Sources */,
29973E561F68BFDE0004B693 /* Signature.swift in Sources */,
2971722D1F069E96005E43AC /* SpinnerCell.swift in Sources */,
296A4962210E7E0E00BBBF2B /* CheckIfSentWithGitHawk.swift in Sources */,
29B94E6F1FCB743900715D7E /* RepositoryFileCell.swift in Sources */,
29459A711FE7153500034A04 /* LogEnvironmentInformation.swift in Sources */,
49AF91B4204B4B6A00DFF325 /* MergeHelper.swift in Sources */,
Expand Down
22 changes: 22 additions & 0 deletions Resources/Assets.xcassets/githawk-badge.imageset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"images" : [
{
"idiom" : "universal",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "githawk-badge@2x.png",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "githawk-badge@3x.png",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.