Present shared items from conversations info view.

Signed-off-by: Ivan Sein <ivan@nextcloud.com>
This commit is contained in:
Ivan Sein 2022-04-22 17:10:07 +02:00
Родитель cf4338d3cb
Коммит 50309e68d7
12 изменённых файлов: 258 добавлений и 36 удалений

Просмотреть файл

@ -247,6 +247,8 @@
2CC007CA20E125C20096D91F /* NewRoomTableViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 2CC007C820E125C20096D91F /* NewRoomTableViewController.m */; };
2CC007CB20E125C20096D91F /* NewRoomTableViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 2CC007C920E125C20096D91F /* NewRoomTableViewController.xib */; };
2CC007CE20E50B0A0096D91F /* MessageBodyTextView.m in Sources */ = {isa = PBXBuildFile; fileRef = 2CC007CD20E50B0A0096D91F /* MessageBodyTextView.m */; };
2CC1FF4428147F11009F7288 /* RoomSharedItemsTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2CC1FF4228147F10009F7288 /* RoomSharedItemsTableViewController.swift */; };
2CC1FF4528147F11009F7288 /* RoomSharedItemsTableViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 2CC1FF4328147F10009F7288 /* RoomSharedItemsTableViewController.xib */; };
2CC32E8D27F4540E00BB8C39 /* ReactionsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2CC32E8C27F4540E00BB8C39 /* ReactionsView.swift */; };
2CC32E9227F45AE000BB8C39 /* ReactionsViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2CC32E9027F45AE000BB8C39 /* ReactionsViewCell.swift */; };
2CC32E9327F45AE000BB8C39 /* ReactionsViewCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 2CC32E9127F45AE000BB8C39 /* ReactionsViewCell.xib */; };
@ -722,6 +724,8 @@
2CC007C920E125C20096D91F /* NewRoomTableViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = NewRoomTableViewController.xib; sourceTree = "<group>"; };
2CC007CC20E50B0A0096D91F /* MessageBodyTextView.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MessageBodyTextView.h; sourceTree = "<group>"; };
2CC007CD20E50B0A0096D91F /* MessageBodyTextView.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MessageBodyTextView.m; sourceTree = "<group>"; };
2CC1FF4228147F10009F7288 /* RoomSharedItemsTableViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RoomSharedItemsTableViewController.swift; sourceTree = "<group>"; };
2CC1FF4328147F10009F7288 /* RoomSharedItemsTableViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = RoomSharedItemsTableViewController.xib; sourceTree = "<group>"; };
2CC32E8C27F4540E00BB8C39 /* ReactionsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ReactionsView.swift; sourceTree = "<group>"; };
2CC32E9027F45AE000BB8C39 /* ReactionsViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ReactionsViewCell.swift; sourceTree = "<group>"; };
2CC32E9127F45AE000BB8C39 /* ReactionsViewCell.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = ReactionsViewCell.xib; sourceTree = "<group>"; };
@ -1004,6 +1008,8 @@
2C3780BC2107209C003F9AE8 /* NCRoomParticipants.m */,
2C98F77721622445001A6A73 /* RoomSearchTableViewController.h */,
2C98F77821622445001A6A73 /* RoomSearchTableViewController.m */,
2CC1FF4228147F10009F7288 /* RoomSharedItemsTableViewController.swift */,
2CC1FF4328147F10009F7288 /* RoomSharedItemsTableViewController.xib */,
);
name = Rooms;
sourceTree = "<group>";
@ -1646,6 +1652,7 @@
2CC007CB20E125C20096D91F /* NewRoomTableViewController.xib in Resources */,
2C98F77D216231D3001A6A73 /* RoomTableViewCell.xib in Resources */,
2CF9CBFF26025F65002246EF /* TextInputTableViewCell.xib in Resources */,
2CC1FF4528147F11009F7288 /* RoomSharedItemsTableViewController.xib in Resources */,
2C06BF6420AC64370031EB46 /* DateHeaderView.xib in Resources */,
2C440D1220EA4A770005F9BB /* RoomInfoTableViewController.xib in Resources */,
2C7A1237200E0A5700864818 /* UserSettingsTableViewCell.xib in Resources */,
@ -1921,6 +1928,7 @@
2CBF82B61FD0939600636459 /* NCAPISessionManager.m in Sources */,
2CA155562099E07700CE8EF0 /* GroupedChatMessageTableViewCell.m in Sources */,
2CA15548208EA1EA00CE8EF0 /* ChatMessageTableViewCell.m in Sources */,
2CC1FF4428147F11009F7288 /* RoomSharedItemsTableViewController.swift in Sources */,
2C4446D8265814D100DF1DBC /* ServerCapabilities.m in Sources */,
DA66582D27B6A73800B46B11 /* UserProfileTableViewController+DelegateMethods.swift in Sources */,
1F5CDF642584E78900B0026E /* NCChatFileStatus.m in Sources */,

Просмотреть файл

@ -297,35 +297,6 @@
[self presentViewController:confirmDialog animated:YES completion:nil];
}
- (NSString *)dateDiff:(NSDate *) convertedDate
{
NSDate *todayDate = [NSDate date];
double ti = [convertedDate timeIntervalSinceDate:todayDate];
ti = ti * -1;
if (ti < 60) {
// This minute
return NSLocalizedString(@"less than a minute ago", nil);
} else if (ti < 3600) {
// This hour
int diff = round(ti / 60);
return [NSString stringWithFormat:NSLocalizedString(@"%d minutes ago", nil), diff];
} else if (ti < 86400) {
// This day
int diff = round(ti / 60 / 60);
return[NSString stringWithFormat:NSLocalizedString(@"%d hours ago", nil), diff];
} else if (ti < 86400 * 30) {
// This month
int diff = round(ti / 60 / 60 / 24);
return[NSString stringWithFormat:NSLocalizedString(@"%d days ago", nil), diff];
} else {
// Older than one month
NSDateFormatter *df = [[NSDateFormatter alloc] init];
[df setFormatterBehavior:NSDateFormatterBehavior10_4];
[df setDateStyle:NSDateFormatterMediumStyle];
return [df stringFromDate:convertedDate];
}
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
@ -353,7 +324,7 @@
// Name and modification date
cell.fileNameLabel.text = item.fileName;
cell.fileInfoLabel.text = [self dateDiff:item.date];
cell.fileInfoLabel.text = [NCUtils relativeTimeFromDate:item.date];
// Icon or preview
NSString *imageName = [NCUtils previewImageForFileMIMEType:item.contentType];

Просмотреть файл

@ -61,7 +61,7 @@ typedef void (^SendChatMessagesCompletionBlock)(NSError *error);
typedef void (^GetMentionSuggestionsCompletionBlock)(NSMutableArray *mentions, NSError *error);
typedef void (^DeleteChatMessageCompletionBlock)(NSDictionary *messageDict, NSError *error, NSInteger statusCode);
typedef void (^ClearChatHistoryCompletionBlock)(NSDictionary *messageDict, NSError *error, NSInteger statusCode);
typedef void (^GetSharedItemsCompletionBlock)(NSArray *messages, NSInteger lastKnownMessage, NSError *error, NSInteger statusCode);
typedef void (^GetSharedItemsCompletionBlock)(NSDictionary *sharedItems, NSInteger lastKnownMessage, NSError *error, NSInteger statusCode);
typedef void (^MessageReactionCompletionBlock)(NSDictionary *reactionsDict, NSError *error, NSInteger statusCode);

Просмотреть файл

@ -1300,7 +1300,18 @@ NSInteger const kReceivedChatMessagesLimit = 100;
NCAPISessionManager *apiSessionManager = [_apiSessionManagers objectForKey:account.accountId];
NSURLSessionDataTask *task = [apiSessionManager GET:URLString parameters:parameters progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
NSArray *responseMessages = [[responseObject objectForKey:@"ocs"] objectForKey:@"data"];
NSDictionary *responseSharedItems = [[responseObject objectForKey:@"ocs"] objectForKey:@"data"];
// Create dictionary [String: [NCChatMessage]]
NSMutableDictionary *sharedItems = [NSMutableDictionary new];
for (NSString *key in responseSharedItems.allKeys) {
NSArray *responseMessages = [responseSharedItems objectForKey:key];
NSMutableArray *messages = [NSMutableArray new];
for (NSDictionary *messageDict in responseMessages) {
NCChatMessage *message = [NCChatMessage messageWithDictionary:messageDict];
[messages addObject:message];
}
[sharedItems setObject:messages forKey:key];
}
// Get X-Chat-Last-Given
NSHTTPURLResponse *response = ((NSHTTPURLResponse *)[task response]);
NSDictionary *headers = [response allHeaderFields];
@ -1311,7 +1322,7 @@ NSInteger const kReceivedChatMessagesLimit = 100;
}
if (block) {
block(responseMessages, lastKnownMessage, nil, 0);
block(sharedItems, lastKnownMessage, nil, 0);
}
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
NSInteger statusCode = [self getResponseStatusCode:task.response];
@ -1340,7 +1351,18 @@ NSInteger const kReceivedChatMessagesLimit = 100;
NCAPISessionManager *apiSessionManager = [_apiSessionManagers objectForKey:account.accountId];
NSURLSessionDataTask *task = [apiSessionManager GET:URLString parameters:parameters progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
NSArray *responseMessages = [[responseObject objectForKey:@"ocs"] objectForKey:@"data"];
NSDictionary *responseSharedItems = [[responseObject objectForKey:@"ocs"] objectForKey:@"data"];
// Create dictionary [String: [NCChatMessage]]
NSMutableDictionary *sharedItems = [NSMutableDictionary new];
for (NSString *key in responseSharedItems.allKeys) {
NSArray *responseMessages = [responseSharedItems objectForKey:key];
NSMutableArray *messages = [NSMutableArray new];
for (NSDictionary *messageDict in responseMessages) {
NCChatMessage *message = [NCChatMessage messageWithDictionary:messageDict];
[messages addObject:message];
}
[sharedItems setObject:messages forKey:key];
}
// Get X-Chat-Last-Given
NSHTTPURLResponse *response = ((NSHTTPURLResponse *)[task response]);
NSDictionary *headers = [response allHeaderFields];
@ -1351,7 +1373,7 @@ NSInteger const kReceivedChatMessagesLimit = 100;
}
if (block) {
block(responseMessages, lastKnownMessage, nil, 0);
block(sharedItems, lastKnownMessage, nil, 0);
}
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
NSInteger statusCode = [self getResponseStatusCode:task.response];

Просмотреть файл

@ -38,7 +38,13 @@ extern NSString * const kMessageTypeSystem;
extern NSString * const kMessageTypeCommand;
extern NSString * const kMessageTypeVoiceMessage;
RLM_ARRAY_TYPE(NCChatReaction)
extern NSString * const kSharedItemTypeAudio;
extern NSString * const kSharedItemTypeDeckcard;
extern NSString * const kSharedItemTypeFile;
extern NSString * const kSharedItemTypeLocation;
extern NSString * const kSharedItemTypeMedia;
extern NSString * const kSharedItemTypeOther;
extern NSString * const kSharedItemTypeVoice;
@interface NCChatMessage : RLMObject <NSCopying>

Просмотреть файл

@ -33,6 +33,14 @@ NSString * const kMessageTypeSystem = @"system";
NSString * const kMessageTypeCommand = @"command";
NSString * const kMessageTypeVoiceMessage = @"voice-message";
NSString * const kSharedItemTypeAudio = @"audio";
NSString * const kSharedItemTypeDeckcard = @"deckcard";
NSString * const kSharedItemTypeFile = @"file";
NSString * const kSharedItemTypeLocation = @"location";
NSString * const kSharedItemTypeMedia = @"media";
NSString * const kSharedItemTypeOther = @"other";
NSString * const kSharedItemTypeVoice = @"voice";
@interface NCChatMessage ()
{
NCMessageFileParameter *_fileParameter;

Просмотреть файл

@ -39,6 +39,7 @@ NS_ASSUME_NONNULL_BEGIN
+ (NSString *)dateAtomFormatFromDate:(NSDate *)date;
+ (NSString *)readableDateFromDate:(NSDate *)date;
+ (NSString *)getTimeFromDate:(NSDate *)date;
+ (NSString *)relativeTimeFromDate:(NSDate *)date;
+ (NSString *)sha1FromString:(NSString *)string;

Просмотреть файл

@ -148,6 +148,35 @@ static NSString *const nextcloudScheme = @"nextcloud:";
return [formatter stringFromDate:date];
}
+ (NSString *)relativeTimeFromDate:(NSDate *)date
{
NSDate *todayDate = [NSDate date];
double ti = [date timeIntervalSinceDate:todayDate];
ti = ti * -1;
if (ti < 60) {
// This minute
return NSLocalizedString(@"less than a minute ago", nil);
} else if (ti < 3600) {
// This hour
int diff = round(ti / 60);
return [NSString stringWithFormat:NSLocalizedString(@"%d minutes ago", nil), diff];
} else if (ti < 86400) {
// This day
int diff = round(ti / 60 / 60);
return[NSString stringWithFormat:NSLocalizedString(@"%d hours ago", nil), diff];
} else if (ti < 86400 * 30) {
// This month
int diff = round(ti / 60 / 60 / 24);
return[NSString stringWithFormat:NSLocalizedString(@"%d days ago", nil), diff];
} else {
// Older than one month
NSDateFormatter *df = [[NSDateFormatter alloc] init];
[df setFormatterBehavior:NSDateFormatterBehavior10_4];
[df setDateStyle:NSDateFormatterMediumStyle];
return [df stringFromDate:date];
}
}
+ (NSString *)sha1FromString:(NSString *)string
{
NSData *data = [string dataUsingEncoding:NSUTF8StringEncoding];

Просмотреть файл

@ -25,6 +25,7 @@
#import "AvatarHeaderView.h"
#import "DetailedOptionsSelectorTableViewController.h"
#import "DirectoryTableViewCell.h"
#import "HeaderWithButton.h"
#import "NBPhoneNumber.h"
#import "NBPhoneNumberDefines.h"
@ -39,6 +40,7 @@
#import "NCUserDefaults.h"
#import "NCUserInterfaceController.h"
#import "NCUserStatus.h"
#import "NCUtils.h"
#import "NotificationCenterNotifications.h"
#import "PlaceholderView.h"
#import "RoundedNumberView.h"

Просмотреть файл

@ -30,6 +30,8 @@
#import "UIImageView+Letters.h"
#import "UIView+Toast.h"
#import "NextcloudTalk-Swift.h"
#import "AddParticipantsTableViewController.h"
#import "ContactsTableViewCell.h"
#import "HeaderWithButton.h"
@ -887,6 +889,20 @@ typedef enum FileAction {
}];
}
- (void)presentSharedItemsView
{
RoomSharedItemsTableViewController *sharedItemsVC = [[RoomSharedItemsTableViewController alloc] init];
[self.navigationController pushViewController:sharedItemsVC animated:YES];
[[NCAPIController sharedInstance] getSharedItemsOverviewInRoom:_room.token withLimit:-1 forAccount:[[NCDatabaseManager sharedInstance] activeAccount] withCompletionBlock:^(NSDictionary *sharedItems, NSInteger lastKnownMessage, NSError *error, NSInteger statusCode) {
if (!error) {
[sharedItemsVC addSharedItemsWithSharedItems:sharedItems];
} else {
NSLog(@"Error getting shared items: %@", error.description);
}
}];
}
- (void)clearHistory
{
[[NCAPIController sharedInstance] clearChatHistoryInRoom:_room.token forAccount:[[NCDatabaseManager sharedInstance] activeAccount] withCompletionBlock:^(NSDictionary *messageDict, NSError *error, NSInteger statusCode) {
@ -1956,6 +1972,11 @@ typedef enum FileAction {
}
}
break;
case kRoomInfoSectionSharedItems:
{
[self presentSharedItemsView];
}
break;
case kRoomInfoSectionNotifications:
{
NSArray *actions = [self getNotificationsActions];

Просмотреть файл

@ -0,0 +1,119 @@
/**
* @copyright Copyright (c) 2022 Ivan Sein <ivan@nextcloud.com>
*
* @author Ivan Sein <ivan@nextcloud.com>
*
* @license GNU GPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
import UIKit
@objcMembers class RoomSharedItemsTableViewController: UITableViewController {
var sharedItems: [String: [NCChatMessage]] = [:]
var filterType: String = "all"
override func viewDidLoad() {
super.viewDidLoad()
self.navigationController?.navigationBar.titleTextAttributes = [NSAttributedString.Key.foregroundColor: NCAppBranding.themeTextColor()]
self.navigationController?.navigationBar.tintColor = NCAppBranding.themeTextColor()
self.navigationController?.navigationBar.barTintColor = NCAppBranding.themeColor()
self.navigationController?.navigationBar.isTranslucent = false
self.navigationItem.title = NSLocalizedString("Shared items", comment: "")
if #available(iOS 13.0, *) {
let appearance = UINavigationBarAppearance()
appearance.configureWithOpaqueBackground()
appearance.titleTextAttributes = [.foregroundColor: NCAppBranding.themeTextColor()]
appearance.backgroundColor = NCAppBranding.themeColor()
self.navigationItem.standardAppearance = appearance
self.navigationItem.compactAppearance = appearance
self.navigationItem.scrollEdgeAppearance = appearance
}
self.tableView.register(UINib(nibName: kDirectoryTableCellNibName, bundle: nil), forCellReuseIdentifier: kDirectoryCellIdentifier)
self.navigationItem.rightBarButtonItem = UIBarButtonItem(image: UIImage(named: "sorting"), style: .plain, target: self, action: #selector(self.filterButtonPressed))
self.navigationItem.rightBarButtonItem?.tintColor = NCAppBranding.themeTextColor()
}
func filterButtonPressed() {
// TODO: Implement items filter
}
func itemsForFilterType(filterType: String) -> [NCChatMessage] {
if filterType == "all" {
var allItems: [NCChatMessage] = []
sharedItems.values.forEach { items in
allItems.append(contentsOf: items)
}
return allItems
}
return sharedItems[filterType] ?? []
}
func addSharedItems(sharedItems: [String: [NCChatMessage]]) {
self.sharedItems = sharedItems
self.tableView.reloadData()
}
func imageNameForMessage(message: NCChatMessage) -> String {
var imageName = "file"
if message.file() != nil {
imageName = NCUtils.previewImage(forFileMIMEType: message.file().mimetype)
}
return imageName
}
// MARK: - Table view data source
override func numberOfSections(in tableView: UITableView) -> Int {
return 1
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
let itemsForType = itemsForFilterType(filterType: filterType)
return itemsForType.count
}
override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return kDirectoryTableCellHeight
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: kDirectoryCellIdentifier) as? DirectoryTableViewCell ??
DirectoryTableViewCell(style: .default, reuseIdentifier: kShareCellIdentifier)
let itemsForType = itemsForFilterType(filterType: filterType)
let message = itemsForType[indexPath.row]
cell.fileNameLabel?.text = message.parsedMessage().string
cell.fileInfoLabel?.text = NCUtils.relativeTime(from: Date(timeIntervalSince1970: Double(message.timestamp)))
let image = UIImage(named: imageNameForMessage(message: message))
cell.fileImageView?.image = image
if message.file()?.previewAvailable != nil {
cell.fileImageView?
.setImageWith(NCAPIController.sharedInstance().createPreviewRequest(forFile: message.file().parameterId,
width: 40, height: 40,
using: NCDatabaseManager.sharedInstance().activeAccount()),
placeholderImage: image, success: nil, failure: nil)
}
return cell
}
}

Просмотреть файл

@ -0,0 +1,35 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="20037" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
<device id="retina6_1" orientation="portrait" appearance="light"/>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="20020"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="System colors in document resources" minToolsVersion="11.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<objects>
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner" customClass="RoomSharedItemsTableViewController" customModule="NextcloudTalk" customModuleProvider="target">
<connections>
<outlet property="view" destination="i5M-Pr-FkT" id="sfx-zR-JGt"/>
</connections>
</placeholder>
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
<tableView opaque="NO" clipsSubviews="YES" clearsContextBeforeDrawing="NO" contentMode="scaleToFill" bouncesZoom="NO" style="plain" separatorStyle="default" rowHeight="44" sectionHeaderHeight="22" sectionFooterHeight="22" id="i5M-Pr-FkT">
<rect key="frame" x="0.0" y="0.0" width="414" height="896"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<viewLayoutGuide key="safeArea" id="vLr-E1-eTs"/>
<color key="backgroundColor" systemColor="systemBackgroundColor"/>
<connections>
<outlet property="dataSource" destination="-1" id="Tng-2m-Rnh"/>
<outlet property="delegate" destination="-1" id="9aC-8N-iBw"/>
</connections>
<point key="canvasLocation" x="139" y="98"/>
</tableView>
</objects>
<resources>
<systemColor name="systemBackgroundColor">
<color white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
</systemColor>
</resources>
</document>