Respond to CR.

pull/1/head
Matthew Chen 8 years ago
parent 4de4a4b229
commit 55916e84c2

@ -215,7 +215,12 @@ class MessageDetailViewController: OWSViewController, MediaGalleryDataSourceDele
let messageRecipientIds = outgoingMessage.recipientIds() let messageRecipientIds = outgoingMessage.recipientIds()
for recipientId in messageRecipientIds { for recipientId in messageRecipientIds {
let (recipientStatus, shortStatusMessage, _) = MessageRecipientStatusUtils.recipientStatusAndStatusMessage(outgoingMessage: outgoingMessage, recipientId: recipientId, referenceView: self.view) guard let recipientState = outgoingMessage.recipientState(forRecipientId: recipientId) else {
owsFail("\(self.logTag) no message status for recipient: \(recipientId).")
continue
}
let (recipientStatus, shortStatusMessage, _) = MessageRecipientStatusUtils.recipientStatusAndStatusMessage(outgoingMessage: outgoingMessage, recipientState: recipientState, referenceView: self.view)
guard recipientStatus == recipientStatusGroup else { guard recipientStatus == recipientStatusGroup else {
continue continue

@ -16,61 +16,46 @@ import SignalMessaging
case skipped case skipped
} }
class MessageRecipientStatusUtils: NSObject { @objc
public class MessageRecipientStatusUtils: NSObject {
// MARK: Initializers // MARK: Initializers
@available(*, unavailable, message:"do not instantiate this class.") @available(*, unavailable, message:"do not instantiate this class.")
private override init() { private override init() {
} }
// This method is per-recipient and "biased towards success". class func recipientStatus(outgoingMessage: TSOutgoingMessage,
// See comments above. recipientState: TSOutgoingMessageRecipientState,
public class func recipientStatus(outgoingMessage: TSOutgoingMessage,
recipientId: String,
referenceView: UIView) -> MessageRecipientStatus { referenceView: UIView) -> MessageRecipientStatus {
let (messageRecipientStatus, _, _) = recipientStatusAndStatusMessage(outgoingMessage: outgoingMessage, let (messageRecipientStatus, _, _) = recipientStatusAndStatusMessage(outgoingMessage: outgoingMessage,
recipientId: recipientId, recipientState: recipientState,
referenceView: referenceView) referenceView: referenceView)
return messageRecipientStatus return messageRecipientStatus
} }
// This method is per-recipient and "biased towards success". @objc
// See comments above.
public class func shortStatusMessage(outgoingMessage: TSOutgoingMessage, public class func shortStatusMessage(outgoingMessage: TSOutgoingMessage,
recipientId: String, recipientState: TSOutgoingMessageRecipientState,
referenceView: UIView) -> String { referenceView: UIView) -> String {
let (_, shortStatusMessage, _) = recipientStatusAndStatusMessage(outgoingMessage: outgoingMessage, let (_, shortStatusMessage, _) = recipientStatusAndStatusMessage(outgoingMessage: outgoingMessage,
recipientId: recipientId, recipientState: recipientState,
referenceView: referenceView) referenceView: referenceView)
return shortStatusMessage return shortStatusMessage
} }
// This method is per-recipient and "biased towards success". @objc
// See comments above.
public class func longStatusMessage(outgoingMessage: TSOutgoingMessage, public class func longStatusMessage(outgoingMessage: TSOutgoingMessage,
recipientId: String, recipientState: TSOutgoingMessageRecipientState,
referenceView: UIView) -> String { referenceView: UIView) -> String {
let (_, _, longStatusMessage) = recipientStatusAndStatusMessage(outgoingMessage: outgoingMessage, let (_, _, longStatusMessage) = recipientStatusAndStatusMessage(outgoingMessage: outgoingMessage,
recipientId: recipientId, recipientState: recipientState,
referenceView: referenceView) referenceView: referenceView)
return longStatusMessage return longStatusMessage
} }
// This method is per-recipient and "biased towards success". class func recipientStatusAndStatusMessage(outgoingMessage: TSOutgoingMessage,
// See comments above. recipientState: TSOutgoingMessageRecipientState,
public class func recipientStatusAndStatusMessage(outgoingMessage: TSOutgoingMessage,
recipientId: String,
referenceView: UIView) -> (status: MessageRecipientStatus, shortStatusMessage: String, longStatusMessage: String) { referenceView: UIView) -> (status: MessageRecipientStatus, shortStatusMessage: String, longStatusMessage: String) {
// Legacy messages don't have "recipient read" state or "per-recipient delivery" state,
// so we fall back to `TSOutgoingMessageState` which is not per-recipient and therefore
// might be misleading.
guard let recipientState = outgoingMessage.recipientState(forRecipientId: recipientId) else {
owsFail("\(self.logTag) no message status for recipient: \(recipientId).")
let shortStatusMessage = NSLocalizedString("MESSAGE_STATUS_FAILED_SHORT", comment: "status message for failed messages")
let longStatusMessage = NSLocalizedString("MESSAGE_STATUS_FAILED", comment: "message footer for failed messages")
return (status:.failed, shortStatusMessage:shortStatusMessage, longStatusMessage:longStatusMessage)
}
switch recipientState.state { switch recipientState.state {
case .failed: case .failed:
@ -156,7 +141,7 @@ class MessageRecipientStatusUtils: NSObject {
// This method is per-message and "biased towards failure". // This method is per-message and "biased towards failure".
// See comments above. // See comments above.
public class func recipientStatus(outgoingMessage: TSOutgoingMessage) -> MessageRecipientStatus { class func recipientStatus(outgoingMessage: TSOutgoingMessage) -> MessageRecipientStatus {
switch outgoingMessage.messageState { switch outgoingMessage.messageState {
case .failed: case .failed:
return .failed return .failed

Loading…
Cancel
Save