Skip to content

Commit

Permalink
0.3.14 Markdown in the announcements feed
Browse files Browse the repository at this point in the history
  • Loading branch information
ElectricS01 committed Nov 13, 2024
1 parent 03a6737 commit 692012a
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 64 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public class StateQuery: GraphQLQuery {
public static let operationName: String = "StateQuery"
public static let operationDocument: ApolloAPI.OperationDocument = .init(
definition: .init(
#"query StateQuery { coreState { __typename announcements { __typename userId content type id createdAt user { __typename username id avatar } } stats { __typename users collections collectionItems uploads messages chats } } currentUser { __typename username description administrator emailVerified banned createdAt avatar moderator banner status storedStatus privacyPolicyAccepted domain { __typename active domain id } badges { __typename color icon id image name priority tooltip } id notifications { __typename id dismissed message route createdAt } } trackedUsers { __typename username id avatar blocked status bot nickname { __typename nickname } friends { __typename friendId id status userId } } }"#
#"query StateQuery { coreState { __typename announcements { __typename userId content createdAt user { __typename username id avatar } } stats { __typename users collections collectionItems uploads messages chats } } currentUser { __typename username description administrator emailVerified banned createdAt avatar moderator banner status storedStatus privacyPolicyAccepted domain { __typename active domain id } badges { __typename color icon id image name priority tooltip } id notifications { __typename id dismissed message route createdAt } } trackedUsers { __typename username id avatar blocked status bot nickname { __typename nickname } friends { __typename friendId id status userId } } }"#
))

public init() {}
Expand Down Expand Up @@ -56,16 +56,12 @@ public class StateQuery: GraphQLQuery {
.field("__typename", String.self),
.field("userId", Int?.self),
.field("content", String.self),
.field("type", String?.self),
.field("id", Int.self),
.field("createdAt", PrivateUploaderAPI.Date?.self),
.field("user", User?.self),
] }

public var userId: Int? { __data["userId"] }
public var content: String { __data["content"] }
public var type: String? { __data["type"] }
public var id: Int { __data["id"] }
public var createdAt: PrivateUploaderAPI.Date? { __data["createdAt"] }
public var user: User? { __data["user"] }

Expand Down
4 changes: 2 additions & 2 deletions TPU_Mac.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,7 @@
LD_RUNPATH_SEARCH_PATHS = "@executable_path/Frameworks";
"LD_RUNPATH_SEARCH_PATHS[sdk=macosx*]" = "@executable_path/../Frameworks";
MACOSX_DEPLOYMENT_TARGET = 14.0;
MARKETING_VERSION = 0.3.13;
MARKETING_VERSION = 0.3.14;
PRODUCT_BUNDLE_IDENTIFIER = "ElectricS01.TPU-Mac";
PRODUCT_NAME = "$(TARGET_NAME)";
SDKROOT = auto;
Expand Down Expand Up @@ -566,7 +566,7 @@
LD_RUNPATH_SEARCH_PATHS = "@executable_path/Frameworks";
"LD_RUNPATH_SEARCH_PATHS[sdk=macosx*]" = "@executable_path/../Frameworks";
MACOSX_DEPLOYMENT_TARGET = 14.0;
MARKETING_VERSION = 0.3.13;
MARKETING_VERSION = 0.3.14;
PRODUCT_BUNDLE_IDENTIFIER = "ElectricS01.TPU-Mac";
PRODUCT_NAME = "$(TARGET_NAME)";
SDKROOT = auto;
Expand Down
51 changes: 0 additions & 51 deletions TPU_Mac/CommsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ struct CommsView: View {
@State private var editingMessage: String = ""
@State var apolloSubscription: Apollo.Cancellable?
@State private var notifications: Int = 0
// @State private var hoverItem = -1

func getChats() {
Network.shared.apollo.fetch(query: ChatsQuery(), cachePolicy: .fetchIgnoringCacheData) { result in
Expand All @@ -43,56 +42,6 @@ struct CommsView: View {
}
}

func convertToMessage(subscriptionObject: UpdateMessagesSubscription.Data.OnMessage.Message) -> MessagesQuery.Data.Message {
var messageData = DataDict(data: [:], fulfilledFragments: Set<ObjectIdentifier>())

messageData["id"] = subscriptionObject.id
messageData["createdAt"] = subscriptionObject.createdAt
messageData["updatedAt"] = subscriptionObject.updatedAt
messageData["chatId"] = subscriptionObject.chatId
messageData["userId"] = subscriptionObject.userId
messageData["content"] = subscriptionObject.content
messageData["type"] = subscriptionObject.type
messageData["emoji"] = subscriptionObject.emoji
messageData["embeds"] = subscriptionObject.embeds
messageData["reply"] = subscriptionObject.reply
messageData["user"] = subscriptionObject.user
messageData["edited"] = subscriptionObject.edited
messageData["editedAt"] = subscriptionObject.editedAt
messageData["replyId"] = subscriptionObject.replyId
messageData["pinned"] = subscriptionObject.pinned
messageData["readReceipts"] = subscriptionObject.readReceipts

let message = MessagesQuery.Data.Message(_dataDict: messageData)

return message
}

func editToMessage(messageObject: MessagesQuery.Data.Message, editObject: EditedMessageSubscription.Data.OnEditMessage.Message) -> MessagesQuery.Data.Message {
var messageData = DataDict(data: [:], fulfilledFragments: Set<ObjectIdentifier>())

messageData["id"] = editObject.id
messageData["createdAt"] = messageObject.createdAt
messageData["updatedAt"] = messageObject.updatedAt
messageData["chatId"] = messageObject.chatId
messageData["userId"] = editObject.userId
messageData["content"] = editObject.content
messageData["type"] = messageObject.type
messageData["emoji"] = editObject.emoji
messageData["embeds"] = editObject.embeds
messageData["reply"] = messageObject.reply
messageData["user"] = messageObject.user
messageData["edited"] = editObject.edited
messageData["editedAt"] = editObject.editedAt
messageData["replyId"] = messageObject.replyId
messageData["pinned"] = editObject.pinned
messageData["readReceipts"] = messageObject.readReceipts

let message = MessagesQuery.Data.Message(_dataDict: messageData)

return message
}

func newToChat(chatObject: ChatsQuery.Data.Chat, self: Bool) -> ChatsQuery.Data.Chat {
var chatData = DataDict(data: [:], fulfilledFragments: Set<ObjectIdentifier>())

Expand Down
27 changes: 23 additions & 4 deletions TPU_Mac/HomeView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
//

import Apollo
import MarkdownUI
import PrivateUploaderAPI
import SwiftUI

Expand All @@ -23,6 +24,27 @@ struct HomeStat: View {
}
}

struct NewsItem: View {
@Binding var item: StateQuery.Data.CoreState.Announcement

var body: some View {
ProfilePicture(avatar: item.user?.avatar, size: 48)
Text(item.user?.username ?? "Deleted User").font(.system(size: 16, weight: .semibold))
Markdown(item.content)
.markdownSoftBreakMode(.lineBreak)
.textSelection(.enabled)
.markdownBlockStyle(\.blockquote) { configuration in
configuration.label
.padding(EdgeInsets(top: 2, leading: 8, bottom: 2, trailing: 2))
.overlay(alignment: .leading) {
Rectangle().frame(width: 2)
}
}
.multilineTextAlignment(.center)
Text(DateUtils.dateFormat(item.createdAt))
}
}

struct HomeView: View {
@EnvironmentObject var store: Store

Expand All @@ -37,10 +59,7 @@ struct HomeView: View {
Text("Announcments").font(.system(size: 24, weight: .semibold))
ScrollView {
ForEach(store.coreState?.announcements ?? [], id: \.self) { item in
ProfilePicture(avatar: item.user?.avatar, size: 48)
Text(item.user?.username ?? "Deleted User").font(.system(size: 16, weight: .semibold))
Text(item.content).multilineTextAlignment(.center)
Text(DateUtils.dateFormat(item.createdAt))
NewsItem(item: .constant(item))
}.padding()
}
}.frame(maxHeight: .infinity)
Expand Down
2 changes: 0 additions & 2 deletions graphql/StateQuery.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ query StateQuery {
announcements {
userId
content
type
id
createdAt
user {
username
Expand Down

0 comments on commit 692012a

Please sign in to comment.