Partially implement feedback
This commit is contained in:
parent
294d44c773
commit
7b0e2d06b0
|
@ -568,6 +568,7 @@
|
|||
B82584A02315024B001B41CB /* RSSFeedPoller.swift in Sources */ = {isa = PBXBuildFile; fileRef = B825849F2315024B001B41CB /* RSSFeedPoller.swift */; };
|
||||
B846365B22B7418B00AF1514 /* Identicon+ObjC.swift in Sources */ = {isa = PBXBuildFile; fileRef = B846365A22B7418B00AF1514 /* Identicon+ObjC.swift */; };
|
||||
B84664F5235022F30083A1CD /* MentionUtilities.swift in Sources */ = {isa = PBXBuildFile; fileRef = B84664F4235022F30083A1CD /* MentionUtilities.swift */; };
|
||||
B84664F923541F070083A1CD /* DisplayNameUtilities.swift in Sources */ = {isa = PBXBuildFile; fileRef = B84664F823541F070083A1CD /* DisplayNameUtilities.swift */; };
|
||||
B86BD08123399883000F5AE3 /* QRCodeModal.swift in Sources */ = {isa = PBXBuildFile; fileRef = B86BD08023399883000F5AE3 /* QRCodeModal.swift */; };
|
||||
B86BD08423399ACF000F5AE3 /* Modal.swift in Sources */ = {isa = PBXBuildFile; fileRef = B86BD08323399ACF000F5AE3 /* Modal.swift */; };
|
||||
B86BD08623399CEF000F5AE3 /* SeedModal.swift in Sources */ = {isa = PBXBuildFile; fileRef = B86BD08523399CEF000F5AE3 /* SeedModal.swift */; };
|
||||
|
@ -1380,6 +1381,7 @@
|
|||
B825849F2315024B001B41CB /* RSSFeedPoller.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RSSFeedPoller.swift; sourceTree = "<group>"; };
|
||||
B846365A22B7418B00AF1514 /* Identicon+ObjC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Identicon+ObjC.swift"; sourceTree = "<group>"; };
|
||||
B84664F4235022F30083A1CD /* MentionUtilities.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MentionUtilities.swift; sourceTree = "<group>"; };
|
||||
B84664F823541F070083A1CD /* DisplayNameUtilities.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DisplayNameUtilities.swift; sourceTree = "<group>"; };
|
||||
B86BD08023399883000F5AE3 /* QRCodeModal.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = QRCodeModal.swift; sourceTree = "<group>"; };
|
||||
B86BD08323399ACF000F5AE3 /* Modal.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Modal.swift; sourceTree = "<group>"; };
|
||||
B86BD08523399CEF000F5AE3 /* SeedModal.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SeedModal.swift; sourceTree = "<group>"; };
|
||||
|
@ -2671,6 +2673,7 @@
|
|||
B846365A22B7418B00AF1514 /* Identicon+ObjC.swift */,
|
||||
241C6312231F5F1D00B4198E /* CGFloat+Rounding.swift */,
|
||||
241C6310231F5C4400B4198E /* UIColor+Helper.swift */,
|
||||
B84664F823541F070083A1CD /* DisplayNameUtilities.swift */,
|
||||
);
|
||||
path = Loki;
|
||||
sourceTree = "<group>";
|
||||
|
@ -3575,6 +3578,7 @@
|
|||
450998681FD8C0FF00D89EB3 /* AttachmentSharing.m in Sources */,
|
||||
347850711FDAEB17007B8332 /* OWSUserProfile.m in Sources */,
|
||||
346129F81FD5F31400532771 /* OWS100RemoveTSRecipientsMigration.m in Sources */,
|
||||
B84664F923541F070083A1CD /* DisplayNameUtilities.swift in Sources */,
|
||||
34AC09DF211B39B100997B47 /* OWSNavigationController.m in Sources */,
|
||||
34074F61203D0CBE004596AE /* OWSSounds.m in Sources */,
|
||||
34BEDB1721C80BCA007B0EAE /* OWSAnyTouchGestureRecognizer.m in Sources */,
|
||||
|
|
|
@ -83,11 +83,12 @@ final class NewPublicChatVC : OWSViewController {
|
|||
return showError(title: NSLocalizedString("Invalid URL", comment: ""), message: NSLocalizedString("Please check the URL you entered and try again.", comment: ""))
|
||||
}
|
||||
updateAddButton(isConnecting: true)
|
||||
let channelID: UInt64 = 1
|
||||
let urlAsString = url.absoluteString
|
||||
let displayName = OWSProfileManager.shared().localProfileName()
|
||||
LokiPublicChatManager.shared.addChat(server: urlAsString, channel: 1)
|
||||
LokiPublicChatManager.shared.addChat(server: urlAsString, channel: channelID)
|
||||
.done(on: .main) { [weak self] _ in
|
||||
let _ = LokiGroupChatAPI.getMessages(for: 1, on: urlAsString)
|
||||
let _ = LokiGroupChatAPI.getMessages(for: channelID, on: urlAsString)
|
||||
let _ = LokiGroupChatAPI.setDisplayName(to: displayName, on: urlAsString)
|
||||
self?.presentingViewController!.dismiss(animated: true, completion: nil)
|
||||
}
|
||||
|
|
|
@ -4,21 +4,21 @@ public final class MentionUtilities : NSObject {
|
|||
|
||||
override private init() { }
|
||||
|
||||
@objc public static func highlightMentions(in string: String, thread: TSThread) -> String {
|
||||
return highlightMentions(in: string, isOutgoingMessage: false, thread: thread, attributes: [:]).string // isOutgoingMessage and attributes are irrelevant
|
||||
@objc public static func highlightMentions(in string: String, threadID: String) -> String {
|
||||
return highlightMentions(in: string, isOutgoingMessage: false, threadID: threadID, attributes: [:]).string // isOutgoingMessage and attributes are irrelevant
|
||||
}
|
||||
|
||||
@objc public static func highlightMentions(in string: String, isOutgoingMessage: Bool, thread: TSThread, attributes: [NSAttributedString.Key:Any]) -> NSAttributedString {
|
||||
@objc public static func highlightMentions(in string: String, isOutgoingMessage: Bool, threadID: String, attributes: [NSAttributedString.Key:Any]) -> NSAttributedString {
|
||||
var groupChat: LokiGroupChat?
|
||||
OWSPrimaryStorage.shared().dbReadConnection.read { transaction in
|
||||
groupChat = LokiDatabaseUtilities.objc_getGroupChat(for: thread.uniqueId!, in: transaction)
|
||||
groupChat = LokiDatabaseUtilities.getGroupChat(for: threadID, in: transaction)
|
||||
}
|
||||
var string = string
|
||||
let regex = try! NSRegularExpression(pattern: "@[0-9a-fA-F]*", options: [])
|
||||
let knownUserHexEncodedPublicKeys = LokiAPI.userHexEncodedPublicKeyCache[thread.uniqueId!] ?? [] // Should always be populated at this point
|
||||
let knownUserHexEncodedPublicKeys = LokiAPI.userHexEncodedPublicKeyCache[threadID] ?? [] // Should always be populated at this point
|
||||
var mentions: [NSRange] = []
|
||||
var outerMatch = regex.firstMatch(in: string, options: .withoutAnchoringBounds, range: NSRange(location: 0, length: string.count))
|
||||
while let match = outerMatch, thread.isGroupThread() {
|
||||
while let match = outerMatch {
|
||||
let hexEncodedPublicKey = String((string as NSString).substring(with: match.range).dropFirst()) // Drop the @
|
||||
let matchEnd: Int
|
||||
if knownUserHexEncodedPublicKeys.contains(hexEncodedPublicKey) {
|
||||
|
@ -27,12 +27,9 @@ public final class MentionUtilities : NSObject {
|
|||
userDisplayName = OWSProfileManager.shared().localProfileName()
|
||||
} else {
|
||||
if let groupChat = groupChat {
|
||||
OWSPrimaryStorage.shared().dbReadConnection.read { transaction in
|
||||
let collection = "\(groupChat.server).\(groupChat.channel)"
|
||||
userDisplayName = transaction.object(forKey: hexEncodedPublicKey, inCollection: collection) as! String?
|
||||
}
|
||||
userDisplayName = DisplayNameUtilities.getGroupChatDisplayName(for: hexEncodedPublicKey, in: groupChat.channel, on: groupChat.server)
|
||||
} else {
|
||||
userDisplayName = nil // TODO: Implement
|
||||
userDisplayName = DisplayNameUtilities.getPrivateChatDisplayName(for: hexEncodedPublicKey)
|
||||
}
|
||||
}
|
||||
if let userDisplayName = userDisplayName {
|
||||
|
|
|
@ -303,13 +303,10 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
[OWSPrimaryStorage.sharedManager.dbReadConnection readWithBlock:^(YapDatabaseReadTransaction *transaction) {
|
||||
groupChat = [LKDatabaseUtilities getGroupChatForThreadID:self.viewItem.interaction.uniqueThreadId transaction: transaction];
|
||||
}];
|
||||
|
||||
if (groupChat != nil) {
|
||||
BOOL isModerator = [LKGroupChatAPI isUserModerator:incomingMessage.authorId forGroup:groupChat.channel onServer:groupChat.server];
|
||||
UIImage *moderatorIcon = [UIImage imageNamed:@"Crown"];
|
||||
self.moderatorIconImageView.image = moderatorIcon;
|
||||
self.moderatorIconImageView.hidden = !isModerator;
|
||||
}
|
||||
BOOL isModerator = [LKGroupChatAPI isUserModerator:incomingMessage.authorId forGroup:groupChat.channel onServer:groupChat.server];
|
||||
UIImage *moderatorIcon = [UIImage imageNamed:@"Crown"];
|
||||
self.moderatorIconImageView.image = moderatorIcon;
|
||||
self.moderatorIconImageView.hidden = !isModerator;
|
||||
}
|
||||
|
||||
[self.contentView addSubview:self.moderatorIconImageView];
|
||||
|
|
|
@ -554,11 +554,11 @@ const CGFloat kRemotelySourcedContentRowSpacing = 3;
|
|||
|
||||
if (quotedAuthor == self.quotedMessage.authorId) {
|
||||
[OWSPrimaryStorage.sharedManager.dbReadConnection readWithBlock:^(YapDatabaseReadTransaction *transaction) {
|
||||
LKGroupChat *chat = [LKDatabaseUtilities getGroupChatForThreadID:self.quotedMessage.threadId transaction:transaction];
|
||||
if (chat != nil) {
|
||||
NSString *collection = [NSString stringWithFormat:@"%@.%@", chat.server, @(chat.channel)];
|
||||
NSString *displayName = [transaction stringForKey:self.quotedMessage.authorId inCollection:collection];
|
||||
if (displayName != nil) { quotedAuthor = displayName; }
|
||||
LKGroupChat *groupChat = [LKDatabaseUtilities getGroupChatForThreadID:self.quotedMessage.threadId transaction:transaction];
|
||||
if (groupChat != nil) {
|
||||
quotedAuthor = [LKDisplayNameUtilities getGroupChatDisplayNameFor:self.quotedMessage.authorId in:groupChat.channel on:groupChat.server using:transaction];;
|
||||
} else {
|
||||
quotedAuthor = [LKDisplayNameUtilities getPrivateChatDisplayNameFor:self.quotedMessage.authorId];
|
||||
}
|
||||
}];
|
||||
}
|
||||
|
|
|
@ -1262,7 +1262,7 @@ NSString *NSStringForOWSMessageCellType(OWSMessageCellType cellType)
|
|||
TSMessage *message = (TSMessage *)self.interaction;
|
||||
if (!message.isGroupChatMessage) return false;
|
||||
|
||||
// Make sure we have the details to contact the server
|
||||
// Ensure we have the details needed to contact the server
|
||||
__block LKGroupChat *groupChat;
|
||||
[self.primaryStorage.dbReadConnection readWithBlock:^(YapDatabaseReadTransaction *transaction) {
|
||||
groupChat = [LKDatabaseUtilities getGroupChatForThreadID:groupThread.uniqueId transaction: transaction];
|
||||
|
|
|
@ -2016,7 +2016,7 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
transaction:transaction
|
||||
conversationStyle:conversationStyle];
|
||||
quotedMessage = [
|
||||
[OWSQuotedReplyModel quotedReplyForSendingWithConversationViewItem:viewItem threadId:viewItem.interaction.uniqueThreadId transaction:transaction]
|
||||
[OWSQuotedReplyModel quotedReplyForSendingWithConversationViewItem:viewItem threadId:viewItem.interaction.uniqueThreadId transaction:transaction]
|
||||
buildQuotedMessageForSending];
|
||||
} else {
|
||||
TSOutgoingMessage *_Nullable messageToQuote = [self createFakeOutgoingMessage:thread
|
||||
|
|
|
@ -787,21 +787,15 @@ typedef NS_ENUM(NSInteger, HomeViewControllerSection) {
|
|||
self.navigationItem.leftBarButtonItem = settingsButton;
|
||||
SET_SUBVIEW_ACCESSIBILITY_IDENTIFIER(self, settingsButton);
|
||||
|
||||
UIBarButtonItem *newConversation = [[UIBarButtonItem alloc]
|
||||
UIBarButtonItem *newPrivateChatButton = [[UIBarButtonItem alloc]
|
||||
initWithBarButtonSystemItem:UIBarButtonSystemItemCompose
|
||||
target:self
|
||||
action:@selector(showNewConversationView)
|
||||
action:@selector(showNewConversationVC)
|
||||
accessibilityIdentifier:ACCESSIBILITY_IDENTIFIER_WITH_NAME(self, @"compose")];
|
||||
|
||||
UIBarButtonItem *newServer = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd
|
||||
target:self
|
||||
action:@selector(showNewPublicChatView)
|
||||
accessibilityIdentifier:ACCESSIBILITY_IDENTIFIER_WITH_NAME(self, @"addServer")];
|
||||
UIBarButtonItem *newGroupChatButton = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"group-avatar"] style:UIBarButtonItemStylePlain target:self action:@selector(showNewPublicChatVC)];
|
||||
|
||||
self.navigationItem.rightBarButtonItems = @[
|
||||
newConversation,
|
||||
newServer,
|
||||
];
|
||||
self.navigationItem.rightBarButtonItems = @[ newPrivateChatButton, newGroupChatButton ];
|
||||
}
|
||||
|
||||
- (void)settingsButtonPressed:(id)sender
|
||||
|
@ -843,7 +837,7 @@ typedef NS_ENUM(NSInteger, HomeViewControllerSection) {
|
|||
[self.navigationController pushViewController:vc animated:NO];
|
||||
}
|
||||
|
||||
- (void)showNewConversationView
|
||||
- (void)showNewConversationVC
|
||||
{
|
||||
LKNewConversationVC *newConversationVC = [LKNewConversationVC new];
|
||||
OWSNavigationController *navigationController = [[OWSNavigationController alloc] initWithRootViewController:newConversationVC];
|
||||
|
@ -871,7 +865,7 @@ typedef NS_ENUM(NSInteger, HomeViewControllerSection) {
|
|||
*/
|
||||
}
|
||||
|
||||
- (void)showNewPublicChatView
|
||||
- (void)showNewPublicChatVC
|
||||
{
|
||||
LKNewPublicChatVC *newPublicChatVC = [LKNewPublicChatVC new];
|
||||
OWSNavigationController *navigationController = [[OWSNavigationController alloc] initWithRootViewController:newPublicChatVC];
|
||||
|
|
|
@ -2552,7 +2552,6 @@
|
|||
"Password (Optional)" = "Password (Optional)";
|
||||
"Next" = "Next";
|
||||
"Add" = "Add";
|
||||
"Connecting to server" = "Connecting to server...";
|
||||
"Please save the seed below in a safe location. It can be used to restore your account if you lose access, or to migrate to a new device." = "Please save the seed below in a safe location. It can be used to restore your account if you lose access, or to migrate to a new device.";
|
||||
"Restore your account by entering your seed below." = "Restore your account by entering your seed below.";
|
||||
"Copy" = "Copy";
|
||||
|
@ -2571,7 +2570,6 @@
|
|||
"Start a Conversation" = "Start a Conversation";
|
||||
"Invalid public key" = "Invalid public key";
|
||||
"No search results" = "No search results";
|
||||
"Failed to connect to server" = "Failed to connect to server";
|
||||
"Calculating proof of work" = "Calculating proof of work";
|
||||
"Failed to calculate proof of work." = "Failed to calculate proof of work.";
|
||||
"Share Public Key" = "Share Public Key";
|
||||
|
@ -2648,5 +2646,4 @@
|
|||
"Enter a URL" = "Enter a URL";
|
||||
"Enter the URL of the public chat you'd like to join. The Loki Public Chat URL is https://chat.lokinet.org." = "Enter the URL of the public chat you'd like to join. The Loki Public Chat URL is https://chat.lokinet.org.";
|
||||
"Connecting..." = "Connecting...";
|
||||
"Add" = "Add";
|
||||
"Couldn't Connect" = "Couldn't Connect";
|
||||
|
|
|
@ -0,0 +1,39 @@
|
|||
|
||||
@objc(LKDisplayNameUtilities)
|
||||
public final class DisplayNameUtilities : NSObject {
|
||||
|
||||
override private init() { }
|
||||
|
||||
private static var userHexEncodedPublicKey: String {
|
||||
return OWSIdentityManager.shared().identityKeyPair()!.hexEncodedPublicKey
|
||||
}
|
||||
|
||||
private static var userDisplayName: String? {
|
||||
return OWSProfileManager.shared().localProfileName()
|
||||
}
|
||||
|
||||
@objc public static func getPrivateChatDisplayName(for hexEncodedPublicKey: String) -> String? {
|
||||
if hexEncodedPublicKey == userHexEncodedPublicKey {
|
||||
return userDisplayName
|
||||
} else {
|
||||
return OWSProfileManager.shared().profileName(forRecipientId: hexEncodedPublicKey)
|
||||
}
|
||||
}
|
||||
|
||||
@objc public static func getGroupChatDisplayName(for hexEncodedPublicKey: String, in channel: UInt64, on server: String) -> String? {
|
||||
var result: String?
|
||||
OWSPrimaryStorage.shared().dbReadConnection.read { transaction in
|
||||
result = getGroupChatDisplayName(for: hexEncodedPublicKey, in: channel, on: server, using: transaction)
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
@objc public static func getGroupChatDisplayName(for hexEncodedPublicKey: String, in channel: UInt64, on server: String, using transaction: YapDatabaseReadTransaction) -> String? {
|
||||
if hexEncodedPublicKey == userHexEncodedPublicKey {
|
||||
return userDisplayName
|
||||
} else {
|
||||
let collection = "\(server).\(channel)"
|
||||
return transaction.object(forKey: hexEncodedPublicKey, inCollection: collection) as! String?
|
||||
}
|
||||
}
|
||||
}
|
|
@ -51,10 +51,8 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
- (TSQuotedMessage *)buildQuotedMessageForSending;
|
||||
|
||||
// Loki
|
||||
|
||||
@property (nonatomic, readonly) NSString *threadId;
|
||||
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
|
|
|
@ -167,7 +167,7 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
}
|
||||
}
|
||||
|
||||
# pragma mark Loki - Upgrading to public chat manager
|
||||
# pragma mark Loki - Upgrading to Public Chat Manager
|
||||
|
||||
// Versions less than or equal to 1.2.0 didn't store group chat mappings
|
||||
+ (void)updatePublicChatMapping
|
||||
|
|
|
@ -535,13 +535,15 @@ typedef void (^ProfileManagerFailureBlock)(NSError *error);
|
|||
OWSAssertDebug(successBlock);
|
||||
OWSAssertDebug(failureBlock);
|
||||
|
||||
__block NSDictionary *chats;
|
||||
[SSKEnvironment.shared.primaryStorage.dbReadConnection readWithBlock:^(YapDatabaseReadTransaction * _Nonnull transaction) {
|
||||
chats = [LKDatabaseUtilities getAllGroupChats:transaction];
|
||||
__block NSDictionary *groupChats;
|
||||
[SSKEnvironment.shared.primaryStorage.dbReadConnection readWithBlock:^(YapDatabaseReadTransaction *transaction) {
|
||||
groupChats = [LKDatabaseUtilities getAllGroupChats:transaction];
|
||||
}];
|
||||
|
||||
for (LKGroupChat *chat in chats.allValues) {
|
||||
[[LKGroupChatAPI setDisplayName:localProfileName on:chat.server] retainUntilComplete];
|
||||
NSSet *servers = [NSSet setWithArray:[groupChats.allValues map:^NSString *(LKGroupChat *groupChat) { return groupChat.server; }]];
|
||||
|
||||
for (NSString *server in servers) {
|
||||
[[LKGroupChatAPI setDisplayName:localProfileName on:server] retainUntilComplete];
|
||||
}
|
||||
|
||||
successBlock();
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
|
||||
@objc(LKGroupChatPoller)
|
||||
public final class LokiGroupChatPoller : NSObject {
|
||||
public final class GroupChatPoller : NSObject {
|
||||
private let group: LokiGroupChat
|
||||
private var pollForNewMessagesTimer: Timer? = nil
|
||||
private var pollForDeletedMessagesTimer: Timer? = nil
|
||||
|
@ -50,7 +50,7 @@ public final class LokiGroupChatPoller : NSObject {
|
|||
let endIndex = senderHexEncodedPublicKey.endIndex
|
||||
let cutoffIndex = senderHexEncodedPublicKey.index(endIndex, offsetBy: -8)
|
||||
let senderDisplayName = "\(message.displayName) (...\(senderHexEncodedPublicKey[cutoffIndex..<endIndex]))"
|
||||
let id = group.idAsData!
|
||||
let id = group.idAsData
|
||||
let groupContext = SSKProtoGroupContext.builder(id: id, type: .deliver)
|
||||
groupContext.setName(group.displayName)
|
||||
let dataMessage = SSKProtoDataMessage.builder()
|
||||
|
@ -89,7 +89,7 @@ public final class LokiGroupChatPoller : NSObject {
|
|||
isDuplicate = id != nil
|
||||
}
|
||||
guard !isDuplicate else { return }
|
||||
guard let groupID = group.idAsData else { return }
|
||||
let groupID = group.idAsData
|
||||
let thread = TSGroupThread.getOrCreateThread(withGroupId: groupID)
|
||||
let signalQuote: TSQuotedMessage?
|
||||
if let quote = message.quote {
|
|
@ -1,26 +1,18 @@
|
|||
|
||||
@objc(LKGroupChat)
|
||||
public final class LokiGroupChat : NSObject, NSCoding {
|
||||
|
||||
@objc public static var defaultChats: [LokiGroupChat] {
|
||||
var chats = [LokiGroupChat(channel: UInt64(1), server: "https://chat.lokinet.org", displayName: NSLocalizedString("Loki Public Chat", comment: ""), isDeletable: true)]
|
||||
|
||||
#if DEBUG
|
||||
chats.append(LokiGroupChat(channel: UInt64(1), server: "https://chat-dev.lokinet.org", displayName: "Loki Dev Chat", isDeletable: true))
|
||||
#endif
|
||||
|
||||
return chats
|
||||
}
|
||||
|
||||
@objc public var id: String { return "\(server).\(channel)" }
|
||||
@objc public var idAsData: Data? { return id.data(using: .utf8) }
|
||||
|
||||
@objc public let id: String
|
||||
@objc public let idAsData: Data
|
||||
@objc public let channel: UInt64
|
||||
@objc public let server: String
|
||||
@objc public let displayName: String
|
||||
@objc public let isDeletable: Bool
|
||||
|
||||
@objc public init(channel: UInt64, server: String, displayName: String, isDeletable: Bool) {
|
||||
@objc public init?(channel: UInt64, server: String, displayName: String, isDeletable: Bool) {
|
||||
let id = "\(server).\(channel)"
|
||||
self.id = id
|
||||
guard let idAsData = id.data(using: .utf8) else { return nil }
|
||||
self.idAsData = idAsData
|
||||
self.channel = channel
|
||||
self.server = server.lowercased()
|
||||
self.displayName = displayName
|
||||
|
@ -28,10 +20,13 @@ public final class LokiGroupChat : NSObject, NSCoding {
|
|||
}
|
||||
|
||||
// MARK: Coding
|
||||
|
||||
@objc public init?(coder: NSCoder) {
|
||||
channel = UInt64(coder.decodeInt64(forKey: "channel"))
|
||||
server = coder.decodeObject(forKey: "server") as! String
|
||||
let id = "\(server).\(channel)"
|
||||
self.id = id
|
||||
guard let idAsData = id.data(using: .utf8) else { return nil }
|
||||
self.idAsData = idAsData
|
||||
displayName = coder.decodeObject(forKey: "displayName") as! String
|
||||
isDeletable = coder.decodeBool(forKey: "isDeletable")
|
||||
super.init()
|
||||
|
@ -44,5 +39,5 @@ public final class LokiGroupChat : NSObject, NSCoding {
|
|||
coder.encode(isDeletable, forKey: "isDeletable")
|
||||
}
|
||||
|
||||
override public var description: String { return "\(displayName) - \(server)" }
|
||||
override public var description: String { return "\(displayName) (\(server))" }
|
||||
}
|
||||
|
|
|
@ -223,7 +223,7 @@ public final class LokiGroupChatAPI : LokiDotNetAPI {
|
|||
}
|
||||
}
|
||||
|
||||
public static func getChannelInfo(_ channel: UInt64, on server: String) -> Promise<LokiPublicChannel> {
|
||||
public static func getChannelInfo(_ channel: UInt64, on server: String) -> Promise<String> {
|
||||
let url = URL(string: "\(server)/channels/\(channel)?include_annotations=1")!
|
||||
let request = TSRequest(url: url)
|
||||
return TSNetworkManager.shared().makePromise(request: request).map { $0.responseObject }.map { rawResponse in
|
||||
|
@ -236,7 +236,7 @@ public final class LokiGroupChatAPI : LokiDotNetAPI {
|
|||
print("[Loki] Couldn't parse info for group chat with ID: \(channel) on server: \(server) from: \(rawResponse).")
|
||||
throw Error.parsingFailed
|
||||
}
|
||||
return LokiPublicChannel(name: name)
|
||||
return name
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -11,7 +11,7 @@ public final class LokiPublicChatManager: NSObject {
|
|||
@objc public static let shared = LokiPublicChatManager()
|
||||
|
||||
private var chats: [String: LokiGroupChat] = [:]
|
||||
private var pollers: [String: LokiGroupChatPoller] = [:]
|
||||
private var pollers: [String: GroupChatPoller] = [:]
|
||||
private var isPolling = false
|
||||
|
||||
private let storage = OWSPrimaryStorage.shared()
|
||||
|
@ -32,7 +32,7 @@ public final class LokiPublicChatManager: NSObject {
|
|||
if let poller = pollers[threadID] {
|
||||
poller.startIfNeeded()
|
||||
} else {
|
||||
let poller = LokiGroupChatPoller(for: groupChat)
|
||||
let poller = GroupChatPoller(for: groupChat)
|
||||
poller.startIfNeeded()
|
||||
pollers[threadID] = poller
|
||||
}
|
||||
|
@ -53,7 +53,7 @@ public final class LokiPublicChatManager: NSObject {
|
|||
return LokiGroupChatAPI.getAuthToken(for: server).then { token in
|
||||
return LokiGroupChatAPI.getChannelInfo(channel, on: server)
|
||||
}.map { channelInfo -> LokiGroupChat in
|
||||
return self.addChat(server: server, channel: channel, name: channelInfo.name)
|
||||
return self.addChat(server: server, channel: channel, name: channelInfo)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -309,10 +309,19 @@ public final class LokiAPI : NSObject {
|
|||
guard let cache = userHexEncodedPublicKeyCache[threadID] else { return [] }
|
||||
var candidates: [Mention] = []
|
||||
// Gather candidates
|
||||
var groupChat: LokiGroupChat?
|
||||
OWSPrimaryStorage.shared().dbReadConnection.read { transaction in
|
||||
groupChat = LokiDatabaseUtilities.getGroupChat(for: threadID, in: transaction)
|
||||
}
|
||||
storage.dbReadConnection.read { transaction in
|
||||
let collection = "https://chat.lokinet.org.1" // FIXME: Mentions need to work for every kind of chat
|
||||
candidates = cache.flatMap { hexEncodedPublicKey in
|
||||
guard let displayName = transaction.object(forKey: hexEncodedPublicKey, inCollection: collection) as! String? else { return nil }
|
||||
let uncheckedDisplayName: String?
|
||||
if let groupChat = groupChat {
|
||||
uncheckedDisplayName = DisplayNameUtilities.getGroupChatDisplayName(for: hexEncodedPublicKey, in: groupChat.channel, on: groupChat.server)
|
||||
} else {
|
||||
uncheckedDisplayName = DisplayNameUtilities.getPrivateChatDisplayName(for: hexEncodedPublicKey)
|
||||
}
|
||||
guard let displayName = uncheckedDisplayName else { return nil }
|
||||
guard !displayName.hasPrefix("Anonymous") else { return nil }
|
||||
return Mention(hexEncodedPublicKey: hexEncodedPublicKey, displayName: displayName)
|
||||
}
|
||||
|
|
|
@ -26,12 +26,12 @@ public final class LokiDatabaseUtilities : NSObject {
|
|||
}
|
||||
|
||||
@objc(getAllGroupChats:)
|
||||
public static func objc_getAllGroupChats(in transaction: YapDatabaseReadTransaction) -> [String: LokiGroupChat] {
|
||||
public static func objc_getAllGroupChats(in transaction: YapDatabaseReadTransaction) -> [String:LokiGroupChat] {
|
||||
return OWSPrimaryStorage.shared().getAllGroupChats(with: transaction)
|
||||
}
|
||||
|
||||
@objc(getGroupChatForThreadID:transaction:)
|
||||
public static func objc_getGroupChat(for threadID: String, in transaction: YapDatabaseReadTransaction) -> LokiGroupChat? {
|
||||
public static func getGroupChat(for threadID: String, in transaction: YapDatabaseReadTransaction) -> LokiGroupChat? {
|
||||
return OWSPrimaryStorage.shared().getGroupChat(for: threadID, in: transaction)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue