Skip to content
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

Merged
merged 19 commits into from
Oct 15, 2019
Merged

Custom Public Chats #57

merged 19 commits into from
Oct 15, 2019

Conversation

Mikunj
Copy link

@Mikunj Mikunj commented Oct 9, 2019

No description provided.

@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!)
Copy link
Author

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];
Copy link
Author

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

Signal/src/Loki/NewPublicChatVC.swift Outdated Show resolved Hide resolved
} else {
self.moderatorIconImageView.hidden = YES;
}
BOOL isModerator = [LKGroupChatAPI isUserModerator:incomingMessage.authorId forGroup:groupChat.channel onServer:groupChat.server];
Copy link
Author

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

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?

Copy link
Author

@Mikunj Mikunj Oct 14, 2019

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.

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

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

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

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
Copy link
Author

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?

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

navigationItem.leftBarButtonItem = UIBarButtonItem(barButtonSystemItem: .stop, target: self, action: #selector(close))
title = NSLocalizedString("Add Public Chat Server", comment: "")
// Separator
let separator = UIView()

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,

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) {

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: ""))

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)

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)" }

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) }

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 {

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

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];

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) {

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

@@ -1620,8 +1595,7 @@ - (void)createRSSFeedPollersIfNeeded

- (void)startGroupChatPollersIfNeeded
{
[self createGroupChatPollersIfNeeded];
if (self.lokiPublicChatPoller != nil) { [self.lokiPublicChatPoller startIfNeeded]; }
[LKPublicChatManager.shared startPollersIfNeeded];

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

@nielsandriesse nielsandriesse changed the title Custom Public Servers Custom Public Chats Oct 15, 2019
@nielsandriesse nielsandriesse merged commit dcca0cc into dev Oct 15, 2019
@nielsandriesse nielsandriesse deleted the custom-server branch October 15, 2019 00:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants