-
Notifications
You must be signed in to change notification settings - Fork 85
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Custom Public Chats #57
Conversation
Minor refactor.
Added migrations.
…erver # Conflicts: # Signal.xcodeproj/project.pbxproj
@objc(addChatWithServer:channel:name:) | ||
public func addChat(server: String, channel: UInt64, name: String) -> LokiGroupChat { | ||
let chat = LokiGroupChat(channel: channel, server: server, displayName: name, isDeletable: true) | ||
let model = TSGroupModel(title: chat.displayName, memberIds: [ourHexEncodedPublicKey!, chat.server], image: nil, groupId: chat.idAsData!) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ourHexEncodedPublicKey!
might cause a crash
NSString *userDefaultsKey = [@"isGroupChatSetUp." stringByAppendingString:chat.id]; | ||
BOOL isChatSetUp = [NSUserDefaults.standardUserDefaults boolForKey:userDefaultsKey]; | ||
if (!isChatSetUp || !chat.isDeletable) { | ||
[LKPublicChatManager.shared addChatWithServer:chat.server channel:chat.channel name:chat.displayName]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to update the display name on the server
} else { | ||
self.moderatorIconImageView.hidden = YES; | ||
} | ||
BOOL isModerator = [LKGroupChatAPI isUserModerator:incomingMessage.authorId forGroup:groupChat.channel onServer:groupChat.server]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
groupChat
could be nil
here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not actually, right? Unless we made a mistake somewhere?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
getGroupChatForThreadID:
returns nil
if a group chat object doesn't exist. This may be the case for private group chats.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, yeah, it makes sense if you're thinking about private group chats already
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should get on the same page about public chats / private group chats / private chats
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LokiGroupChat
should really be LokiPublicChat
then
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll refactor this now so we don't get confused anymore
@objc public var id: String { return "\(server).\(channel)" } | ||
@objc public var idAsData: Data? { return id.data(using: .utf8) } | ||
|
||
@objc public let id: String |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why can't we let id
be a computed variable?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's something that doesn't (and shouldn't change). By making it a let
instead of a computed variable you reflect that. It's also slightly more efficient though in practice that's unlikely to matter
578d733
to
7b0e2d0
Compare
8b6cd4d
to
48883bf
Compare
navigationItem.leftBarButtonItem = UIBarButtonItem(barButtonSystemItem: .stop, target: self, action: #selector(close)) | ||
title = NSLocalizedString("Add Public Chat Server", comment: "") | ||
// Separator | ||
let separator = UIView() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This separator is never added as a subview
|
||
// Stack view | ||
let stackView = UIStackView(arrangedSubviews: [ | ||
serverUrlTextField, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
An explainer label would be nice
presentAlert(alert) | ||
} | ||
|
||
private func updateButton(enabled: Bool) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This shouldn't be under the interaction mark
|
||
private func updateButton(enabled: Bool) { | ||
addButton.setEnabled(enabled) | ||
addButton.setTitle(enabled ? NSLocalizedString("Add", comment: "") : NSLocalizedString("Connecting to server", comment: "")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These need to be localized
let addButtonFont = UIFont.ows_dynamicTypeBodyClamped.ows_mediumWeight() | ||
let addButtonHeight = addButtonFont.pointSize * 48 / 17 | ||
let addButton = OWSFlatButton.button(title: NSLocalizedString("Add", comment: ""), font: addButtonFont, titleColor: .white, backgroundColor: .lokiGreen(), target: self, selector: #selector(handleNextButtonTapped)) | ||
addButton.autoSetDimension(.height, toSize: addButtonHeight) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Convention is to not set up constraints here. The reason is that not all constraints can be set up at this point (the view needs to be added as a subview before some of them can be created), so the idea is to wait for that and then set up everything.
return chats | ||
} | ||
|
||
@objc public var id: String { return "\(server).\(channel)" } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can just compute these once and make these fields constant
} | ||
|
||
@objc public var id: String { return "\(server).\(channel)" } | ||
@objc public var idAsData: Data? { return id.data(using: .utf8) } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you use a failable initializer you can reflect the fact that this should either succeed or the whole chat shouldn't exist
@@ -1,6 +1,6 @@ | |||
|
|||
@objc(LKGroupChatPoller) | |||
public final class GroupChatPoller : NSObject { | |||
public final class LokiGroupChatPoller : NSObject { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's either move both this and RSSFeedPoller
to core or neither
@objc public var id: String { return "\(server).\(channel)" } | ||
@objc public var idAsData: Data? { return id.data(using: .utf8) } | ||
|
||
@objc public let id: String |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's something that doesn't (and shouldn't change). By making it a let
instead of a computed variable you reflect that. It's also slightly more efficient though in practice that's unlikely to matter
} else { | ||
self.moderatorIconImageView.hidden = YES; | ||
} | ||
BOOL isModerator = [LKGroupChatAPI isUserModerator:incomingMessage.authorId forGroup:groupChat.channel onServer:groupChat.server]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not actually, right? Unless we made a mistake somewhere?
} | ||
} | ||
|
||
public static func resetLastMessageCache(for group: UInt64, on server: String) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This also clears the last deletion cache
Signal/src/AppDelegate.m
Outdated
@@ -1620,8 +1595,7 @@ - (void)createRSSFeedPollersIfNeeded | |||
|
|||
- (void)startGroupChatPollersIfNeeded | |||
{ | |||
[self createGroupChatPollersIfNeeded]; | |||
if (self.lokiPublicChatPoller != nil) { [self.lokiPublicChatPoller startIfNeeded]; } | |||
[LKPublicChatManager.shared startPollersIfNeeded]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This makes the function redundant so let's remove it then
No description provided.