session-ios/SessionMessagingKit/Open Groups/Models/SendMessageRequest.swift
Morgan Pretty dbead5e3c8 Got the '/inbox' APIs and encryption/decryption/validation working
Added a few types to make the code more readable
Added the inbox request to the polling
Added a couple of properties to the TSContactThread to indicate the originating open group to support SOGS DMs
Added code to store the latest message id for an open group inbox
Added a bunch of documentation from the API docs into the OpenGroupAPI (and associated models)
Updated the OpenGroupAPI to match the latest docs
Fixed the incorrect structure of the SendDirectMessageRequest
Fixed an incorrect inbox endpoint path
Tweaked the batch response handling so it wouldn't fail to parse all responses if a single one failed
Renamed IdPrefix to SessionId.Prefix and cleaned up the type to be more readable & self-documenting
2022-02-25 11:59:29 +11:00

74 lines
3.1 KiB
Swift

// Copyright © 2022 Rangeproof Pty Ltd. All rights reserved.
import Foundation
extension OpenGroupAPI {
public struct SendMessageRequest: Codable {
enum CodingKeys: String, CodingKey {
case data
case signature
case whisperTo = "whisper_to"
case whisperMods = "whisper_mods"
case fileIds = "files"
}
/// The serialized message body (encoded in base64 when encoding)
let data: Data
/// A 64-byte Ed25519 signature of the message body, signed by the current user's keys (encoded in base64 when
/// encoding - ie. 88 base64 chars)
let signature: Data
/// If present this indicates that this message is a whisper that should only be shown to the given user (via their sessionId)
let whisperTo: String?
/// If `true`, then this message will be visible to moderators but not ordinary users
///
/// If this and `whisper_to` are used together then the message will be visible to the given user and any room
/// moderators (this can be used, for instance, to issue a warning to a user that only the user and other mods can see)
///
/// **Note:** Only moderators may set this flag
let whisperMods: Bool?
/// Array of file IDs of new files uploaded as attachments of this post
///
/// This is required to preserve uploads for the default expiry period (15 days, unless otherwise configured by the SOGS
/// administrator); uploaded files that are not attached to a post will be deleted much sooner
///
/// If any of the given file ids are already associated with another message then the association is ignored (i.e. the files remain
/// associated with the original message)
///
/// When submitting a message edit this field must contain the IDs of any newly uploaded files that are part of the edit; existing
/// attachment IDs may also be included, but are not required
let fileIds: [Int64]?
// MARK: - Initialization
init(
data: Data,
signature: Data,
whisperTo: String? = nil,
whisperMods: Bool? = nil,
fileIds: [Int64]? = nil
) {
self.data = data
self.signature = signature
self.whisperTo = whisperTo
self.whisperMods = whisperMods
self.fileIds = fileIds
}
// MARK: - Encodable
public func encode(to encoder: Encoder) throws {
var container: KeyedEncodingContainer<CodingKeys> = encoder.container(keyedBy: CodingKeys.self)
try container.encode(data.base64EncodedString(), forKey: .data)
try container.encode(signature.base64EncodedString(), forKey: .signature)
try container.encodeIfPresent(whisperTo, forKey: .whisperTo)
try container.encodeIfPresent(whisperMods, forKey: .whisperMods)
try container.encodeIfPresent(fileIds, forKey: .fileIds)
}
}
}