-
Notifications
You must be signed in to change notification settings - Fork 357
/
contacts.unblock_handler.go
109 lines (96 loc) · 3.18 KB
/
contacts.unblock_handler.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
// Copyright 2022 Teamgram Authors
// All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// Author: teamgramio (teamgram.io@gmail.com)
//
package core
import (
"github.com/teamgram/proto/mtproto"
"github.com/teamgram/teamgram-server/app/messenger/sync/sync"
userpb "github.com/teamgram/teamgram-server/app/service/biz/user/user"
)
// ContactsUnblock
// contacts.unblock#bea65d50 id:InputPeer = Bool;
func (c *ContactsCore) ContactsUnblock(in *mtproto.TLContactsUnblock) (*mtproto.Bool, error) {
var (
mUsers *userpb.Vector_ImmutableUser
err error
unblockId = mtproto.FromInputPeer2(c.MD.UserId, in.GetId())
idHelper = mtproto.NewIDListHelper(c.MD.UserId)
)
if !unblockId.IsUser() || unblockId.IsSelf() {
err = mtproto.ErrPeerIdInvalid
c.Logger.Errorf("contacts.block - error: %v", err)
return nil, err
}
if unblockId.PeerId == c.MD.UserId {
err = mtproto.ErrContactIdInvalid
c.Logger.Errorf("contacts.block - error: %v", err)
return nil, err
}
// TODO
/*
auto BlockPeerBoxController::createRow(not_null<History*> history)
-> std::unique_ptr<BlockPeerBoxController::Row> {
if (!history->peer->isUser()
|| history->peer->isServiceUser()
|| history->peer->isSelf()
|| history->peer->isRepliesChat()) {
return nullptr;
}
auto row = std::make_unique<Row>(history);
updateIsBlocked(row.get(), history->peer);
return row;
}
*/
mUsers, err = c.svcCtx.Dao.UserClient.UserGetMutableUsers(c.ctx, &userpb.TLUserGetMutableUsers{
Id: []int64{c.MD.UserId, unblockId.PeerId},
})
// me, _ := users.GetImmutableUser(c.MD.UserId)
blocked, _ := mUsers.GetImmutableUser(unblockId.PeerId)
if blocked == nil {
err = mtproto.ErrContactIdInvalid
c.Logger.Errorf("contacts.unblock - error: %v", err)
return nil, err
} else if blocked.GetUser().GetDeleted() {
err = mtproto.ErrInputUserDeactivated
c.Logger.Errorf("contacts.unblock - error: %v", err)
return nil, err
}
c.svcCtx.Dao.UserClient.UserUnBlockPeer(c.ctx, &userpb.TLUserUnBlockPeer{
UserId: c.MD.UserId,
PeerType: unblockId.PeerType,
PeerId: unblockId.PeerId,
})
idHelper.AppendUsers(unblockId.PeerId)
syncUpdates := mtproto.MakeUpdatesByUpdates(mtproto.MakeTLUpdatePeerBlocked(&mtproto.Update{
PeerId: unblockId.ToPeer(),
Blocked: mtproto.BoolFalse,
}).To_Update())
idHelper.Visit(
func(userIdList []int64) {
syncUpdates.PushUser(mUsers.GetUserListByIdList(c.MD.UserId, userIdList...)...)
},
func(chatIdList []int64) {
},
func(channelIdList []int64) {
})
c.svcCtx.Dao.SyncClient.SyncUpdatesNotMe(c.ctx, &sync.TLSyncUpdatesNotMe{
UserId: c.MD.UserId,
AuthKeyId: c.MD.AuthId,
Updates: syncUpdates,
})
return mtproto.BoolTrue, nil
}