Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions app/Shared/Localization/zh-Hans.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,14 @@
"%@'s Posts" = "%@ 的回复";
"Posts" = "回复";
"My Profile" = "我的档案";
"Following" = "关注用户";
"Following Activity" = "关注动态";
"No Followed Users" = "还没有关注用户";
"No Following Activity" = "还没有关注动态";
"Follow" = "关注";
"Unfollow" = "取消关注";
"Posted a Reply" = "发表了回复";
"Published a Topic" = "发布了主题";
"Edit Favorites" = "编辑收藏";
"Posting" = "发表";
"Device Identity" = "设备身份";
Expand Down
101 changes: 101 additions & 0 deletions app/Shared/Views/FollowListView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
import SwiftUI

struct FollowUserListView: View {
typealias DataSource = PagingDataSource<FollowUserListResponse, User>

@StateObject private var dataSource: DataSource

init() {
_dataSource = StateObject(wrappedValue: DataSource(
buildRequest: { page in
.followUserList(.with { $0.page = UInt32(page) })
},
onResponse: { ($0.users, Int($0.pages)) },
id: \.id,
))
}

var body: some View {
List {
if dataSource.notLoaded {
LoadingRowView().onAppear { dataSource.initialLoad() }
} else if dataSource.items.isEmpty {
EmptyRowView(title: "No Followed Users")
} else {
ForEach(dataSource.items, id: \.id) { user in
NavigationLink(destination: UserProfileView.build(user: user)) {
UserView(user: user, style: .normal)
}
.onAppear { dataSource.loadMoreIfNeeded(currentItem: user) }
}
}
}
.refreshable { await dataSource.refreshAsync(animated: true) }
.mayGroupedListStyle()
.navigationTitle("Following")
}
}

struct FollowActivityRowView: View {
let activity: FollowActivity

var destination: some View {
let postID: PostId? = activity.hasPost ? activity.post.id : nil
return TopicDetailsView.build(topicBinding: .constant(activity.topic), onlyPost: (postID, nil))
}

var body: some View {
CrossStackNavigationLinkHack(destination: destination, id: activity.id) {
VStack(alignment: .leading, spacing: 8) {
HStack {
UserView(user: activity.user, style: .compact)
Spacer()
Text(activity.type == .reply ? "Posted a Reply" : "Published a Topic")
.font(.caption)
.foregroundStyle(.secondary)
}

if activity.hasPost {
TopicPostRowView(topic: activity.topic, post: activity.post)
} else {
TopicRowView(topic: activity.topic, useTopicPostDate: true, dimmedSubject: false)
}
}
.padding(.vertical, 2)
}
}
}

struct FollowActivityListView: View {
typealias DataSource = PagingDataSource<FollowActivityListResponse, FollowActivity>

@StateObject private var dataSource: DataSource

init() {
_dataSource = StateObject(wrappedValue: DataSource(
buildRequest: { page in
.followActivityList(.with { $0.page = UInt32(page) })
},
onResponse: { ($0.activities, Int($0.pages)) },
id: \.id,
))
}

var body: some View {
List {
if dataSource.notLoaded {
LoadingRowView().onAppear { dataSource.initialLoad() }
} else if dataSource.items.isEmpty {
EmptyRowView(title: "No Following Activity")
} else {
ForEach(dataSource.items, id: \.id) { activity in
FollowActivityRowView(activity: activity)
.onAppear { dataSource.loadMoreIfNeeded(currentItem: activity) }
}
}
}
.refreshable { await dataSource.refreshAsync(animated: true) }
.mayGroupedListStyle()
.navigationTitle("Following Activity")
}
}
6 changes: 6 additions & 0 deletions app/Shared/Views/UserMenuView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,12 @@ struct UserMenuView: View {
NavigationLink(destination: FavoriteTopicListView()) {
Label("Favorite Topics", systemImage: "bookmark")
}
NavigationLink(destination: FollowActivityListView()) {
Label("Following Activity", systemImage: "person.line.dotted.person.fill")
}
NavigationLink(destination: FollowUserListView()) {
Label("Following", systemImage: "person.2")
}
}
PlusCheckNavigationLink(destination: TopicHistoryListView.build(), feature: .topicHistory) {
Label("History", systemImage: "clock")
Expand Down
28 changes: 28 additions & 0 deletions app/Shared/Views/UserProfileView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ struct UserProfileView: View {
@StateObject var users = UsersModel.shared

@State var tab = Tab.topics
@State var isModifyingFollow = false

var isMyself: Bool {
user.id == currentUser.user?.id
Expand Down Expand Up @@ -135,6 +136,15 @@ struct UserProfileView: View {
}
}

if !isMyself, !user.isAnonymous {
ToolbarItem(placement: .navigationBarTrailing) {
Button(action: { modifyFollow() }) {
Label(user.followed ? "Unfollow" : "Follow", systemImage: user.followed ? "person.fill.checkmark" : "person.badge.plus")
}
.disabled(isModifyingFollow)
}
}

ToolbarItem(placement: .navigationBarTrailing) {
Menu {
if isMyself {
Expand Down Expand Up @@ -221,6 +231,24 @@ struct UserProfileView: View {
signaturePostModel.show(action: .init(userID: user.id, initialSignature: initial))
}

func modifyFollow() {
guard !isMyself, !user.isAnonymous, !isModifyingFollow else { return }
isModifyingFollow = true
Task {
let response: Result<FollowUserModifyResponse, LogicError> = await logicCallAsync(.followUserModify(.with {
$0.userID = user.id
$0.operation = user.followed ? .delete : .add
}))
switch response {
case let .success(response):
withAnimation { user.followed = response.followed }
case let .failure(error):
ToastModel.showAuto(.error(error.error))
}
isModifyingFollow = false
}
}

func reloadUser() async {
if let refreshed = await users.remoteUser(id: user.id, ignoreCache: true) {
withAnimation { user = refreshed }
Expand Down
8 changes: 7 additions & 1 deletion logic/service/src/dispatch/handlers_async.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ use crate::{
get_hot_topic_list, get_topic_details, get_topic_list, get_user_topic_list,
modify_favorite_folder, search_topic, topic_favor,
},
user::{get_remote_user, update_signature},
user::{
get_follow_activity_list, get_follow_user_list, get_remote_user, modify_follow_user,
update_signature,
},
};
use paste::paste;
use protos::Service::*;
Expand Down Expand Up @@ -61,3 +64,6 @@ handle!(topic_search, search_topic);
handle!(clock_in, clock_in);
handle!(cache, manipulate_cache);
handle!(user_signature_update, update_signature);
handle!(follow_user_modify, modify_follow_user);
handle!(follow_user_list, get_follow_user_list);
handle!(follow_activity_list, get_follow_activity_list);
3 changes: 3 additions & 0 deletions logic/service/src/dispatch/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ mod dispatch_async {
clock_in(r) => r!(handle_clock_in(r)),
cache(r) => r!(handle_cache(r)),
user_signature_update(r) => r!(handle_user_signature_update(r)),
follow_user_modify(r) => r!(handle_follow_user_modify(r)),
follow_user_list(r) => r!(handle_follow_user_list(r)),
follow_activity_list(r) => r!(handle_follow_activity_list(r)),
}
}
}
Expand Down
Loading