channels: force pre-history visible when a group gets a public username
New supergroups are created with "chat history for new members" hidden (the client sets this right after creation, matching official Telegram). The official server then forces it back to visible when the group is made public; owpengram's UpdateUsername left the flag alone, leaving public groups in a state where non-members (and post-join members) see no history at all. UpdateUsername now clears pre_history_hidden whenever a non-empty username is assigned, in the same transaction, with a matching admin-log event. Removing the username leaves the flag untouched, so the creator can hide history again once the group is private. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
parent
c376262cff
commit
df15c3ffb3
3 changed files with 90 additions and 1 deletions
|
|
@ -2761,6 +2761,61 @@ func TestChannelUsernameAndSignatures(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestUpdateUsernameForcesPreHistoryVisible(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
const ownerID int64 = 1001
|
||||
service := NewService(memory.NewChannelStore())
|
||||
created, err := service.CreateMegagroupFromCreateChat(ctx, ownerID, domain.CreateChannelRequest{
|
||||
Title: "Private First",
|
||||
MemberUserIDs: []int64{1002},
|
||||
Date: 10,
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("CreateMegagroupFromCreateChat: %v", err)
|
||||
}
|
||||
|
||||
hidden, err := service.SetPreHistoryHidden(ctx, ownerID, created.Channel.ID, true)
|
||||
if err != nil {
|
||||
t.Fatalf("SetPreHistoryHidden: %v", err)
|
||||
}
|
||||
if !hidden.PreHistoryHidden {
|
||||
t.Fatalf("hidden channel = %+v, want pre-history hidden", hidden)
|
||||
}
|
||||
|
||||
// Assigning a public username must force pre-history back to visible.
|
||||
public, err := service.UpdateUsername(ctx, ownerID, domain.UpdateChannelUsernameRequest{
|
||||
ChannelID: created.Channel.ID,
|
||||
Username: "private_first_pub",
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("UpdateUsername: %v", err)
|
||||
}
|
||||
if public.PreHistoryHidden {
|
||||
t.Fatalf("public channel = %+v, want pre-history visible after publish", public)
|
||||
}
|
||||
|
||||
// Removing the username leaves the flag alone (still visible).
|
||||
private, err := service.UpdateUsername(ctx, ownerID, domain.UpdateChannelUsernameRequest{
|
||||
ChannelID: created.Channel.ID,
|
||||
Username: "",
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("UpdateUsername clear: %v", err)
|
||||
}
|
||||
if private.PreHistoryHidden {
|
||||
t.Fatalf("re-privated channel = %+v, want pre-history still visible", private)
|
||||
}
|
||||
|
||||
// ...and the creator can hide it again once private.
|
||||
rehidden, err := service.SetPreHistoryHidden(ctx, ownerID, created.Channel.ID, true)
|
||||
if err != nil {
|
||||
t.Fatalf("SetPreHistoryHidden after re-privating: %v", err)
|
||||
}
|
||||
if !rehidden.PreHistoryHidden {
|
||||
t.Fatalf("re-hidden channel = %+v, want pre-history hidden again", rehidden)
|
||||
}
|
||||
}
|
||||
|
||||
func TestListStoryPostableChannelsFiltersPostStoryRights(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
service := NewService(memory.NewChannelStore())
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue