-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #96 from ls1intum/develop
`General`: Navigate to mentions in messages (#95)
- Loading branch information
Showing
12 changed files
with
205 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
.../Sources/Messages/ViewModels/MessageDetailViewModels/MessageCellModel+MentionScheme.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// | ||
// MessageCellModel+MentionScheme.swift | ||
// | ||
// | ||
// Created by Nityananda Zbil on 25.03.24. | ||
// | ||
|
||
import Foundation | ||
|
||
enum MentionScheme { | ||
case channel(Int64) | ||
case exercise(Int) | ||
case lecture(Int) | ||
case member(String) | ||
|
||
init?(_ url: URL) { | ||
guard url.scheme == "mention" else { | ||
return nil | ||
} | ||
switch url.host() { | ||
case "channel": | ||
if let id = Int64(url.lastPathComponent) { | ||
self = .channel(id) | ||
return | ||
} | ||
case "exercise": | ||
if let id = Int(url.lastPathComponent) { | ||
self = .exercise(id) | ||
return | ||
} | ||
case "lecture": | ||
if let id = Int(url.lastPathComponent) { | ||
self = .lecture(id) | ||
return | ||
} | ||
case "member": | ||
self = .member(url.lastPathComponent) | ||
return | ||
default: | ||
return nil | ||
} | ||
return nil | ||
} | ||
} |
77 changes: 77 additions & 0 deletions
77
ArtemisKit/Sources/Messages/ViewModels/MessageDetailViewModels/MessageCellModel.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
// | ||
// MessageCellModel.swift | ||
// | ||
// | ||
// Created by Nityananda Zbil on 25.03.24. | ||
// | ||
|
||
import Foundation | ||
import Navigation | ||
import SharedModels | ||
import UserStore | ||
|
||
@MainActor | ||
@Observable | ||
final class MessageCellModel { | ||
let course: Course | ||
|
||
let conversationPath: ConversationPath? | ||
let isHeaderVisible: Bool | ||
let retryButtonAction: (() -> Void)? | ||
|
||
var isActionSheetPresented = false | ||
var isDetectingLongPress = false | ||
|
||
private let messagesService: MessagesService | ||
private let userSession: UserSession | ||
|
||
init( | ||
course: Course, | ||
conversationPath: ConversationPath?, | ||
isHeaderVisible: Bool, | ||
retryButtonAction: (() -> Void)?, | ||
messagesService: MessagesService = MessagesServiceFactory.shared, | ||
userSession: UserSession = .shared | ||
) { | ||
self.course = course | ||
self.conversationPath = conversationPath | ||
self.isHeaderVisible = isHeaderVisible | ||
self.retryButtonAction = retryButtonAction | ||
self.messagesService = messagesService | ||
self.userSession = userSession | ||
} | ||
} | ||
|
||
extension MessageCellModel { | ||
// MARK: View | ||
|
||
func isChipVisible(creationDate: Date, authorId: Int64?) -> Bool { | ||
guard let lastReadDate = conversationPath?.conversation?.baseConversation.lastReadDate else { | ||
return false | ||
} | ||
|
||
return lastReadDate < creationDate && userSession.user?.id != authorId | ||
} | ||
|
||
// MARK: Navigation | ||
|
||
func getOneToOneChatOrCreate(login: String) async -> Conversation? { | ||
async let conversations = messagesService.getConversations(for: course.id) | ||
async let chat = messagesService.createOneToOneChat(for: course.id, usernames: [login]) | ||
|
||
if let conversations = await conversations.value, | ||
let conversation = conversations.first(where: { conversation in | ||
guard case let .oneToOneChat(conversation) = conversation, | ||
let members = conversation.members else { | ||
return false | ||
} | ||
return members.map(\.login).contains(login) | ||
}) { | ||
return conversation | ||
} else if let chat = await chat.value { | ||
return Conversation.oneToOneChat(conversation: chat) | ||
} | ||
|
||
return nil | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.