Show the delete action in public chats.

pull/43/head
Mikunj 6 years ago
parent fb7d6dcc21
commit e68de54a87

@ -86,7 +86,7 @@ class ConversationViewItemActions: NSObject {
actions.append(copyTextAction) actions.append(copyTextAction)
} }
if !isGroup { if !isGroup || conversationViewItem.canDeleteGroupMessage {
let deleteAction = MessageActionBuilder.deleteMessage(conversationViewItem: conversationViewItem, delegate: delegate) let deleteAction = MessageActionBuilder.deleteMessage(conversationViewItem: conversationViewItem, delegate: delegate)
actions.append(deleteAction) actions.append(deleteAction)
} }

@ -305,6 +305,8 @@ class ColorPickerView: UIView, ColorViewDelegate {
@objc @objc
private class MockConversationViewItem: NSObject, ConversationViewItem { private class MockConversationViewItem: NSObject, ConversationViewItem {
var canDeleteGroupMessage: Bool = false
var interaction: TSInteraction = TSMessage() var interaction: TSInteraction = TSMessage()
var interactionType: OWSInteractionType = OWSInteractionType.unknown var interactionType: OWSInteractionType = OWSInteractionType.unknown
var quotedReply: OWSQuotedReplyModel? var quotedReply: OWSQuotedReplyModel?

@ -67,6 +67,7 @@ NSString *NSStringForOWSMessageCellType(OWSMessageCellType cellType);
@property (nonatomic, readonly, nullable) OWSQuotedReplyModel *quotedReply; @property (nonatomic, readonly, nullable) OWSQuotedReplyModel *quotedReply;
@property (nonatomic, readonly) BOOL isGroupThread; @property (nonatomic, readonly) BOOL isGroupThread;
@property (nonatomic, readonly) BOOL canDeleteGroupMessage;
@property (nonatomic, readonly) BOOL hasBodyText; @property (nonatomic, readonly) BOOL hasBodyText;

@ -1161,6 +1161,30 @@ NSString *NSStringForOWSMessageCellType(OWSMessageCellType cellType)
- (void)deleteAction - (void)deleteAction
{ {
// TODO: Handle deletion differently for public chats
if (self.isGroupThread) {
TSGroupThread *groupThread = (TSGroupThread *)self.interaction.thread;
// If it's RSS then just proceed normally
if (groupThread.isRSS) {
[self.interaction remove];
return;
};
// Only allow deletion on incoming and outgoing messages
OWSInteractionType interationType = self.interaction.interactionType;
if (interationType != OWSInteractionType_OutgoingMessage && interationType != OWSInteractionType_IncomingMessage) return;
// Check that we have the server id for the message
TSMessage *message = (TSMessage *)self.interaction;
if (!message.isPublicChatMessage) return;
// TODO: Call the group api here to delete the message
// Just return and don't delete for now
return;
}
[self.interaction remove]; [self.interaction remove];
} }
@ -1204,6 +1228,27 @@ NSString *NSStringForOWSMessageCellType(OWSMessageCellType cellType)
return NO; return NO;
} }
- (BOOL)canDeleteGroupMessage
{
if (!self.isGroupThread) return false;
// Make sure it's a public chat and not an rss feed
TSGroupThread *groupThread = (TSGroupThread *)self.interaction.thread;
if (groupThread.isRSS) return false;
// Only allow deletion on incoming and outgoing messages
OWSInteractionType interationType = self.interaction.interactionType;
if (interationType != OWSInteractionType_OutgoingMessage && interationType != OWSInteractionType_IncomingMessage) return false;
// Make sure it's a public chat message
TSMessage *message = (TSMessage *)self.interaction;
if (!message.isPublicChatMessage) return false;
// TODO: Disable deletion of incoming messages if we're not moderators
return true;
}
@end @end
NS_ASSUME_NONNULL_END NS_ASSUME_NONNULL_END

@ -16,6 +16,7 @@ extern NSString *const TSGroupThread_NotificationKey_UniqueId;
@interface TSGroupThread : TSThread @interface TSGroupThread : TSThread
@property (nonatomic, strong) TSGroupModel *groupModel; @property (nonatomic, strong) TSGroupModel *groupModel;
@property (nonatomic, readonly) BOOL isRSS;
+ (instancetype)getOrCreateThreadWithGroupModel:(TSGroupModel *)groupModel; + (instancetype)getOrCreateThreadWithGroupModel:(TSGroupModel *)groupModel;
+ (instancetype)getOrCreateThreadWithGroupModel:(TSGroupModel *)groupModel + (instancetype)getOrCreateThreadWithGroupModel:(TSGroupModel *)groupModel

@ -266,6 +266,12 @@ NSString *const TSGroupThread_NotificationKey_UniqueId = @"TSGroupThread_Notific
return [self.class stableColorNameForNewConversationWithString:[self threadIdFromGroupId:groupId]]; return [self.class stableColorNameForNewConversationWithString:[self threadIdFromGroupId:groupId]];
} }
- (BOOL)isRSS
{
NSString *groupID = [[NSString alloc] initWithData:self.groupModel.groupId encoding:NSUTF8StringEncoding];
return groupID != nil && [groupID containsString:@"rss:"];
}
@end @end
NS_ASSUME_NONNULL_END NS_ASSUME_NONNULL_END

@ -7,7 +7,7 @@ public final class LokiRSSFeed : NSObject {
@objc public let isDeletable: Bool @objc public let isDeletable: Bool
@objc public init(id: String, server: String, displayName: String, isDeletable: Bool) { @objc public init(id: String, server: String, displayName: String, isDeletable: Bool) {
self.id = id self.id = "rss://\(id)"
self.server = server self.server = server
self.displayName = displayName self.displayName = displayName
self.isDeletable = isDeletable self.isDeletable = isDeletable

Loading…
Cancel
Save