|
|
|
|
@ -13,6 +13,21 @@ import Foundation
|
|
|
|
|
case failed
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Our per-recipient status messages are "biased towards success"
|
|
|
|
|
// and reflect the most successful known state for that recipient.
|
|
|
|
|
//
|
|
|
|
|
// Our per-message status messages are "biased towards failure"
|
|
|
|
|
// and reflect the least successful known state for that message.
|
|
|
|
|
//
|
|
|
|
|
// Why?
|
|
|
|
|
//
|
|
|
|
|
// When showing the per-recipient status, we want to show the message
|
|
|
|
|
// as "read" even if delivery failed to another recipient of the same
|
|
|
|
|
// message.
|
|
|
|
|
//
|
|
|
|
|
// When showing the per-message status, we want to show the message
|
|
|
|
|
// as "failed" if delivery failed to any recipient, even if another
|
|
|
|
|
// receipient has read the message.
|
|
|
|
|
class MessageRecipientStatusUtils: NSObject {
|
|
|
|
|
// MARK: Initializers
|
|
|
|
|
|
|
|
|
|
@ -20,6 +35,8 @@ class MessageRecipientStatusUtils: NSObject {
|
|
|
|
|
private override init() {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// This method is per-recipient and "biased towards success".
|
|
|
|
|
// See comments above.
|
|
|
|
|
public class func recipientStatus(outgoingMessage: TSOutgoingMessage,
|
|
|
|
|
recipientId: String,
|
|
|
|
|
referenceView: UIView) -> MessageRecipientStatus {
|
|
|
|
|
@ -29,6 +46,8 @@ class MessageRecipientStatusUtils: NSObject {
|
|
|
|
|
return messageRecipientStatus
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// This method is per-recipient and "biased towards success".
|
|
|
|
|
// See comments above.
|
|
|
|
|
public class func statusMessage(outgoingMessage: TSOutgoingMessage,
|
|
|
|
|
recipientId: String,
|
|
|
|
|
referenceView: UIView) -> String {
|
|
|
|
|
@ -38,6 +57,8 @@ class MessageRecipientStatusUtils: NSObject {
|
|
|
|
|
return statusMessage
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// This method is per-recipient and "biased towards success".
|
|
|
|
|
// See comments above.
|
|
|
|
|
public class func recipientStatusAndStatusMessage(outgoingMessage: TSOutgoingMessage,
|
|
|
|
|
recipientId: String,
|
|
|
|
|
referenceView: UIView) -> (MessageRecipientStatus, String) {
|
|
|
|
|
@ -94,9 +115,27 @@ class MessageRecipientStatusUtils: NSObject {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// This method is per-message and "biased towards failure".
|
|
|
|
|
// See comments above.
|
|
|
|
|
public class func statusMessage(outgoingMessage: TSOutgoingMessage,
|
|
|
|
|
referenceView: UIView) -> String {
|
|
|
|
|
|
|
|
|
|
if outgoingMessage.messageState == .unsent {
|
|
|
|
|
return NSLocalizedString("MESSAGE_STATUS_FAILED", comment:"message footer for failed messages")
|
|
|
|
|
} else if outgoingMessage.messageState == .attemptingOut {
|
|
|
|
|
if outgoingMessage.hasAttachments() {
|
|
|
|
|
assert(outgoingMessage.messageState == .attemptingOut)
|
|
|
|
|
|
|
|
|
|
return NSLocalizedString("MESSAGE_STATUS_UPLOADING",
|
|
|
|
|
comment:"message footer while attachment is uploading")
|
|
|
|
|
} else {
|
|
|
|
|
assert(outgoingMessage.messageState == .attemptingOut)
|
|
|
|
|
|
|
|
|
|
return NSLocalizedString("MESSAGE_STATUS_SENDING",
|
|
|
|
|
comment:"message status while message is sending.")
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let recipientReadMap = outgoingMessage.recipientReadMap
|
|
|
|
|
if recipientReadMap.count > 0 {
|
|
|
|
|
assert(outgoingMessage.messageState == .sentToService)
|
|
|
|
|
@ -115,28 +154,29 @@ class MessageRecipientStatusUtils: NSObject {
|
|
|
|
|
comment:"message status for message delivered to their recipient.")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if outgoingMessage.messageState == .unsent {
|
|
|
|
|
return NSLocalizedString("MESSAGE_STATUS_FAILED", comment:"message footer for failed messages")
|
|
|
|
|
} else if outgoingMessage.messageState == .sentToService {
|
|
|
|
|
return NSLocalizedString("MESSAGE_STATUS_SENT",
|
|
|
|
|
comment:"message footer for sent messages")
|
|
|
|
|
} else if outgoingMessage.hasAttachments() {
|
|
|
|
|
assert(outgoingMessage.messageState == .attemptingOut)
|
|
|
|
|
|
|
|
|
|
return NSLocalizedString("MESSAGE_STATUS_UPLOADING",
|
|
|
|
|
comment:"message footer while attachment is uploading")
|
|
|
|
|
} else {
|
|
|
|
|
assert(outgoingMessage.messageState == .attemptingOut)
|
|
|
|
|
|
|
|
|
|
return NSLocalizedString("MESSAGE_STATUS_SENDING",
|
|
|
|
|
comment:"message status while message is sending.")
|
|
|
|
|
}
|
|
|
|
|
return NSLocalizedString("MESSAGE_STATUS_SENT",
|
|
|
|
|
comment:"message footer for sent messages")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// This method is per-message and "biased towards failure".
|
|
|
|
|
// See comments above.
|
|
|
|
|
public class func recipientStatus(outgoingMessage: TSOutgoingMessage) -> MessageRecipientStatus {
|
|
|
|
|
if outgoingMessage.messageState == .unsent {
|
|
|
|
|
return .failed
|
|
|
|
|
} else if outgoingMessage.messageState == .attemptingOut {
|
|
|
|
|
if outgoingMessage.hasAttachments() {
|
|
|
|
|
assert(outgoingMessage.messageState == .attemptingOut)
|
|
|
|
|
return .uploading
|
|
|
|
|
} else {
|
|
|
|
|
assert(outgoingMessage.messageState == .attemptingOut)
|
|
|
|
|
return .sending
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
assert(outgoingMessage.messageState == .sentToService)
|
|
|
|
|
|
|
|
|
|
let recipientReadMap = outgoingMessage.recipientReadMap
|
|
|
|
|
if recipientReadMap.count > 0 {
|
|
|
|
|
assert(outgoingMessage.messageState == .sentToService)
|
|
|
|
|
return .read
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -149,16 +189,6 @@ class MessageRecipientStatusUtils: NSObject {
|
|
|
|
|
return .delivered
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if outgoingMessage.messageState == .unsent {
|
|
|
|
|
return .failed
|
|
|
|
|
} else if outgoingMessage.messageState == .sentToService {
|
|
|
|
|
return .sent
|
|
|
|
|
} else if outgoingMessage.hasAttachments() {
|
|
|
|
|
assert(outgoingMessage.messageState == .attemptingOut)
|
|
|
|
|
return .uploading
|
|
|
|
|
} else {
|
|
|
|
|
assert(outgoingMessage.messageState == .attemptingOut)
|
|
|
|
|
return .sending
|
|
|
|
|
}
|
|
|
|
|
return .sent
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|