Skip to content
This repository has been archived by the owner on Jun 7, 2020. It is now read-only.

[NEW] Support autocompletion in new composer #2224

Merged
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
2 changes: 1 addition & 1 deletion Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ CHECKOUT OPTIONS:
:commit: c34d9ccef689c55b9eae69f3c65283da8d8b0c6c
:git: https://github.com/RocketChat/RCMarkdownParser.git
RocketChatViewController:
:commit: 78c7a695512fb04ccbd4934b4e933c4512b012ab
:commit: a7b926a7e490776b43d3f27d699618863e3bc573
:git: https://github.com/RocketChat/RocketChatViewController
SimpleImageViewer:
:commit: 8222c338de0f285ca0c2d556c5d8dedd4a365b52
Expand Down
2 changes: 1 addition & 1 deletion Pods/Manifest.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions Rocket.Chat.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,6 @@
41BFA0AA2146D23D008B9611 /* MessageManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 41BFA0A82146D23C008B9611 /* MessageManager.swift */; };
41BFA0AB2146D23D008B9611 /* MessageManagerSystemMessages.swift in Sources */ = {isa = PBXBuildFile; fileRef = 41BFA0A92146D23C008B9611 /* MessageManagerSystemMessages.swift */; };
41C275DF1D848005003C88CF /* AvatarView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 41C275DE1D848005003C88CF /* AvatarView.swift */; };
41C275E11D84815C003C88CF /* AvatarView.xib in Resources */ = {isa = PBXBuildFile; fileRef = 41C275E01D84815C003C88CF /* AvatarView.xib */; };
41C45AEF1DFAD42800D9969C /* ChatDataController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 41C45AEE1DFAD42800D9969C /* ChatDataController.swift */; };
41C955FA20A3931C00FC8314 /* ChatMessageActionButtonsView.xib in Resources */ = {isa = PBXBuildFile; fileRef = 41F3705320A3917D00C5449E /* ChatMessageActionButtonsView.xib */; };
41C955FC20A3937A00FC8314 /* ChatMessageActionButtonsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 41C955FB20A3937A00FC8314 /* ChatMessageActionButtonsView.swift */; };
Expand Down Expand Up @@ -654,6 +653,7 @@
80CC8A1920ACE320009D64DF /* UserPermissions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 80CC8A1820ACE320009D64DF /* UserPermissions.swift */; };
80CC8A1B20ACEA6A009D64DF /* ChatControllerUserActionPresenter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 80CC8A1A20ACEA6A009D64DF /* ChatControllerUserActionPresenter.swift */; };
80CCD3B7215EA992002AFE83 /* MessagesViewControllerComposerDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 80CCD3B6215EA992002AFE83 /* MessagesViewControllerComposerDelegate.swift */; };
80CCD3BC216235B1002AFE83 /* MessagesComposerViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 80CCD3BB216235B1002AFE83 /* MessagesComposerViewModel.swift */; };
80D0CE5C204FFAA50056B17F /* SEServerCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 80D0CE5B204FFAA50056B17F /* SEServerCell.xib */; };
80D0CE60205016B40056B17F /* SEServerCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 80D0CE5F205016B40056B17F /* SEServerCell.swift */; };
80D0CE62205023710056B17F /* SECell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 80D0CE61205023710056B17F /* SECell.swift */; };
Expand Down Expand Up @@ -1200,7 +1200,6 @@
41BFA0A82146D23C008B9611 /* MessageManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = MessageManager.swift; path = Rocket.Chat/Managers/Model/MessageManager/MessageManager.swift; sourceTree = SOURCE_ROOT; };
41BFA0A92146D23C008B9611 /* MessageManagerSystemMessages.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = MessageManagerSystemMessages.swift; path = Rocket.Chat/Managers/Model/MessageManager/MessageManagerSystemMessages.swift; sourceTree = SOURCE_ROOT; };
41C275DE1D848005003C88CF /* AvatarView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AvatarView.swift; sourceTree = "<group>"; };
41C275E01D84815C003C88CF /* AvatarView.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = AvatarView.xib; sourceTree = "<group>"; };
41C45AEE1DFAD42800D9969C /* ChatDataController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ChatDataController.swift; sourceTree = "<group>"; };
41C955FB20A3937A00FC8314 /* ChatMessageActionButtonsView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ChatMessageActionButtonsView.swift; sourceTree = "<group>"; };
41CABFF71F5047D600E0B289 /* ChatLoaderCell.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = ChatLoaderCell.xib; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1524,6 +1523,7 @@
80CC8A1820ACE320009D64DF /* UserPermissions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UserPermissions.swift; sourceTree = "<group>"; };
80CC8A1A20ACEA6A009D64DF /* ChatControllerUserActionPresenter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChatControllerUserActionPresenter.swift; sourceTree = "<group>"; };
80CCD3B6215EA992002AFE83 /* MessagesViewControllerComposerDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MessagesViewControllerComposerDelegate.swift; sourceTree = "<group>"; };
80CCD3BB216235B1002AFE83 /* MessagesComposerViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MessagesComposerViewModel.swift; sourceTree = "<group>"; };
80D0CE5B204FFAA50056B17F /* SEServerCell.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = SEServerCell.xib; sourceTree = "<group>"; };
80D0CE5F205016B40056B17F /* SEServerCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SEServerCell.swift; sourceTree = "<group>"; };
80D0CE61205023710056B17F /* SECell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SECell.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -2645,7 +2645,6 @@
isa = PBXGroup;
children = (
41C275DE1D848005003C88CF /* AvatarView.swift */,
41C275E01D84815C003C88CF /* AvatarView.xib */,
);
path = Avatar;
sourceTree = "<group>";
Expand Down Expand Up @@ -2791,6 +2790,7 @@
41BF4D6B215B47AD00588B35 /* MessagesSubscriptionViewModel.swift */,
41FB7137215B0FD6002B5187 /* MessagesSizingManager.swift */,
80CCD3B6215EA992002AFE83 /* MessagesViewControllerComposerDelegate.swift */,
80CCD3BB216235B1002AFE83 /* MessagesComposerViewModel.swift */,
);
path = Chat;
sourceTree = "<group>";
Expand Down Expand Up @@ -4055,7 +4055,6 @@
14F8A224202E5CBF00175FDC /* Black-60@3x.png in Resources */,
14F8A23F202E5D0600175FDC /* Red-29@2x.png in Resources */,
412BCC851E55C6A300F7F4EE /* ChatMessageTextView.xib in Resources */,
41C275E11D84815C003C88CF /* AvatarView.xib in Resources */,
14F8A261202E64B200175FDC /* BnW-76@3x.png in Resources */,
41FC9E0E209B44CD00FED485 /* ChatLoaderCell.xib in Resources */,
809B53121FE2F2F900833DD2 /* ReactionView.xib in Resources */,
Expand Down Expand Up @@ -4776,6 +4775,7 @@
33D08E2420BD5EDC008D03EF /* ThemeableViewControllers.swift in Sources */,
35BCD301201A57EA00B4BE5A /* Ask.swift in Sources */,
33D08E3120BD92A5008D03EF /* ThemePreferenceCell.swift in Sources */,
80CCD3BC216235B1002AFE83 /* MessagesComposerViewModel.swift in Sources */,
992B5AB6209A14B5009C8123 /* AudioFileViewController.swift in Sources */,
8041C0402028C7A1007E21FA /* ReactorListViewController.swift in Sources */,
8039443020B34B12002F317A /* DirectoryRequest.swift in Sources */,
Expand Down
69 changes: 69 additions & 0 deletions Rocket.Chat/Controllers/Chat/MessagesComposerViewModel.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
//
// MessagesComposerViewModel.swift
// Rocket.Chat
//
// Created by Matheus Cardoso on 10/1/18.
// Copyright © 2018 Rocket.Chat. All rights reserved.
//

import Foundation
import RealmSwift

final class MessagesComposerViewModel {
let hintPrefixes: [Character] = ["/", "#", "@", ":"]

var hints: [String] = []
var hintPrefixedWord: String = ""

func didChangeHintPrefixedWord(word: String, realm: Realm? = Realm.current) {
hints = []
hintPrefixedWord = word

guard
let realm = realm,
let prefix = hintPrefixedWord.first
else {
return
}

let word = String(word.dropFirst())

if prefix == "@" {
hints = User.search(usernameContaining: word, preference: []).map { $0.0 }

if "here".contains(word) || word.count == 0 {
hints.append("here")
}

if "all".contains(word) || word.count == 0 {
hints.append("all")
}
} else if prefix == "#" {
let filter = "auth != nil && (privateType == 'c' || privateType == 'p')\(word.isEmpty ? "" : "&& name BEGINSWITH[c] %@")"

let channels = realm.objects(Subscription.self).filter(filter, word)

for channel in channels {
hints.append(channel.name)
}

} else if prefix == "/" {
let commands: Results<Command>
if word.count > 0 {
commands = realm.objects(Command.self).filter("command BEGINSWITH[c] %@", word)
} else {
commands = realm.objects(Command.self)
}

commands.forEach {
hints.append($0.command)
}
} else if prefix == ":" {
let emojis = EmojiSearcher.standard.search(shortname: word.lowercased(), custom: CustomEmoji.emojis())

emojis.forEach {
hints.append($0.suggestion)
}
}
}
}
1 change: 1 addition & 0 deletions Rocket.Chat/Controllers/Chat/MessagesViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ final class MessagesViewController: RocketChatViewController {
let viewModel = MessagesViewModel(controllerContext: nil)
let viewSubscriptionModel = MessagesSubscriptionViewModel()
let viewSizingModel = MessagesSizingManager()
let composerViewModel = MessagesComposerViewModel()

var subscription: Subscription! {
didSet {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
//

import RocketChatViewController
import RealmSwift

extension MessagesViewController: ComposerViewExpandedDelegate {
func viewModel(for replyView: ReplyView) -> ReplyViewModel {
Expand All @@ -24,27 +25,54 @@ extension MessagesViewController: ComposerViewExpandedDelegate {
// MARK: Hints

func composerView(_ composerView: ComposerView, didChangeHintPrefixedWord word: String) {
return
composerViewModel.didChangeHintPrefixedWord(word: word)
}

func hintPrefixes(for composerView: ComposerView) -> [Character] {
return ["/", "#", "@", ":"]
return composerViewModel.hintPrefixes
}

func isHinting(in composerView: ComposerView) -> Bool {
return false
return composerViewModel.hints.count > 0
}

func numberOfHints(in hintsView: HintsView) -> Int {
return 0
return composerViewModel.hints.count
}

func hintsView(_ hintsView: HintsView, cellForHintAt index: Int) -> UITableViewCell {
fatalError("not implemented yet")
let hint = composerViewModel.hints[index]

if composerViewModel.hintPrefixedWord.first == "@", let user = User.find(username: hint) {
let cell = hintsView.dequeueReusableCell(withType: UserHintCell<AvatarView>.self)

cell.avatarView.user = user
cell.usernameLabel.text = hint
cell.nameLabel.text = user.name

return cell
}

let cell = hintsView.dequeueReusableCell(withType: TextHintCell.self)
cell.prefixLabel.text = String(composerViewModel.hintPrefixedWord.first ?? " ")
cell.valueLabel.text = String(hint)
return cell
}

func hintsView(_ hintsView: HintsView, didSelectHintAt index: Int) {
return
if let range = composerView.textView.rangeOfNearestWordToSelection {
let oldWord = composerView.textView.text[range]
let newWord = (oldWord.first?.description ?? "") + composerViewModel.hints[index]
composerView.textView.text = composerView.textView.text.replacingCharacters(in: range, with: newWord)
}

composerViewModel.hints = []

UIView.animate(withDuration: 0.2) {
hintsView.reloadData()
hintsView.invalidateIntrinsicContentSize()
hintsView.layoutIfNeeded()
}
}

// MARK: EditingView
Expand Down
1 change: 0 additions & 1 deletion Rocket.Chat/Controllers/Chat/MessagesViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,6 @@ final class MessagesViewModel {

return sameUser && Int(date.timeIntervalSince(prevDate)) < timeLimit
}

}

extension MessagesViewModel {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,17 @@ final class PreferencesViewController: BaseTableViewController {
@IBOutlet weak var avatarViewContainer: UIView! {
didSet {
avatarViewContainer.layer.cornerRadius = 4
if let avatarView = AvatarView.instantiateFromNib() {
avatarView.frame = avatarViewContainer.bounds
avatarViewContainer.addSubview(avatarView)
self.avatarView = avatarView
}
avatarView.frame = avatarViewContainer.bounds
avatarViewContainer.addSubview(avatarView)
}
}

weak var avatarView: AvatarView! {
didSet {
avatarView.layer.cornerRadius = 4
avatarView.layer.masksToBounds = true
}
}
lazy var avatarView: AvatarView = {
let avatarView = AvatarView()
avatarView.layer.cornerRadius = 4
avatarView.layer.masksToBounds = true
return avatarView
}()

@IBOutlet weak var labelProfileName: UILabel!
@IBOutlet weak var labelProfileStatus: UILabel!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ final class EditProfileTableViewController: BaseTableViewController, MediaPicker
@IBOutlet weak var avatarButton: UIButton!

var avatarView: AvatarView = {
guard let avatarView = AvatarView.instantiateFromNib() else { return AvatarView() }
let avatarView = AvatarView()
avatarView.isUserInteractionEnabled = false
avatarView.translatesAutoresizingMaskIntoConstraints = false
avatarView.layer.cornerRadius = 15
Expand Down
Loading