-
Notifications
You must be signed in to change notification settings - Fork 352
/
sync_mq_client.go
110 lines (94 loc) · 3.2 KB
/
sync_mq_client.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
110
// Copyright (c) 2021-present, Teamgram Studio (https://teamgram.io).
// All rights reserved.
//
// Author: teamgramio (teamgram.io@gmail.com)
//
package sync_client
import (
"context"
"fmt"
kafka "github.com/teamgram/marmota/pkg/mq"
"github.com/teamgram/proto/mtproto"
"github.com/teamgram/teamgram-server/app/messenger/sync/sync"
"github.com/gogo/protobuf/proto"
"github.com/zeromicro/go-zero/core/jsonx"
)
type defaultSyncMqClient struct {
cli *kafka.Producer
}
func NewSyncMqClient(cli *kafka.Producer) SyncClient {
return &defaultSyncMqClient{
cli: cli,
}
}
func (m *defaultSyncMqClient) sendMessage(ctx context.Context, k string, in interface{}) (*mtproto.Void, error) {
var (
b []byte
err error
)
b, err = jsonx.Marshal(in)
if err != nil {
return nil, err
}
_, _, err = m.cli.SendMessage(ctx, k, b)
if err != nil {
return nil, err
}
return mtproto.EmptyVoid, nil
}
// SyncUpdatesMe
// sync.updatesMe flags:# user_id:long auth_key_id:long server_id:string session_id:flags.0?long updates:Updates = Void;
func (m *defaultSyncMqClient) SyncUpdatesMe(ctx context.Context, in *sync.TLSyncUpdatesMe) (*mtproto.Void, error) {
return m.sendMessage(
ctx,
fmt.Sprintf("%s#%d", proto.MessageName(in), in.GetUserId()),
in)
}
// SyncUpdatesNotMe
// sync.updatesNotMe user_id:long auth_key_id:long updates:Updates = Void;
func (m *defaultSyncMqClient) SyncUpdatesNotMe(ctx context.Context, in *sync.TLSyncUpdatesNotMe) (*mtproto.Void, error) {
return m.sendMessage(
ctx,
fmt.Sprintf("%s#%d", proto.MessageName(in), in.GetUserId()),
in)
}
// SyncPushUpdates
// sync.pushUpdates user_id:long updates:Updates = Void;
func (m *defaultSyncMqClient) SyncPushUpdates(ctx context.Context, in *sync.TLSyncPushUpdates) (*mtproto.Void, error) {
return m.sendMessage(
ctx,
fmt.Sprintf("%s#%d", proto.MessageName(in), in.GetUserId()),
in)
}
// SyncPushUpdatesIfNot
// sync.pushUpdatesIfNot user_id:long excludes:Vector<long> updates:Updates = Void;
func (m *defaultSyncMqClient) SyncPushUpdatesIfNot(ctx context.Context, in *sync.TLSyncPushUpdatesIfNot) (*mtproto.Void, error) {
return m.sendMessage(
ctx,
fmt.Sprintf("%s#%d", proto.MessageName(in), in.GetUserId()),
in)
}
// SyncPushBotUpdates
// sync.pushBotUpdates user_id:long updates:Updates = Void;
func (m *defaultSyncMqClient) SyncPushBotUpdates(ctx context.Context, in *sync.TLSyncPushBotUpdates) (*mtproto.Void, error) {
return m.sendMessage(
ctx,
fmt.Sprintf("%s#%d", proto.MessageName(in), in.GetUserId()),
in)
}
// SyncPushRpcResult
// sync.pushRpcResult auth_key_id:long server_id:string session_id:long client_req_msg_id:long rpc_result:bytes = Void;
func (m *defaultSyncMqClient) SyncPushRpcResult(ctx context.Context, in *sync.TLSyncPushRpcResult) (*mtproto.Void, error) {
return m.sendMessage(
ctx,
fmt.Sprintf("%s#%d", proto.MessageName(in), in.GetAuthKeyId()),
in)
}
// SyncBroadcastUpdates
// sync.broadcastUpdates broadcast_type:int chat_id:long exclude_id_list:Vector<long> updates:Updates = Void;
func (m *defaultSyncMqClient) SyncBroadcastUpdates(ctx context.Context, in *sync.TLSyncBroadcastUpdates) (*mtproto.Void, error) {
return m.sendMessage(
ctx,
fmt.Sprintf("%s#%d", proto.MessageName(in), in.GetChatId()),
in)
}