fix: sync latest channel and contact fixes
This commit is contained in:
parent
e83650b9fd
commit
35e5d38f4d
11 changed files with 255 additions and 81 deletions
|
|
@ -135,20 +135,9 @@ func TestPublicChannelPreviewRPCsAllowNonMember(t *testing.T) {
|
|||
if err != nil {
|
||||
t.Fatalf("non-member getChannelDifference public preview: %v", err)
|
||||
}
|
||||
fullDiff, ok := diff.(*tg.UpdatesChannelDifference)
|
||||
if !ok || !fullDiff.Final || fullDiff.Pts != sent.Event.Pts || len(fullDiff.NewMessages) != 1 {
|
||||
t.Fatalf("channel difference = %T %+v, want one public preview message at current pts", diff, diff)
|
||||
}
|
||||
diffMsg, ok := fullDiff.NewMessages[0].(*tg.Message)
|
||||
if !ok || diffMsg.Message != "public preview rpc post" {
|
||||
t.Fatalf("channel difference message = %T %+v, want public preview rpc post", fullDiff.NewMessages[0], fullDiff.NewMessages[0])
|
||||
}
|
||||
if len(fullDiff.Chats) != 1 {
|
||||
t.Fatalf("channel difference chats = %d, want public channel chat", len(fullDiff.Chats))
|
||||
}
|
||||
diffChat, ok := fullDiff.Chats[0].(*tg.Channel)
|
||||
if !ok || !diffChat.Left || diffChat.ID != public.Channel.ID {
|
||||
t.Fatalf("channel difference chat = %T %+v, want left public channel", fullDiff.Chats[0], fullDiff.Chats[0])
|
||||
emptyDiff, ok := diff.(*tg.UpdatesChannelDifferenceEmpty)
|
||||
if !ok || !emptyDiff.Final || emptyDiff.Pts != sent.Event.Pts {
|
||||
t.Fatalf("channel difference = %T %+v, want empty public preview difference at current pts", diff, diff)
|
||||
}
|
||||
|
||||
domainPeers, err := r.dialogPeersFromInput(WithUserID(ctx, viewer.ID), viewer.ID, []tg.InputDialogPeerClass{&tg.InputDialogPeer{Peer: peer}})
|
||||
|
|
@ -162,8 +151,8 @@ func TestPublicChannelPreviewRPCsAllowNonMember(t *testing.T) {
|
|||
if err != nil {
|
||||
t.Fatalf("dialog service public preview: %v", err)
|
||||
}
|
||||
if len(directPeerDialogs.Dialogs) != 1 || len(directPeerDialogs.ChannelMessages) != 1 || len(directPeerDialogs.Channels) != 1 {
|
||||
t.Fatalf("direct peer dialogs = %+v, want one dialog/message/channel", directPeerDialogs)
|
||||
if len(directPeerDialogs.Dialogs) != 0 || len(directPeerDialogs.ChannelMessages) != 0 || len(directPeerDialogs.Channels) != 0 {
|
||||
t.Fatalf("direct peer dialogs = %+v, want no public preview dialog/message/channel", directPeerDialogs)
|
||||
}
|
||||
|
||||
peerDialogsReq := &tg.MessagesGetPeerDialogsRequest{
|
||||
|
|
@ -181,20 +170,8 @@ func TestPublicChannelPreviewRPCsAllowNonMember(t *testing.T) {
|
|||
if !ok {
|
||||
t.Fatalf("getPeerDialogs response = %T, want peer dialogs", peerDialogsEnc)
|
||||
}
|
||||
if len(peerDialogs.Dialogs) != 1 || len(peerDialogs.Messages) != 1 || len(peerDialogs.Chats) != 1 {
|
||||
t.Fatalf("peer dialogs = %+v, want one dialog/message/channel", peerDialogs)
|
||||
}
|
||||
tgDialog, ok := peerDialogs.Dialogs[0].(*tg.Dialog)
|
||||
if !ok || tgDialog.TopMessage <= 0 || tgDialog.UnreadCount != 0 {
|
||||
t.Fatalf("peer dialog = %T %+v, want read-only public preview dialog", peerDialogs.Dialogs[0], peerDialogs.Dialogs[0])
|
||||
}
|
||||
tgMessage, ok := peerDialogs.Messages[0].(*tg.Message)
|
||||
if !ok || tgMessage.Message != "public preview rpc post" {
|
||||
t.Fatalf("peer dialog message = %T %+v, want public preview rpc post", peerDialogs.Messages[0], peerDialogs.Messages[0])
|
||||
}
|
||||
peerDialogChat, ok := peerDialogs.Chats[0].(*tg.Channel)
|
||||
if !ok || !peerDialogChat.Left || peerDialogChat.ID != public.Channel.ID {
|
||||
t.Fatalf("peer dialog chat = %T %+v, want left public channel", peerDialogs.Chats[0], peerDialogs.Chats[0])
|
||||
if len(peerDialogs.Dialogs) != 0 || len(peerDialogs.Messages) != 0 || len(peerDialogs.Chats) != 0 {
|
||||
t.Fatalf("peer dialogs = %+v, want no public preview dialog/message/channel", peerDialogs)
|
||||
}
|
||||
|
||||
if _, err := channelService.JoinChannel(ctx, viewer.ID, public.Channel.ID, 1700010120); err != nil {
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ import (
|
|||
"strings"
|
||||
appchannels "telesrv/internal/app/channels"
|
||||
appcontacts "telesrv/internal/app/contacts"
|
||||
appprivacy "telesrv/internal/app/privacy"
|
||||
appstories "telesrv/internal/app/stories"
|
||||
appupdates "telesrv/internal/app/updates"
|
||||
appusers "telesrv/internal/app/users"
|
||||
|
|
@ -1057,6 +1058,84 @@ func TestContactsAcceptContactReturnsSettingsAndReset(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestContactsAddContactPhonePrivacyExceptionUpdatesPeerSettings(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
userStore := memory.NewUserStore()
|
||||
contactsStore := memory.NewContactStore()
|
||||
privacySvc := appprivacy.NewService(memory.NewPrivacyStore(), contactsStore)
|
||||
alice, err := userStore.Create(ctx, domain.User{AccessHash: 31, Phone: "2001", FirstName: "Alice", LastName: "A"})
|
||||
if err != nil {
|
||||
t.Fatalf("create alice: %v", err)
|
||||
}
|
||||
bob, err := userStore.Create(ctx, domain.User{AccessHash: 32, Phone: "2002", FirstName: "Bob", LastName: "B"})
|
||||
if err != nil {
|
||||
t.Fatalf("create bob: %v", err)
|
||||
}
|
||||
carol, err := userStore.Create(ctx, domain.User{AccessHash: 33, Phone: "2003", FirstName: "Carol", LastName: "C"})
|
||||
if err != nil {
|
||||
t.Fatalf("create carol: %v", err)
|
||||
}
|
||||
contactsSvc := appcontacts.NewService(contactsStore, userStore).Configure(appcontacts.WithPrivacyEvaluator(privacySvc))
|
||||
usersSvc := appusers.NewService(userStore, appusers.WithContactStore(contactsStore), appusers.WithPrivacyEvaluator(privacySvc))
|
||||
r := New(Config{}, Deps{
|
||||
Contacts: contactsSvc,
|
||||
Users: usersSvc,
|
||||
}, zaptest.NewLogger(t), fixedClock{now: time.Unix(1700000410, 0)})
|
||||
|
||||
withoutException, err := r.onContactsAddContact(WithUserID(ctx, alice.ID), &tg.ContactsAddContactRequest{
|
||||
ID: &tg.InputUser{UserID: bob.ID, AccessHash: bob.AccessHash},
|
||||
Phone: bob.Phone,
|
||||
FirstName: "Bobby",
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("contacts.addContact without exception: %v", err)
|
||||
}
|
||||
bobSettings := firstPeerSettingsUpdate(t, withoutException)
|
||||
if bobSettings.Settings.AddContact || !bobSettings.Settings.ShareContact || !bobSettings.Settings.NeedContactsException {
|
||||
t.Fatalf("bob peer settings = %+v, want share + need exception", bobSettings.Settings)
|
||||
}
|
||||
if allowed, err := privacySvc.CanSee(ctx, alice.ID, bob.ID, domain.PrivacyKeyPhoneNumber); err != nil {
|
||||
t.Fatalf("bob can see alice phone: %v", err)
|
||||
} else if allowed {
|
||||
t.Fatalf("bob can see alice phone = true, want false before exception")
|
||||
}
|
||||
|
||||
withException, err := r.onContactsAddContact(WithUserID(ctx, alice.ID), &tg.ContactsAddContactRequest{
|
||||
AddPhonePrivacyException: true,
|
||||
ID: &tg.InputUser{UserID: carol.ID, AccessHash: carol.AccessHash},
|
||||
Phone: carol.Phone,
|
||||
FirstName: "Carol",
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("contacts.addContact with exception: %v", err)
|
||||
}
|
||||
carolSettings := firstPeerSettingsUpdate(t, withException)
|
||||
if carolSettings.Settings.AddContact || carolSettings.Settings.ShareContact || carolSettings.Settings.NeedContactsException {
|
||||
t.Fatalf("carol peer settings = %+v, want no add/share/need exception", carolSettings.Settings)
|
||||
}
|
||||
if allowed, err := privacySvc.CanSee(ctx, alice.ID, carol.ID, domain.PrivacyKeyPhoneNumber); err != nil {
|
||||
t.Fatalf("carol can see alice phone: %v", err)
|
||||
} else if !allowed {
|
||||
t.Fatalf("carol can see alice phone = false, want true after exception")
|
||||
}
|
||||
}
|
||||
|
||||
func firstPeerSettingsUpdate(t *testing.T, updates tg.UpdatesClass) *tg.UpdatePeerSettings {
|
||||
t.Helper()
|
||||
got, ok := updates.(*tg.Updates)
|
||||
if !ok {
|
||||
t.Fatalf("updates = %T, want *tg.Updates", updates)
|
||||
}
|
||||
if len(got.Updates) == 0 {
|
||||
t.Fatalf("updates = %+v, want UpdatePeerSettings", got.Updates)
|
||||
}
|
||||
settings, ok := got.Updates[0].(*tg.UpdatePeerSettings)
|
||||
if !ok {
|
||||
t.Fatalf("update[0] = %T, want UpdatePeerSettings", got.Updates[0])
|
||||
}
|
||||
return settings
|
||||
}
|
||||
|
||||
func TestContactsStatusesUsesOnlineSessionFallback(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
alice := domain.User{ID: 1000000001, AccessHash: 11, FirstName: "Alice"}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue