Skip to content

Commit

Permalink
Merge pull request #96 from ls1intum/develop
Browse files Browse the repository at this point in the history
`General`: Navigate to mentions in messages (#95)
  • Loading branch information
nityanandaz authored Mar 25, 2024
2 parents fd30c47 + 1aeed8b commit c7946f2
Show file tree
Hide file tree
Showing 12 changed files with 205 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/ls1intum/artemis-ios-core-modules",
"state" : {
"branch" : "release-candidate/10.0.0",
"revision" : "ac82b556d645bf22b37713e2ff00f1e6c88cbab6"
"revision" : "969303b0a2ab90a4a7150accc3d18764b9bde37f",
"version" : "10.0.0"
}
},
{
Expand Down Expand Up @@ -194,8 +194,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/jpsim/Yams.git",
"state" : {
"revision" : "0d9ee7ea8c4ebd4a489ad7a73d5c6cad55d6fed3",
"version" : "5.0.6"
"revision" : "8a835d918245ca22f36663dd3862138805d7f707",
"version" : "5.1.0"
}
}
],
Expand Down
2 changes: 1 addition & 1 deletion ArtemisKit/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ let package = Package(
.package(url: "https://github.com/daltoniam/Starscream.git", exact: "4.0.4"),
.package(url: "https://github.com/Kelvas09/EmojiPicker.git", from: "1.0.0"),
.package(url: "https://github.com/ls1intum/apollon-ios-module", .upToNextMajor(from: "1.0.2")),
.package(url: "https://github.com/ls1intum/artemis-ios-core-modules", branch: "release-candidate/10.0.0"),
.package(url: "https://github.com/ls1intum/artemis-ios-core-modules", .upToNextMajor(from: "10.0.0")),
.package(url: "https://github.com/mac-cain13/R.swift.git", from: "7.0.0")
],
targets: [
Expand Down
1 change: 0 additions & 1 deletion ArtemisKit/Sources/Dashboard/CourseGridCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
// Created by Nityananda Zbil on 19.03.24.
//

import Charts
import DesignLibrary
import Navigation
import SharedModels
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,9 @@ extension ConversationViewModel {
case let .done(response: response):
// Keep existing members in new, i.e., update existing members in messages.
messages = Set(response.map(IdentifiableMessage.init)).union(messages)
if response.count < MessagesServiceImpl.GetMessagesRequest.size {
if page > 0, response.count < MessagesServiceImpl.GetMessagesRequest.size {
page -= 1
}
log.error(page)
diff = 0
case let .failure(error: error):
presentError(userFacingError: error)
Expand Down
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
}
}
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
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ private struct MessageCellWrapper: View {

var body: some View {
MessageCell(
viewModel: viewModel,
conversationViewModel: viewModel,
message: messageBinding,
conversationPath: conversationPath,
isHeaderVisible: isHeaderVisible)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ struct ConversationOfflineSection: View {
var body: some View {
Group {
MessageCell(
viewModel: conversationViewModel,
conversationViewModel: conversationViewModel,
message: Binding.constant(DataState<BaseMessage>.done(response: OfflineMessageOrAnswer(viewModel.message))),
conversationPath: nil,
isHeaderVisible: viewModel.taskDidFail,
Expand All @@ -30,7 +30,7 @@ struct ConversationOfflineSection: View {
}
ForEach(viewModel.messageQueue) { message in
MessageCell(
viewModel: conversationViewModel,
conversationViewModel: conversationViewModel,
message: Binding.constant(DataState<BaseMessage>.done(response: OfflineMessageOrAnswer(message))),
conversationPath: nil,
isHeaderVisible: false
Expand Down
Loading

0 comments on commit c7946f2

Please sign in to comment.