Add report button for Session Public Chat messages

pull/86/head
Niels Andriesse 5 years ago
parent 495c19452e
commit 15cc478654

@ -0,0 +1,12 @@
{
"images" : [
{
"idiom" : "universal",
"filename" : "Flag.pdf"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}

@ -6,6 +6,7 @@ import Foundation
@objc
protocol MessageActionsDelegate: class {
func report(_ conversationViewItem: ConversationViewItem)
func messageActionsShowDetailsForItem(_ conversationViewItem: ConversationViewItem)
func messageActionsReplyToItem(_ conversationViewItem: ConversationViewItem)
func copyPublicKey(for conversationViewItem: ConversationViewItem)
@ -47,6 +48,14 @@ struct MessageActionBuilder {
delegate?.messageActionsShowDetailsForItem(conversationViewItem)
})
}
static func report(_ conversationViewItem: ConversationViewItem, delegate: MessageActionsDelegate) -> MenuAction {
return MenuAction(image: #imageLiteral(resourceName: "Flag"),
title: NSLocalizedString("Report", comment: ""),
subtitle: nil,
block: { [weak delegate] _ in delegate?.report(conversationViewItem) }
)
}
static func deleteMessage(conversationViewItem: ConversationViewItem, delegate: MessageActionsDelegate) -> MenuAction {
return MenuAction(image: #imageLiteral(resourceName: "ic_trash"),
@ -106,6 +115,11 @@ class ConversationViewItemActions: NSObject {
actions.append(deleteAction)
}
if isGroup && conversationViewItem.interaction.thread.name() == "Session Public Chat" {
let reportAction = MessageActionBuilder.report(conversationViewItem, delegate: delegate)
actions.append(reportAction)
}
let showDetailsAction = MessageActionBuilder.showDetails(conversationViewItem: conversationViewItem, delegate: delegate)
actions.append(showDetailsAction)
@ -139,6 +153,11 @@ class ConversationViewItemActions: NSObject {
actions.append(deleteAction)
}
if isGroup && conversationViewItem.interaction.thread.name() == "Session Public Chat" {
let reportAction = MessageActionBuilder.report(conversationViewItem, delegate: delegate)
actions.append(reportAction)
}
let showDetailsAction = MessageActionBuilder.showDetails(conversationViewItem: conversationViewItem, delegate: delegate)
actions.append(showDetailsAction)
@ -167,6 +186,11 @@ class ConversationViewItemActions: NSObject {
actions.append(deleteAction)
}
if isGroup && conversationViewItem.interaction.thread.name() == "Session Public Chat" {
let reportAction = MessageActionBuilder.report(conversationViewItem, delegate: delegate)
actions.append(reportAction)
}
let showDetailsAction = MessageActionBuilder.showDetails(conversationViewItem: conversationViewItem, delegate: delegate)
actions.append(showDetailsAction)

@ -2083,6 +2083,20 @@ typedef enum : NSUInteger {
[self showDetailViewForViewItem:conversationViewItem];
}
- (void)report:(id<ConversationViewItem>)conversationViewItem
{
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Report?" message:@"If the message is found to violate the Session Public Chat code of conduct it will be removed." preferredStyle:UIAlertControllerStyleAlert];
[alert addAction:[UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
uint64_t messageID = 0;
if ([conversationViewItem.interaction isKindOfClass:TSMessage.class]) {
messageID = ((TSMessage *)conversationViewItem.interaction).groupChatServerID;
}
[LKPublicChatAPI reportMessageWithID:messageID inChannel:1 onServer:@"https://chat.getsession.org"];
}]];
[alert addAction:[UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleDefault handler:nil]];
[self presentViewController:alert animated:YES completion:nil];
}
- (void)messageActionsReplyToItem:(id<ConversationViewItem>)conversationViewItem
{
[self populateReplyForViewItem:conversationViewItem];

@ -2808,3 +2808,4 @@
"Would you like to join the Session Public Chat?" = "Would you like to join the Session Public Chat?";
"Join Public Chat" = "Join Public Chat";
"No, thank you" = "No, thank you";
"Report" = "Report";

@ -360,6 +360,12 @@ public final class LokiPublicChatAPI : LokiDotNetAPI {
}
}
public static func reportMessageWithID(_ messageID: UInt64, in channel: UInt64, on server: String) -> Promise<Void> {
let url = URL(string: "\(server)/loki/v1/channels/\(channel)/messages/\(messageID)/report")!
let request = TSRequest(url: url, method: "POST", parameters: [:])
return LokiFileServerProxy(for: server).perform(request).map { _ in }
}
@objc public static func clearCaches(for channel: UInt64, on server: String) {
removeLastMessageServerID(for: channel, on: server)
removeLastDeletionServerID(for: channel, on: server)
@ -395,4 +401,9 @@ public final class LokiPublicChatAPI : LokiDotNetAPI {
public static func objc_setProfilePicture(to url: String?, using profileKey: Data, on server: String) -> AnyPromise {
return AnyPromise.from(setProfilePictureURL(to: url, using: profileKey, on: server))
}
@objc(reportMessageWithID:inChannel:onServer:)
public static func objc_reportMessageWithID(_ messageID: UInt64, in channel: UInt64, on server: String) -> AnyPromise {
return AnyPromise.from(reportMessageWithID(messageID, in: channel, on: server))
}
}

Loading…
Cancel
Save