mirror of
https://github.com/oxen-io/session-ios.git
synced 2023-12-13 21:30:14 +01:00
Make basic message sending work
This commit is contained in:
parent
4f3448d75d
commit
30370bf4d2
|
@ -213,7 +213,7 @@ public class NotificationPresenter: NSObject, NotificationsProtocol {
|
|||
// for more details.
|
||||
let messageText = DisplayableText.filterNotificationText(rawMessageText)
|
||||
|
||||
let senderName = SSKEnvironment.shared.profileManager.profileNameForRecipient(withID: incomingMessage.authorId, avoidingWriteTransaction: true)!
|
||||
let senderName = SSKEnvironment.shared.profileManager.profileNameForRecipient(withID: incomingMessage.authorId, avoidingWriteTransaction: true) ?? incomingMessage.authorId
|
||||
|
||||
let notificationTitle: String?
|
||||
switch previewType {
|
||||
|
|
|
@ -3823,25 +3823,17 @@ typedef enum : NSUInteger {
|
|||
return;
|
||||
}
|
||||
|
||||
// Limit outgoing text messages to 16kb.
|
||||
//
|
||||
// We convert large text messages to attachments
|
||||
// which are presented as normal text messages.
|
||||
SNVisibleMessage *message = [SNVisibleMessage new];
|
||||
message.text = text;
|
||||
[LKStorage writeWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
[SNMessageSender send:message inThread:self.thread usingTransaction:transaction];
|
||||
}];
|
||||
|
||||
// TODO TODO TODO
|
||||
TSOutgoingMessage *tsMessage = [TSOutgoingMessage from:message associatedWith:self.thread];
|
||||
|
||||
// BOOL didAddToProfileWhitelist = [ThreadUtil addThreadToProfileWhitelistIfEmptyContactThread:self.thread];
|
||||
__block TSOutgoingMessage *message;
|
||||
// [self.uiDatabaseConnection readWithBlock:^(YapDatabaseReadTransaction *_Nonnull transaction) {
|
||||
// message = [ThreadUtil enqueueMessageWithText:text
|
||||
// inThread:self.thread
|
||||
// quotedReplyModel:self.inputToolbar.quotedReply
|
||||
// linkPreviewDraft:self.inputToolbar.linkPreviewDraft
|
||||
// transaction:transaction];
|
||||
// }];
|
||||
// [self.conversationViewModel appendUnsavedOutgoingTextMessage:message];
|
||||
[self.conversationViewModel appendUnsavedOutgoingTextMessage:tsMessage];
|
||||
|
||||
[self messageWasSent:message];
|
||||
[self messageWasSent:tsMessage];
|
||||
|
||||
// Clearing the text message is a key part of the send animation.
|
||||
// It takes 10-15ms, but we do it inline rather than dispatch async
|
||||
|
@ -3867,12 +3859,6 @@ typedef enum : NSUInteger {
|
|||
[LKStorage writeWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
[self.thread setDraft:@"" transaction:transaction];
|
||||
}];
|
||||
|
||||
if ([self.thread isKindOfClass:TSContactThread.class]) {
|
||||
[LKStorage writeWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
[LKSessionManagementProtocol sendSessionRequestIfNeededToPublicKey:self.thread.contactIdentifier transaction:transaction];
|
||||
}];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)voiceMemoGestureDidStart
|
||||
|
|
|
@ -2,7 +2,8 @@ import PromiseKit
|
|||
import SessionSnodeKit
|
||||
import SessionUtilitiesKit
|
||||
|
||||
public enum MessageSender {
|
||||
@objc(SNMessageSender)
|
||||
public final class MessageSender : NSObject {
|
||||
|
||||
public enum Error : LocalizedError {
|
||||
case invalidMessage
|
||||
|
@ -20,6 +21,8 @@ public enum MessageSender {
|
|||
}
|
||||
}
|
||||
|
||||
private override init() { }
|
||||
|
||||
public static func send(_ message: Message, to destination: Message.Destination, using transaction: Any) -> Promise<Void> {
|
||||
switch destination {
|
||||
case .contact(_), .closedGroup(_): return sendToSnodeDestination(destination, message: message, using: transaction)
|
||||
|
|
|
@ -238,6 +238,7 @@
|
|||
B82B4090239DD75000A248E7 /* RestoreVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = B82B408F239DD75000A248E7 /* RestoreVC.swift */; };
|
||||
B82B4094239DF15900A248E7 /* ConversationTitleView.swift in Sources */ = {isa = PBXBuildFile; fileRef = B82B4093239DF15900A248E7 /* ConversationTitleView.swift */; };
|
||||
B83F2B88240CB75A000A54AB /* UIImage+Scaling.swift in Sources */ = {isa = PBXBuildFile; fileRef = B83F2B87240CB75A000A54AB /* UIImage+Scaling.swift */; };
|
||||
B84072962565E9F50037CB17 /* TSOutgoingMessage+Conversion.swift in Sources */ = {isa = PBXBuildFile; fileRef = B84072952565E9F50037CB17 /* TSOutgoingMessage+Conversion.swift */; };
|
||||
B84664F5235022F30083A1CD /* MentionUtilities.swift in Sources */ = {isa = PBXBuildFile; fileRef = B84664F4235022F30083A1CD /* MentionUtilities.swift */; };
|
||||
B85357BF23A1AE0800AAF6CD /* SeedReminderView.swift in Sources */ = {isa = PBXBuildFile; fileRef = B85357BE23A1AE0800AAF6CD /* SeedReminderView.swift */; };
|
||||
B85357C323A1BD1200AAF6CD /* SeedVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = B85357C223A1BD1200AAF6CD /* SeedVC.swift */; };
|
||||
|
@ -1344,6 +1345,7 @@
|
|||
B82B4093239DF15900A248E7 /* ConversationTitleView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConversationTitleView.swift; sourceTree = "<group>"; };
|
||||
B83F2B85240C7B8F000A54AB /* NewConversationButtonSet.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewConversationButtonSet.swift; sourceTree = "<group>"; };
|
||||
B83F2B87240CB75A000A54AB /* UIImage+Scaling.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIImage+Scaling.swift"; sourceTree = "<group>"; };
|
||||
B84072952565E9F50037CB17 /* TSOutgoingMessage+Conversion.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "TSOutgoingMessage+Conversion.swift"; sourceTree = "<group>"; };
|
||||
B84664F4235022F30083A1CD /* MentionUtilities.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MentionUtilities.swift; sourceTree = "<group>"; };
|
||||
B847570023D568EB00759540 /* SignalServiceKit.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = SignalServiceKit.framework; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
B85357BE23A1AE0800AAF6CD /* SeedReminderView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SeedReminderView.swift; sourceTree = "<group>"; };
|
||||
|
@ -3643,6 +3645,7 @@
|
|||
C38EF23A255B6D66007E1867 /* NSAttributedString+OWS.m */,
|
||||
C38EF237255B6D65007E1867 /* UIDevice+featureSupport.swift */,
|
||||
C3B7845C25649DA600ADB2E7 /* TSIncomingMessage+Conversion.swift */,
|
||||
B84072952565E9F50037CB17 /* TSOutgoingMessage+Conversion.swift */,
|
||||
);
|
||||
path = Utilities;
|
||||
sourceTree = "<group>";
|
||||
|
@ -4811,6 +4814,7 @@
|
|||
C33FDC41255A581F00E217F9 /* TypingIndicators.swift in Sources */,
|
||||
C33FDC7D255A582000E217F9 /* OWSDispatch.m in Sources */,
|
||||
C33FDC2E255A581F00E217F9 /* ClosedGroupsProtocol.swift in Sources */,
|
||||
B84072962565E9F50037CB17 /* TSOutgoingMessage+Conversion.swift in Sources */,
|
||||
C38EF247255B6D67007E1867 /* NSAttributedString+OWS.m in Sources */,
|
||||
C33FDC99255A582000E217F9 /* PublicChatManager.swift in Sources */,
|
||||
C33FDCB9255A582000E217F9 /* DisplayNameUtilities.swift in Sources */,
|
||||
|
|
|
@ -181,7 +181,7 @@ public class FullTextSearchFinder: NSObject {
|
|||
}
|
||||
|
||||
private static let recipientIndexer: SearchIndexer<String> = SearchIndexer { (recipientId: String, transaction: YapDatabaseReadTransaction) in
|
||||
let displayName = SSKEnvironment.shared.profileManager.profileNameForRecipient(withID: recipientId, avoidingWriteTransaction: true)!
|
||||
let displayName = SSKEnvironment.shared.profileManager.profileNameForRecipient(withID: recipientId, avoidingWriteTransaction: true) ?? recipientId
|
||||
|
||||
return "\(recipientId) \(displayName)"
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@ public extension Message.Destination {
|
|||
|
||||
static func from(_ thread: TSThread) -> Message.Destination {
|
||||
if let thread = thread as? TSContactThread {
|
||||
return .contact(publicKey: thread.uniqueId!)
|
||||
return .contact(publicKey: thread.contactIdentifier())
|
||||
} else if let thread = thread as? TSGroupThread, thread.usesSharedSenderKeys {
|
||||
let groupID = thread.groupModel.groupId
|
||||
let groupPublicKey = LKGroupUtilities.getDecodedGroupID(groupID)
|
||||
|
|
|
@ -2,6 +2,7 @@ import PromiseKit
|
|||
|
||||
public extension MessageSender {
|
||||
|
||||
@objc(send:inThread:usingTransaction:)
|
||||
static func send(_ message: Message, in thread: TSThread, using transaction: YapDatabaseReadWriteTransaction) {
|
||||
message.threadID = thread.uniqueId!
|
||||
let destination = Message.Destination.from(thread)
|
||||
|
@ -9,6 +10,11 @@ public extension MessageSender {
|
|||
SessionMessagingKit.JobQueue.shared.add(job, using: transaction)
|
||||
}
|
||||
|
||||
@objc(sendNonDurably:inThread:usingTransaction:)
|
||||
static func objc_sendNonDurably(_ message: Message, in thread: TSThread, using transaction: YapDatabaseReadWriteTransaction) -> AnyPromise {
|
||||
return AnyPromise.from(sendNonDurably(message, in: thread, using: transaction))
|
||||
}
|
||||
|
||||
static func sendNonDurably(_ message: Message, in thread: TSThread, using transaction: YapDatabaseReadWriteTransaction) -> Promise<Void> {
|
||||
message.threadID = thread.uniqueId!
|
||||
let destination = Message.Destination.from(thread)
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
|
||||
@objc public extension TSOutgoingMessage {
|
||||
|
||||
@objc(from:associatedWith:)
|
||||
static func from(_ visibleMessage: VisibleMessage, associatedWith thread: TSThread) -> TSOutgoingMessage {
|
||||
var expiration: UInt32 = 0
|
||||
if let disappearingMessagesConfiguration = OWSDisappearingMessagesConfiguration.fetch(uniqueId: thread.uniqueId!) {
|
||||
expiration = disappearingMessagesConfiguration.isEnabled ? disappearingMessagesConfiguration.durationSeconds : 0
|
||||
}
|
||||
return TSOutgoingMessage(
|
||||
in: thread,
|
||||
messageBody: visibleMessage.text,
|
||||
attachmentId: nil,
|
||||
expiresInSeconds: expiration,
|
||||
quotedMessage: nil,
|
||||
linkPreview: nil
|
||||
)
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue