Skip to content

Commit

Permalink
Merge pull request #1805 from nextcloud/add-message-icons
Browse files Browse the repository at this point in the history
Add message icons
  • Loading branch information
Ivansss authored Sep 19, 2024
2 parents c139836 + 8135043 commit c6ccddb
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 9 deletions.
4 changes: 2 additions & 2 deletions NextcloudTalk/NCChatMessage.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ typedef void (^GetReferenceDataCompletionBlock)(NCChatMessage *message, NSDictio
+ (void)updateChatMessage:(NCChatMessage *)managedChatMessage withChatMessage:(NCChatMessage *)chatMessage isRoomLastMessage:(BOOL)isRoomLastMessage;

- (NCMessageFileParameter *)file;
- (NCMessageLocationParameter *)geoLocation;
- (NCDeckCardParameter *)deckCard;
- (NCMessageLocationParameter * _Nullable)geoLocation;
- (NCDeckCardParameter * _Nullable)deckCard;
- (NSString *)objectShareLink;
- (NSMutableAttributedString *)parsedMessage;
- (NSMutableAttributedString *)parsedMarkdown;
Expand Down
25 changes: 25 additions & 0 deletions NextcloudTalk/NCChatMessage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -232,4 +232,29 @@ import SwiftyAttributes
return TalkActor(actorId: self.actorId, actorType: self.actorType, actorDisplayName: self.actorDisplayName)
}

public var messageIconName: String? {
if let file = self.file() {
if NCUtils.isImage(fileType: file.mimetype) {
return "photo"
} else if NCUtils.isVideo(fileType: file.mimetype) {
return "movieclapper"
} else if NCUtils.isVCard(fileType: file.mimetype) {
return "person.text.rectangle"
} else if self.isVoiceMessage {
return "mic"
} else if NCUtils.isAudio(fileType: file.mimetype) {
return "music.note"
} else {
return "doc"
}
} else if poll != nil {
return "chart.bar"
} else if deckCard() != nil {
return "rectangle.stack"
} else if geoLocation() != nil {
return "location"
}

return nil
}
}
18 changes: 13 additions & 5 deletions NextcloudTalk/NCRoom.swift
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ import Realm
return "\(self.messageExpiration)s"
}

public var lastMessageString: String? {
public var lastMessageString: NSMutableAttributedString? {
var lastMessage = self.lastMessage

if self.isFederated && lastMessage == nil {
Expand Down Expand Up @@ -218,11 +218,19 @@ import Realm
actorName = "\(actorName): "
}

// Create last message
let lastMessageString = "\(actorName)\(lastMessage.parsedMarkdown().string)"
let lastMessageString = NSMutableAttributedString(string: actorName)

// Limit last message string to 80 characters
return String(lastMessageString.prefix(80))
if let messageIconName = lastMessage.messageIconName, let messageIcon = UIImage(systemName: messageIconName) {
let attachmentString = NSMutableAttributedString(attachment: NSTextAttachment(image: messageIcon))
attachmentString.append(NSAttributedString(string: " "))

lastMessageString.append(attachmentString)
}

let parsedMarkdownString = String(lastMessage.parsedMarkdown().string.prefix(80))
lastMessageString.append(NSAttributedString(string: parsedMarkdownString))

return lastMessageString.withFont(.preferredFont(forTextStyle: .callout)).withTextColor(.secondaryLabel)
}

private var lastMessageProxiedDictionary: [AnyHashable: Any] {
Expand Down
8 changes: 8 additions & 0 deletions NextcloudTalk/NCUtils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,14 @@ import AVFoundation
return self.previewImage(forMimeType: fileType) == "file-video"
}

public static func isAudio(fileType: String) -> Bool {
return self.previewImage(forMimeType: fileType) == "file-audio"
}

public static func isVCard(fileType: String) -> Bool {
return self.previewImage(forMimeType: fileType) == "file-vcard"
}

public static func isNextcloudAppInstalled() -> Bool {
var isInstalled = false

Expand Down
2 changes: 1 addition & 1 deletion NextcloudTalk/RoomSearchTableViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
// Set last activity
if (room.lastMessageId || room.lastMessageProxiedJSONString) {
cell.titleOnly = NO;
cell.subtitleLabel.text = room.lastMessageString;
cell.subtitleLabel.attributedText = room.lastMessageString;
} else {
cell.titleOnly = YES;
}
Expand Down
2 changes: 1 addition & 1 deletion NextcloudTalk/RoomsTableViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -1446,7 +1446,7 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
// Set last activity
if (room.lastMessageId || room.lastMessageProxiedJSONString) {
cell.titleOnly = NO;
cell.subtitleLabel.text = room.lastMessageString;
cell.subtitleLabel.attributedText = room.lastMessageString;
} else {
cell.titleOnly = YES;
}
Expand Down

0 comments on commit c6ccddb

Please sign in to comment.