forum: project the forum's own channel with member state in getForumTopics
messages.getForumTopics returned every chat via tgChannels -> tgChannelChatMin, so the forum's own channel came back as a min object with left unset. A client with no other object for that peer (a fresh account browsing a public forum by username) then rendered the forum as already joined: topic list visible, no Join button, but no messages. Render the primary channel with tgChannelChatForView so a non-member preview carries left=true; keep the other referenced channels as min.
This commit is contained in:
parent
c8380b4257
commit
0991207802
2 changed files with 41 additions and 1 deletions
|
|
@ -474,12 +474,37 @@ func (r *Router) forumTopicsResponse(ctx context.Context, userID int64, view dom
|
|||
Count: count,
|
||||
Topics: topics,
|
||||
Messages: messages,
|
||||
Chats: tgChannels(userID, channels),
|
||||
Chats: r.forumTopicsChats(userID, view, channels),
|
||||
Users: r.tgUsersForIDs(ctx, userID, userIDs),
|
||||
Pts: view.Channel.Pts,
|
||||
})
|
||||
}
|
||||
|
||||
// forumTopicsChats projects the forum's own channel with the viewer's member
|
||||
// state (so a non-member preview carries left=true and the client still shows a
|
||||
// Join button) and every other referenced channel as a min chat. Rendering the
|
||||
// primary as a bare min chat lets a client that has no other object for the
|
||||
// channel treat the forum as already joined.
|
||||
func (r *Router) forumTopicsChats(userID int64, view domain.ChannelView, channels []domain.Channel) []tg.ChatClass {
|
||||
if view.Channel.ID == 0 {
|
||||
return tgChannels(userID, channels)
|
||||
}
|
||||
chats := make([]tg.ChatClass, 0, len(channels))
|
||||
chats = append(chats, tgChannelChatForView(userID, view))
|
||||
seen := map[int64]struct{}{view.Channel.ID: {}}
|
||||
for _, extra := range channels {
|
||||
if extra.ID == 0 {
|
||||
continue
|
||||
}
|
||||
if _, dup := seen[extra.ID]; dup {
|
||||
continue
|
||||
}
|
||||
seen[extra.ID] = struct{}{}
|
||||
chats = append(chats, tgChannelChatMin(userID, extra))
|
||||
}
|
||||
return chats
|
||||
}
|
||||
|
||||
func tgForumGeneralTopic(viewerUserID int64, view domain.ChannelView, topic domain.ChannelForumTopic) *tg.ForumTopic {
|
||||
return &tg.ForumTopic{
|
||||
My: view.Channel.CreatorUserID == viewerUserID && viewerUserID != 0,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue