Skip to content

Commit

Permalink
support noforwards in chat
Browse files Browse the repository at this point in the history
  • Loading branch information
wubenqi committed Apr 12, 2022
1 parent 003cb6d commit c2362a8
Show file tree
Hide file tree
Showing 20 changed files with 1,933 additions and 1,275 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ cd teamgram-server
mysql -uroot teamgram < teamgramd/sql/migrate_20220326.sql
mysql -uroot teamgram < teamgramd/sql/migrate_20220328.sql
mysql -uroot teamgram < teamgramd/sql/migrate_20220401.sql
mysql -uroot teamgram < teamgramd/sql/migrate_20220412.sql
```

- init minio buckets, bucket names:
Expand Down
16 changes: 9 additions & 7 deletions app/bff/bff/internal/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,13 +156,15 @@ func (s *Server) Initialize() error {
// contacts_helper
mtproto.RegisterRPCContactsServer(
grpcServer,
contacts_helper.New(contacts_helper.Config{
RpcServerConf: c.RpcServerConf,
UserClient: c.BizServiceClient,
ChatClient: c.BizServiceClient,
UsernameClient: c.BizServiceClient,
SyncClient: c.SyncClient,
}, nil))
contacts_helper.New(
contacts_helper.Config{
RpcServerConf: c.RpcServerConf,
UserClient: c.BizServiceClient,
ChatClient: c.BizServiceClient,
UsernameClient: c.BizServiceClient,
SyncClient: c.SyncClient,
},
nil))

// dialogs_helper
mtproto.RegisterRPCDialogsServer(
Expand Down
19 changes: 19 additions & 0 deletions app/bff/messages/internal/core/messages.forwardMessages_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"github.com/gogo/protobuf/types"
"github.com/teamgram/proto/mtproto"
msgpb "github.com/teamgram/teamgram-server/app/messenger/msg/msg/msg"
chatpb "github.com/teamgram/teamgram-server/app/service/biz/chat/chat"
"github.com/teamgram/teamgram-server/app/service/biz/message/message"
userpb "github.com/teamgram/teamgram-server/app/service/biz/user/user"
"github.com/teamgram/teamgram-server/app/service/biz/username/username"
Expand Down Expand Up @@ -168,6 +169,24 @@ func (c *MessagesCore) makeForwardMessages(
UserId: c.MD.UserId,
IdList: idList,
})
if messageList.Length() > 0 {
msgBox0 := messageList.Datas[0]
if msgBox0.PeerType == mtproto.PEER_CHAT {
chat, err := c.svcCtx.Dao.ChatClient.ChatGetMutableChat(c.ctx, &chatpb.TLChatGetMutableChat{
ChatId: msgBox0.PeerId,
})
if err != nil {
c.Logger.Errorf("messages.forwardMessages - error: %v", err)
return nil, err
}

if chat.Noforwards() {
err = mtproto.ErrChatForwardsRestricted
c.Logger.Errorf("messages.forwardMessages - error: %v", err)
return nil, err
}
}
}
}

fwdOutboxList := make([]*msgpb.OutboxMessage, 0, int(messageList.Length()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,38 @@ package core

import (
"github.com/teamgram/proto/mtproto"
chatpb "github.com/teamgram/teamgram-server/app/service/biz/chat/chat"
)

// MessagesToggleNoForwards
// messages.toggleNoForwards#b11eafa2 peer:InputPeer enabled:Bool = Updates;
func (c *MessagesCore) MessagesToggleNoForwards(in *mtproto.TLMessagesToggleNoForwards) (*mtproto.Updates, error) {
// TODO: not impl
c.Logger.Errorf("messages.toggleNoForwards blocked, License key from https://teamgram.net required to unlock enterprise features.")
var (
peer = mtproto.FromInputPeer2(c.MD.UserId, in.Peer)
rUpdates *mtproto.Updates
)

return nil, mtproto.ErrEnterpriseIsBlocked
if !peer.IsChat() {
err := mtproto.ErrPeerIdInvalid
c.Logger.Errorf("messages.toggleNoForwards - error: %v", err)
return nil, err
}

chat, err := c.svcCtx.Dao.ChatClient.ChatToggleNoForwards(c.ctx, &chatpb.TLChatToggleNoForwards{
ChatId: peer.PeerId,
OperatorId: c.MD.UserId,
Enabled: in.Enabled,
})
if err != nil {
c.Logger.Errorf("messages.toggleNoForwards - error: %v", err)
return nil, err
}

rUpdates = mtproto.MakeUpdatesByUpdatesChats(
[]*mtproto.Chat{chat.ToUnsafeChat(c.MD.UserId)},
mtproto.MakeTLUpdateChat(&mtproto.Update{
ChatId_INT64: peer.PeerId,
}).To_Update())

return rUpdates, nil
}
2,427 changes: 1,416 additions & 1,011 deletions app/service/biz/chat/chat/chat.tl.pb.go

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions app/service/biz/chat/chat/class_name_registers.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const (
Predicate_chat_editChatDefaultBannedRights = "chat_editChatDefaultBannedRights"
Predicate_chat_addChatUser = "chat_addChatUser"
Predicate_chat_getMutableChatByLink = "chat_getMutableChatByLink"
Predicate_chat_toggleNoForwards = "chat_toggleNoForwards"
Predicate_chat_migratedToChannel = "chat_migratedToChannel"
Predicate_chat_getChatParticipantIdList = "chat_getChatParticipantIdList"
Predicate_chat_getUsersChatIdList = "chat_getUsersChatIdList"
Expand Down Expand Up @@ -124,6 +125,10 @@ var clazzNameRegisters2 = map[string]map[int]int32{
Predicate_chat_getMutableChatByLink: {
0: -1570363509, // 0xa266278b

},
Predicate_chat_toggleNoForwards: {
0: -711644423, // 0xd5952af9

},
Predicate_chat_migratedToChannel: {
0: 138390239, // 0x83faadf
Expand Down Expand Up @@ -208,6 +213,7 @@ var clazzIdNameRegisters2 = map[int32]string{
1513399943: Predicate_chat_editChatDefaultBannedRights, // 0x5a34a687
2086511757: Predicate_chat_addChatUser, // 0x7c5da48d
-1570363509: Predicate_chat_getMutableChatByLink, // 0xa266278b
-711644423: Predicate_chat_toggleNoForwards, // 0xd5952af9
138390239: Predicate_chat_migratedToChannel, // 0x83faadf
848700073: Predicate_chat_getChatParticipantIdList, // 0x329622a9
792111948: Predicate_chat_getUsersChatIdList, // 0x2f36ab4c
Expand Down
Loading

0 comments on commit c2362a8

Please sign in to comment.