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

Commit 92cb228

Browse files
authored
Merge pull request #2514 from blewjy/new/support-announcements
[NEW] Support announcements
2 parents 842b292 + de54420 commit 92cb228

21 files changed

Lines changed: 142 additions & 2 deletions

File tree

Rocket.Chat.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -895,6 +895,7 @@
895895
D32E28251DFD86C300D6019C /* LauncherProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = D32E28221DFD86C300D6019C /* LauncherProtocol.swift */; };
896896
D32E28261DFD86C300D6019C /* PersistencyCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = D32E28231DFD86C300D6019C /* PersistencyCoordinator.swift */; };
897897
D3CFAFBD1E907D8900BADC0A /* ChatMessageTextViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = D3CFAFBC1E907D8900BADC0A /* ChatMessageTextViewModel.swift */; };
898+
DB926AFD21FA0AEE0046F53F /* ChatAnnouncementView.swift in Sources */ = {isa = PBXBuildFile; fileRef = DB926AFC21FA0AEE0046F53F /* ChatAnnouncementView.swift */; };
898899
/* End PBXBuildFile section */
899900

900901
/* Begin PBXContainerItemProxy section */
@@ -1848,6 +1849,7 @@
18481849
D32E28221DFD86C300D6019C /* LauncherProtocol.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LauncherProtocol.swift; sourceTree = "<group>"; };
18491850
D32E28231DFD86C300D6019C /* PersistencyCoordinator.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PersistencyCoordinator.swift; sourceTree = "<group>"; };
18501851
D3CFAFBC1E907D8900BADC0A /* ChatMessageTextViewModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ChatMessageTextViewModel.swift; sourceTree = "<group>"; };
1852+
DB926AFC21FA0AEE0046F53F /* ChatAnnouncementView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChatAnnouncementView.swift; sourceTree = "<group>"; };
18511853
E05A718A50D61E3E547007AF /* Pods-Rocket.Chat.test.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Rocket.Chat.test.xcconfig"; path = "Pods/Target Support Files/Pods-Rocket.Chat/Pods-Rocket.Chat.test.xcconfig"; sourceTree = "<group>"; };
18521854
F87E8221BEB77AF190F06201 /* Pods-Rocket.Chat.ShareExtension.beta.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Rocket.Chat.ShareExtension.beta.xcconfig"; path = "Pods/Target Support Files/Pods-Rocket.Chat.ShareExtension/Pods-Rocket.Chat.ShareExtension.beta.xcconfig"; sourceTree = "<group>"; };
18531855
FEDACA44BBB1C0633DEA6F3D /* Pods-Rocket.ChatTests.beta.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Rocket.ChatTests.beta.xcconfig"; path = "Pods/Target Support Files/Pods-Rocket.ChatTests/Pods-Rocket.ChatTests.beta.xcconfig"; sourceTree = "<group>"; };
@@ -3028,6 +3030,7 @@
30283030
411498E21FC7A99C00D66542 /* ChatTitleViewModel.swift */,
30293031
339B6929205042D300F97392 /* KeyboardFrameView.swift */,
30303032
1435BFA21F9B601600FB2768 /* RCTextView.swift */,
3033+
DB926AFC21FA0AEE0046F53F /* ChatAnnouncementView.swift */,
30313034
);
30323035
path = Chat;
30333036
sourceTree = "<group>";
@@ -4827,6 +4830,7 @@
48274830
4190694321D0E82F00FE2573 /* MessageVideoCallCell.swift in Sources */,
48284831
9987B5992093E526007D277C /* FileTableViewCell.swift in Sources */,
48294832
99BE4D8A2153162A001A43E2 /* UnmanagedMessage.swift in Sources */,
4833+
DB926AFD21FA0AEE0046F53F /* ChatAnnouncementView.swift in Sources */,
48304834
41FC9E0C209B3BAA00FED485 /* UploadMessageRequest.swift in Sources */,
48314835
800FCD501F728EC800D9A692 /* MemberCell.swift in Sources */,
48324836
997FE19C210BA5B8000F6836 /* SubscriptionHideRequest.swift in Sources */,

Rocket.Chat/Controllers/Chat/ChannelActionsViewController.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ class ChannelActionsViewController: BaseViewController {
3737
header = [ChannelInfoUserCellData(user: subscription.directMessageUser)]
3838
} else {
3939
let hasDescription = !(subscription.roomDescription?.isEmpty ?? true)
40+
let hasAnnouncement = !(subscription.roomAnnouncement?.isEmpty ?? true)
4041
let hasTopic = !(subscription.roomTopic?.isEmpty ?? true)
4142

4243
header = [
@@ -45,6 +46,12 @@ class ChannelActionsViewController: BaseViewController {
4546
title: localized("chat.info.item.description"),
4647
descriptionText: hasDescription ? subscription.roomDescription : localized("chat.info.item.no_description")
4748
),
49+
ChannelInfoDescriptionCellData(
50+
title: localized("chat.info.item.announcement"),
51+
descriptionText: hasAnnouncement ?
52+
subscription.roomAnnouncement :
53+
localized("chat.info.item.no_announcement")
54+
),
4855
ChannelInfoDescriptionCellData(
4956
title: localized("chat.info.item.topic"),
5057
descriptionText: hasTopic ? subscription.roomTopic : localized("chat.info.item.no_topic")

Rocket.Chat/Controllers/Chat/MessagesViewController.swift

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,12 @@ final class MessagesViewController: RocketChatViewController {
7979
}
8080
}
8181

82+
lazy var announcementBannerView: UIView = {
83+
let announcementBannerView = ChatAnnouncementView()
84+
announcementBannerView.subscription = subscription?.unmanaged
85+
return announcementBannerView
86+
}()
87+
8288
private let buttonScrollToBottomSize = CGFloat(70)
8389
var keyboardHeight: CGFloat = 0
8490
var buttonScrollToBottomConstraint: NSLayoutConstraint!
@@ -131,7 +137,7 @@ final class MessagesViewController: RocketChatViewController {
131137

132138
registerCells()
133139
setupScrollToBottom()
134-
140+
setupAnnouncementBanner()
135141
NotificationCenter.default.addObserver(
136142
self,
137143
selector: #selector(keyboardWillShow(_:)),
@@ -197,6 +203,7 @@ final class MessagesViewController: RocketChatViewController {
197203
super.viewDidAppear(animated)
198204
markAsRead()
199205
becomeFirstResponder()
206+
updateAnnouncementBanner()
200207
}
201208

202209
override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
@@ -274,6 +281,35 @@ final class MessagesViewController: RocketChatViewController {
274281
}
275282
}
276283

284+
// MARK: Announcement
285+
286+
func setupAnnouncementBanner() {
287+
// Start as invisible first, alpha will be set to 1 if a valid announcement is fetched
288+
announcementBannerView.alpha = 0
289+
290+
view.addSubview(announcementBannerView)
291+
view.bringSubviewToFront(announcementBannerView)
292+
NSLayoutConstraint.activate([
293+
announcementBannerView.topAnchor.constraint(equalTo: view.topAnchor),
294+
announcementBannerView.leftAnchor.constraint(equalTo: view.leftAnchor),
295+
announcementBannerView.rightAnchor.constraint(equalTo: view.rightAnchor),
296+
announcementBannerView.heightAnchor.constraint(equalToConstant: 50)
297+
])
298+
299+
announcementBannerView.applyTheme()
300+
}
301+
302+
func updateAnnouncementBanner() {
303+
guard let announcement = subscription?.unmanaged?.roomAnnouncement else { return }
304+
let hasAnnouncement = announcement == "" ? false : true
305+
306+
if hasAnnouncement {
307+
announcementBannerView.alpha = 1
308+
} else {
309+
announcementBannerView.alpha = 0
310+
}
311+
}
312+
277313
// MARK: Scroll to Bottom
278314

279315
func setupScrollToBottom() {

Rocket.Chat/Models/Mapping/SubscriptionModelMapping.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ extension Subscription: ModelMappeable {
9696

9797
func mapRoom(_ values: JSON, realm: Realm?) {
9898
self.roomDescription = values["description"].stringValue
99+
self.roomAnnouncement = values["announcement"].stringValue
99100
self.roomTopic = values["topic"].stringValue
100101

101102
if let broadcast = values["broadcast"].bool {

Rocket.Chat/Models/Subscription/Subscription.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ final class Subscription: BaseModel {
6767

6868
@objc dynamic var roomTopic: String?
6969
@objc dynamic var roomDescription: String?
70+
@objc dynamic var roomAnnouncement: String?
7071
@objc dynamic var roomReadOnly = false
7172
@objc dynamic var roomUpdatedAt: Date?
7273
@objc dynamic var roomLastMessage: Message?

Rocket.Chat/Models/Subscription/UnmanagedSubscription.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ struct UnmanagedSubscription: UnmanagedObject, Equatable {
2828
var lastSeen: Date?
2929
var roomTopic: String?
3030
var roomDescription: String?
31+
var roomAnnouncement: String?
3132
var roomReadOnly: Bool
3233
var roomUpdatedAt: Date?
3334
var roomLastMessage: Message?
@@ -82,6 +83,7 @@ extension UnmanagedSubscription {
8283
lastSeen = subscription.lastSeen
8384
roomTopic = subscription.roomTopic
8485
roomDescription = subscription.roomDescription
86+
roomAnnouncement = subscription.roomAnnouncement
8587
roomReadOnly = subscription.roomReadOnly
8688
roomUpdatedAt = subscription.roomUpdatedAt
8789
roomLastMessage = subscription.roomLastMessage

Rocket.Chat/Resources/cs.lproj/Localizable.strings

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,8 @@
301301
"chat.info.item.no_topic" = "Bez tématu";
302302
"chat.info.item.description" = "Popis";
303303
"chat.info.item.no_description" = "Žádný popis";
304+
"chat.info.item.announcement" = "Announcement"; // TODO
305+
"chat.info.item.no_announcement" = "No announcement"; // TODO
304306
"chat.info.item.notifications" = "Upozornění";
305307
"chat.info.item.members" = "Členové";
306308
"chat.info.item.pinned" = "Připnuto";

Rocket.Chat/Resources/de.lproj/Localizable.strings

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,8 @@
300300
"chat.info.item.no_topic" = "Ohne Thema";
301301
"chat.info.item.description" = "Beschreibung";
302302
"chat.info.item.no_description" = "Ohne Beschreibung";
303+
"chat.info.item.announcement" = "Announcement"; // TODO
304+
"chat.info.item.no_announcement" = "No announcement"; // TODO
303305
"chat.info.item.notifications" = "Benachrichtigungen";
304306
"chat.info.item.members" = "Teilnehmer";
305307
"chat.info.item.pinned" = "Angeheftet";

Rocket.Chat/Resources/el.lproj/Localizable.strings

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,8 @@
300300
"chat.info.item.no_topic" = "Όχι θέμα";
301301
"chat.info.item.description" = "Περιγραφή";
302302
"chat.info.item.no_description" = "Έλλειψη περιγραφής";
303+
"chat.info.item.announcement" = "Announcement"; // TODO
304+
"chat.info.item.no_announcement" = "No announcement"; // TODO
303305
"chat.info.item.notifications" = "Ειδοποιήσεις";
304306
"chat.info.item.members" = "Μέλη";
305307
"chat.info.item.pinned" = "Καρφιτσωμένα";

Rocket.Chat/Resources/en.lproj/Localizable.strings

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,8 @@
300300
"chat.info.item.no_topic" = "No topic";
301301
"chat.info.item.description" = "Description";
302302
"chat.info.item.no_description" = "No description";
303+
"chat.info.item.announcement" = "Announcement";
304+
"chat.info.item.no_announcement" = "No announcement";
303305
"chat.info.item.members" = "Members";
304306
"chat.info.item.pinned" = "Pinned";
305307
"chat.info.item.starred" = "Starred";

0 commit comments

Comments
 (0)