Respond to CR.

This commit is contained in:
Matthew Chen 2018-04-24 16:38:35 -04:00
parent 55916e84c2
commit 204d379603
7 changed files with 60 additions and 62 deletions

View File

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

View File

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

View File

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

View File

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

View File

@ -213,8 +213,8 @@ typedef NS_ENUM(NSInteger, TSGroupMetaMessage) {
// 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
// delivered to the requestor.
- (void)updateWithSingleGroupRecipient:(NSString *)singleGroupRecipient
transaction:(YapDatabaseReadWriteTransaction *)transaction;
- (void)updateWithSendingToSingleGroupRecipient:(NSString *)singleGroupRecipient
transaction:(YapDatabaseReadWriteTransaction *)transaction;
// This method is used to record a successful "read" by one recipient.
- (void)updateWithReadRecipientId:(NSString *)recipientId

View File

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

View File

@ -891,7 +891,7 @@ NS_ASSUME_NONNULL_BEGIN
[TSOutgoingMessage outgoingMessageInThread:gThread groupMetaMessage:TSGroupMessageUpdate];
[message updateWithCustomMessage:updateGroupInfo transaction:transaction];
// 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];
}