Respond to CR.

pull/1/head
Matthew Chen 7 years ago
parent 55916e84c2
commit 204d379603

@ -316,7 +316,7 @@ NS_ASSUME_NONNULL_BEGIN
if (!self.viewItem.shouldHideRecipientStatus || hasExpirationTimer) { if (!self.viewItem.shouldHideRecipientStatus || hasExpirationTimer) {
TSOutgoingMessage *outgoingMessage = (TSOutgoingMessage *)message; TSOutgoingMessage *outgoingMessage = (TSOutgoingMessage *)message;
NSString *statusMessage = NSString *statusMessage =
[MessageRecipientStatusUtils statusMessageWithOutgoingMessage:outgoingMessage referenceView:self]; [MessageRecipientStatusUtils receiptMessageWithOutgoingMessage:outgoingMessage referenceView:self];
attributedText = [[NSAttributedString alloc] initWithString:statusMessage attributes:@{}]; attributedText = [[NSAttributedString alloc] initWithString:statusMessage attributes:@{}];
} }
} else if (self.viewItem.isGroupThread) { } else if (self.viewItem.isGroupThread) {

@ -4651,7 +4651,7 @@ typedef enum : NSUInteger {
// Update the "shouldShowDate" property of the view items. // Update the "shouldShowDate" property of the view items.
OWSInteractionType lastInteractionType = OWSInteractionType_Unknown; OWSInteractionType lastInteractionType = OWSInteractionType_Unknown;
MessageRecipientStatus lastRecipientStatus = MessageRecipientStatusUploading; MessageReceiptStatus lastReceiptStatus = MessageReceiptStatusUploading;
NSString *_Nullable lastIncomingSenderId = nil; NSString *_Nullable lastIncomingSenderId = nil;
for (ConversationViewItem *viewItem in viewItems.reverseObjectEnumerator) { for (ConversationViewItem *viewItem in viewItems.reverseObjectEnumerator) {
BOOL shouldHideRecipientStatus = NO; BOOL shouldHideRecipientStatus = NO;
@ -4660,20 +4660,21 @@ typedef enum : NSUInteger {
if (interactionType == OWSInteractionType_OutgoingMessage) { if (interactionType == OWSInteractionType_OutgoingMessage) {
TSOutgoingMessage *outgoingMessage = (TSOutgoingMessage *)viewItem.interaction; TSOutgoingMessage *outgoingMessage = (TSOutgoingMessage *)viewItem.interaction;
MessageRecipientStatus recipientStatus = MessageReceiptStatus receiptStatus =
[MessageRecipientStatusUtils recipientStatusWithOutgoingMessage:outgoingMessage]; [MessageRecipientStatusUtils recipientStatusWithOutgoingMessage:outgoingMessage
referenceView:self.view];
if (outgoingMessage.messageState == TSOutgoingMessageStateFailed) { if (outgoingMessage.messageState == TSOutgoingMessageStateFailed) {
// always show "failed to send" status // always show "failed to send" status
shouldHideRecipientStatus = NO; shouldHideRecipientStatus = NO;
} else { } else {
shouldHideRecipientStatus shouldHideRecipientStatus
= (interactionType == lastInteractionType && recipientStatus == lastRecipientStatus); = (interactionType == lastInteractionType && receiptStatus == lastReceiptStatus);
} }
shouldHideBubbleTail = interactionType == lastInteractionType; shouldHideBubbleTail = interactionType == lastInteractionType;
lastRecipientStatus = recipientStatus; lastReceiptStatus = receiptStatus;
} else if (interactionType == OWSInteractionType_IncomingMessage) { } else if (interactionType == OWSInteractionType_IncomingMessage) {
TSIncomingMessage *incomingMessage = (TSIncomingMessage *)viewItem.interaction; TSIncomingMessage *incomingMessage = (TSIncomingMessage *)viewItem.interaction;
NSString *incomingSenderId = incomingMessage.authorId; NSString *incomingSenderId = incomingMessage.authorId;

@ -193,13 +193,14 @@ class MessageDetailViewController: OWSViewController, MediaGalleryDataSourceDele
let isGroupThread = thread.isGroupThread() let isGroupThread = thread.isGroupThread()
let recipientStatusGroups: [MessageRecipientStatus] = [ let recipientStatusGroups: [MessageReceiptStatus] = [
.read, .read,
.uploading, .uploading,
.delivered, .delivered,
.sent, .sent,
.sending, .sending,
.failed .failed,
.skipped
] ]
for recipientStatusGroup in recipientStatusGroups { for recipientStatusGroup in recipientStatusGroups {
var groupRows = [UIView]() var groupRows = [UIView]()
@ -548,8 +549,8 @@ class MessageDetailViewController: OWSViewController, MediaGalleryDataSourceDele
updateContent() updateContent()
} }
private func string(for messageRecipientStatus: MessageRecipientStatus) -> String { private func string(for messageReceiptStatus: MessageReceiptStatus) -> String {
switch messageRecipientStatus { switch messageReceiptStatus {
case .uploading: case .uploading:
return NSLocalizedString("MESSAGE_METADATA_VIEW_MESSAGE_STATUS_UPLOADING", return NSLocalizedString("MESSAGE_METADATA_VIEW_MESSAGE_STATUS_UPLOADING",
comment: "Status label for messages which are uploading.") comment: "Status label for messages which are uploading.")

@ -6,7 +6,7 @@ import Foundation
import SignalServiceKit import SignalServiceKit
import SignalMessaging import SignalMessaging
@objc enum MessageRecipientStatus: Int { @objc enum MessageReceiptStatus: Int {
case uploading case uploading
case sending case sending
case sent case sent
@ -24,15 +24,17 @@ public class MessageRecipientStatusUtils: NSObject {
private override init() { private override init() {
} }
// This method is per-recipient.
class func recipientStatus(outgoingMessage: TSOutgoingMessage, class func recipientStatus(outgoingMessage: TSOutgoingMessage,
recipientState: TSOutgoingMessageRecipientState, recipientState: TSOutgoingMessageRecipientState,
referenceView: UIView) -> MessageRecipientStatus { referenceView: UIView) -> MessageReceiptStatus {
let (messageRecipientStatus, _, _) = recipientStatusAndStatusMessage(outgoingMessage: outgoingMessage, let (messageReceiptStatus, _, _) = recipientStatusAndStatusMessage(outgoingMessage: outgoingMessage,
recipientState: recipientState, recipientState: recipientState,
referenceView: referenceView) referenceView: referenceView)
return messageRecipientStatus return messageReceiptStatus
} }
// This method is per-recipient.
@objc @objc
public class func shortStatusMessage(outgoingMessage: TSOutgoingMessage, public class func shortStatusMessage(outgoingMessage: TSOutgoingMessage,
recipientState: TSOutgoingMessageRecipientState, recipientState: TSOutgoingMessageRecipientState,
@ -43,6 +45,7 @@ public class MessageRecipientStatusUtils: NSObject {
return shortStatusMessage return shortStatusMessage
} }
// This method is per-recipient.
@objc @objc
public class func longStatusMessage(outgoingMessage: TSOutgoingMessage, public class func longStatusMessage(outgoingMessage: TSOutgoingMessage,
recipientState: TSOutgoingMessageRecipientState, recipientState: TSOutgoingMessageRecipientState,
@ -53,9 +56,10 @@ public class MessageRecipientStatusUtils: NSObject {
return longStatusMessage return longStatusMessage
} }
// This method is per-recipient.
class func recipientStatusAndStatusMessage(outgoingMessage: TSOutgoingMessage, class func recipientStatusAndStatusMessage(outgoingMessage: TSOutgoingMessage,
recipientState: TSOutgoingMessageRecipientState, recipientState: TSOutgoingMessageRecipientState,
referenceView: UIView) -> (status: MessageRecipientStatus, shortStatusMessage: String, longStatusMessage: String) { referenceView: UIView) -> (status: MessageReceiptStatus, shortStatusMessage: String, longStatusMessage: String) {
switch recipientState.state { switch recipientState.state {
case .failed: case .failed:
@ -105,65 +109,51 @@ public class MessageRecipientStatusUtils: NSObject {
} }
} }
// This method is per-message and "biased towards failure". // This method is per-message.
// See comments above. internal class func receiptStatusAndMessage(outgoingMessage: TSOutgoingMessage,
public class func statusMessage(outgoingMessage: TSOutgoingMessage, referenceView: UIView) -> (status: MessageReceiptStatus, message: String) {
referenceView: UIView) -> String {
switch outgoingMessage.messageState { switch outgoingMessage.messageState {
case .failed: case .failed:
// Use the "long" version of this message here. // Use the "long" version of this message here.
return NSLocalizedString("MESSAGE_STATUS_FAILED", comment: "message footer for failed messages") return (.failed, NSLocalizedString("MESSAGE_STATUS_FAILED", comment: "message footer for failed messages"))
case .sending: case .sending:
if outgoingMessage.hasAttachments() { if outgoingMessage.hasAttachments() {
return NSLocalizedString("MESSAGE_STATUS_UPLOADING", return (.uploading, NSLocalizedString("MESSAGE_STATUS_UPLOADING",
comment: "message footer while attachment is uploading") comment: "message footer while attachment is uploading"))
} else { } else {
return NSLocalizedString("MESSAGE_STATUS_SENDING", return (.sending, NSLocalizedString("MESSAGE_STATUS_SENDING",
comment: "message status while message is sending.") comment: "message status while message is sending."))
} }
case .sent: case .sent:
if outgoingMessage.readRecipientIds().count > 0 { if outgoingMessage.readRecipientIds().count > 0 {
return NSLocalizedString("MESSAGE_STATUS_READ", comment: "message footer for read messages") return (.read, NSLocalizedString("MESSAGE_STATUS_READ", comment: "message footer for read messages"))
} }
if outgoingMessage.deliveredRecipientIds().count > 0 { if outgoingMessage.deliveredRecipientIds().count > 0 {
return NSLocalizedString("MESSAGE_STATUS_DELIVERED", return (.delivered, NSLocalizedString("MESSAGE_STATUS_DELIVERED",
comment: "message status for message delivered to their recipient.") comment: "message status for message delivered to their recipient."))
} }
return NSLocalizedString("MESSAGE_STATUS_SENT", return (.sent, NSLocalizedString("MESSAGE_STATUS_SENT",
comment: "message footer for sent messages") comment: "message footer for sent messages"))
default: default:
owsFail("\(self.logTag) Message has unexpected status: \(outgoingMessage.messageState).") owsFail("\(self.logTag) Message has unexpected status: \(outgoingMessage.messageState).")
return NSLocalizedString("MESSAGE_STATUS_SENT", return (.sent, NSLocalizedString("MESSAGE_STATUS_SENT",
comment: "message footer for sent messages") comment: "message footer for sent messages"))
} }
} }
// This method is per-message and "biased towards failure". // This method is per-message.
// See comments above. public class func receiptMessage(outgoingMessage: TSOutgoingMessage,
class func recipientStatus(outgoingMessage: TSOutgoingMessage) -> MessageRecipientStatus { referenceView: UIView) -> String {
switch outgoingMessage.messageState { let (_, message ) = receiptStatusAndMessage(outgoingMessage: outgoingMessage,
case .failed: referenceView: referenceView)
return .failed return message
case .sending:
if outgoingMessage.hasAttachments() {
return .uploading
} else {
return .sending
}
case .sent:
if outgoingMessage.readRecipientIds().count > 0 {
return .read
}
if outgoingMessage.deliveredRecipientIds().count > 0 {
return .delivered
} }
return .sent // This method is per-message.
default: class func recipientStatus(outgoingMessage: TSOutgoingMessage, referenceView: UIView) -> MessageReceiptStatus {
owsFail("\(self.logTag) Message has unexpected status: \(outgoingMessage.messageState).") let (status, _ ) = receiptStatusAndMessage(outgoingMessage: outgoingMessage,
referenceView: referenceView)
return .sent return status
}
} }
} }

@ -213,7 +213,7 @@ typedef NS_ENUM(NSInteger, TSGroupMetaMessage) {
// This method is used to rewrite the recipient list with a single recipient. // This method is used to rewrite the recipient list with a single recipient.
// It is used to reply to a "group info request", which should only be // It is used to reply to a "group info request", which should only be
// delivered to the requestor. // delivered to the requestor.
- (void)updateWithSingleGroupRecipient:(NSString *)singleGroupRecipient - (void)updateWithSendingToSingleGroupRecipient:(NSString *)singleGroupRecipient
transaction:(YapDatabaseReadWriteTransaction *)transaction; transaction:(YapDatabaseReadWriteTransaction *)transaction;
// This method is used to record a successful "read" by one recipient. // This method is used to record a successful "read" by one recipient.

@ -271,7 +271,7 @@ NSString *const kTSOutgoingMessageSentRecipientAll = @"kTSOutgoingMessageSentRec
// New outgoing messages should immediately determine their // New outgoing messages should immediately determine their
// recipient list from current thread state. // recipient list from current thread state.
NSMutableDictionary<NSString *, TSOutgoingMessageRecipientState *> *recipientStateMap = [NSMutableDictionary new]; NSMutableDictionary<NSString *, TSOutgoingMessageRecipientState *> *recipientStateMap = [NSMutableDictionary new];
NSArray<NSString *> *recipientIds = [self.thread recipientIdentifiers]; NSArray<NSString *> *recipientIds = [thread recipientIdentifiers];
for (NSString *recipientId in recipientIds) { for (NSString *recipientId in recipientIds) {
TSOutgoingMessageRecipientState *recipientState = [TSOutgoingMessageRecipientState new]; TSOutgoingMessageRecipientState *recipientState = [TSOutgoingMessageRecipientState new];
recipientState.state = OWSOutgoingMessageRecipientStateSending; recipientState.state = OWSOutgoingMessageRecipientStateSending;
@ -565,6 +565,9 @@ NSString *const kTSOutgoingMessageSentRecipientAll = @"kTSOutgoingMessageSentRec
recipientId); recipientId);
return; return;
} }
if (recipientState.state != OWSOutgoingMessageRecipientStateSent) {
DDLogWarn(@"%@ marking unsent message as delivered.", self.logTag);
}
recipientState.state = OWSOutgoingMessageRecipientStateSent; recipientState.state = OWSOutgoingMessageRecipientStateSent;
recipientState.deliveryTimestamp = deliveryTimestamp; recipientState.deliveryTimestamp = deliveryTimestamp;
}]; }];
@ -587,6 +590,9 @@ NSString *const kTSOutgoingMessageSentRecipientAll = @"kTSOutgoingMessageSentRec
recipientId); recipientId);
return; return;
} }
if (recipientState.state != OWSOutgoingMessageRecipientStateSent) {
DDLogWarn(@"%@ marking unsent message as delivered.", self.logTag);
}
recipientState.state = OWSOutgoingMessageRecipientStateSent; recipientState.state = OWSOutgoingMessageRecipientStateSent;
recipientState.readTimestamp = @(readTimestamp); recipientState.readTimestamp = @(readTimestamp);
}]; }];
@ -609,7 +615,7 @@ NSString *const kTSOutgoingMessageSentRecipientAll = @"kTSOutgoingMessageSentRec
}]; }];
} }
- (void)updateWithSingleGroupRecipient:(NSString *)singleGroupRecipient - (void)updateWithSendingToSingleGroupRecipient:(NSString *)singleGroupRecipient
transaction:(YapDatabaseReadWriteTransaction *)transaction transaction:(YapDatabaseReadWriteTransaction *)transaction
{ {
OWSAssert(transaction); OWSAssert(transaction);

@ -891,7 +891,7 @@ NS_ASSUME_NONNULL_BEGIN
[TSOutgoingMessage outgoingMessageInThread:gThread groupMetaMessage:TSGroupMessageUpdate]; [TSOutgoingMessage outgoingMessageInThread:gThread groupMetaMessage:TSGroupMessageUpdate];
[message updateWithCustomMessage:updateGroupInfo transaction:transaction]; [message updateWithCustomMessage:updateGroupInfo transaction:transaction];
// Only send this group update to the requester. // Only send this group update to the requester.
[message updateWithSingleGroupRecipient:envelope.source transaction:transaction]; [message updateWithSendingToSingleGroupRecipient:envelope.source transaction:transaction];
[self sendGroupUpdateForThread:gThread message:message]; [self sendGroupUpdateForThread:gThread message:message];
} }

Loading…
Cancel
Save