-
Notifications
You must be signed in to change notification settings - Fork 247
/
messenger_config.go
409 lines (350 loc) · 10.8 KB
/
messenger_config.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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
package protocol
import (
"database/sql"
"encoding/json"
"github.com/status-im/status-go/account"
"github.com/status-im/status-go/rpc"
"github.com/status-im/status-go/server"
"github.com/status-im/status-go/services/browsers"
"github.com/status-im/status-go/services/communitytokens"
"github.com/status-im/status-go/wakuv2"
"go.uber.org/zap"
"github.com/status-im/status-go/appdatabase/migrations"
"github.com/status-im/status-go/multiaccounts"
"github.com/status-im/status-go/multiaccounts/accounts"
"github.com/status-im/status-go/multiaccounts/settings"
"github.com/status-im/status-go/params"
"github.com/status-im/status-go/protocol/anonmetrics"
"github.com/status-im/status-go/protocol/common"
"github.com/status-im/status-go/protocol/communities"
"github.com/status-im/status-go/protocol/discord"
"github.com/status-im/status-go/protocol/protobuf"
"github.com/status-im/status-go/protocol/pushnotificationclient"
"github.com/status-im/status-go/protocol/pushnotificationserver"
"github.com/status-im/status-go/protocol/transport"
"github.com/status-im/status-go/protocol/wakusync"
"github.com/status-im/status-go/services/mailservers"
"github.com/status-im/status-go/services/wallet"
)
type MessageDeliveredHandler func(string, string)
type MessengerSignalsHandler interface {
MessageDelivered(chatID string, messageID string)
CommunityInfoFound(community *communities.Community)
MessengerResponse(response *MessengerResponse)
HistoryRequestStarted(numBatches int)
HistoryRequestCompleted()
BackupPerformed(uint64)
HistoryArchivesProtocolEnabled()
HistoryArchivesProtocolDisabled()
CreatingHistoryArchives(communityID string)
NoHistoryArchivesCreated(communityID string, from int, to int)
HistoryArchivesCreated(communityID string, from int, to int)
HistoryArchivesSeeding(communityID string)
HistoryArchivesUnseeded(communityID string)
HistoryArchiveDownloaded(communityID string, from int, to int)
DownloadingHistoryArchivesStarted(communityID string)
DownloadingHistoryArchivesFinished(communityID string)
ImportingHistoryArchiveMessages(communityID string)
StatusUpdatesTimedOut(statusUpdates *[]UserStatus)
DiscordCategoriesAndChannelsExtracted(categories []*discord.Category, channels []*discord.Channel, oldestMessageTimestamp int64, errors map[string]*discord.ImportError)
DiscordCommunityImportProgress(importProgress *discord.ImportProgress)
DiscordCommunityImportFinished(communityID string)
DiscordCommunityImportCancelled(communityID string)
DiscordCommunityImportCleanedUp(communityID string)
DiscordChannelImportProgress(importProgress *discord.ImportProgress)
DiscordChannelImportFinished(communityID string, channelID string)
DiscordChannelImportCancelled(channelID string)
SendWakuFetchingBackupProgress(response *wakusync.WakuBackedUpDataResponse)
SendWakuBackedUpProfile(response *wakusync.WakuBackedUpDataResponse)
SendWakuBackedUpSettings(response *wakusync.WakuBackedUpDataResponse)
SendWakuBackedUpKeypair(response *wakusync.WakuBackedUpDataResponse)
SendWakuBackedUpWatchOnlyAccount(response *wakusync.WakuBackedUpDataResponse)
SendCuratedCommunitiesUpdate(response *communities.KnownCommunitiesResponse)
}
type config struct {
// systemMessagesTranslations holds translations for system-messages
systemMessagesTranslations *systemMessageTranslationsMap
// Config for the envelopes monitor
envelopesMonitorConfig *transport.EnvelopesMonitorConfig
featureFlags common.FeatureFlags
appDb *sql.DB
walletDb *sql.DB
afterDbCreatedHooks []Option
multiAccount *multiaccounts.Database
mailserversDatabase *mailservers.Database
account *multiaccounts.Account
clusterConfig params.ClusterConfig
browserDatabase *browsers.Database
torrentConfig *params.TorrentConfig
walletConfig *params.WalletConfig
walletService *wallet.Service
communityTokensService communitytokens.ServiceInterface
httpServer *server.MediaServer
rpcClient *rpc.Client
tokenManager communities.TokenManager
accountsManager account.Manager
verifyTransactionClient EthClient
verifyENSURL string
verifyENSContractAddress string
anonMetricsClientConfig *anonmetrics.ClientConfig
anonMetricsServerConfig *anonmetrics.ServerConfig
pushNotificationServerConfig *pushnotificationserver.Config
pushNotificationClientConfig *pushnotificationclient.Config
logger *zap.Logger
outputMessagesCSV bool
messengerSignalsHandler MessengerSignalsHandler
telemetryServerURL string
wakuService *wakuv2.Waku
messageResendMinDelay int
messageResendMaxCount int
}
func messengerDefaultConfig() config {
c := config{
messageResendMinDelay: 30,
messageResendMaxCount: 3,
}
c.featureFlags.AutoRequestHistoricMessages = true
return c
}
type Option func(*config) error
// WithSystemMessagesTranslations is required for Group Chats which are currently disabled.
// nolint: unused
func WithSystemMessagesTranslations(t map[protobuf.MembershipUpdateEvent_EventType]string) Option {
return func(c *config) error {
c.systemMessagesTranslations.Init(t)
return nil
}
}
func WithCustomLogger(logger *zap.Logger) Option {
return func(c *config) error {
c.logger = logger
return nil
}
}
func WithVerifyTransactionClient(client EthClient) Option {
return func(c *config) error {
c.verifyTransactionClient = client
return nil
}
}
func WithResendParams(minDelay int, maxCount int) Option {
return func(c *config) error {
c.messageResendMinDelay = minDelay
c.messageResendMaxCount = maxCount
return nil
}
}
func WithDatabase(db *sql.DB) Option {
return func(c *config) error {
c.appDb = db
return nil
}
}
func WithWalletDatabase(db *sql.DB) Option {
return func(c *config) error {
c.walletDb = db
return nil
}
}
func WithToplevelDatabaseMigrations() Option {
return func(c *config) error {
c.afterDbCreatedHooks = append(c.afterDbCreatedHooks, func(c *config) error {
return migrations.Migrate(c.appDb, nil)
})
return nil
}
}
func WithAppSettings(s settings.Settings, nc params.NodeConfig) Option {
return func(c *config) error {
c.afterDbCreatedHooks = append(c.afterDbCreatedHooks, func(c *config) error {
if s.Networks == nil {
networks := new(json.RawMessage)
if err := networks.UnmarshalJSON([]byte("net")); err != nil {
return err
}
s.Networks = networks
}
sDB, err := accounts.NewDB(c.appDb)
if err != nil {
return err
}
return sDB.CreateSettings(s, nc)
})
return nil
}
}
func WithMultiAccounts(ma *multiaccounts.Database) Option {
return func(c *config) error {
c.multiAccount = ma
return nil
}
}
func WithMailserversDatabase(ma *mailservers.Database) Option {
return func(c *config) error {
c.mailserversDatabase = ma
return nil
}
}
func WithAccount(acc *multiaccounts.Account) Option {
return func(c *config) error {
c.account = acc
return nil
}
}
func WithBrowserDatabase(bd *browsers.Database) Option {
return func(c *config) error {
c.browserDatabase = bd
if c.browserDatabase == nil {
c.afterDbCreatedHooks = append(c.afterDbCreatedHooks, func(c *config) error {
c.browserDatabase = browsers.NewDB(c.appDb)
return nil
})
}
return nil
}
}
func WithAnonMetricsClientConfig(anonMetricsClientConfig *anonmetrics.ClientConfig) Option {
return func(c *config) error {
c.anonMetricsClientConfig = anonMetricsClientConfig
return nil
}
}
func WithAnonMetricsServerConfig(anonMetricsServerConfig *anonmetrics.ServerConfig) Option {
return func(c *config) error {
c.anonMetricsServerConfig = anonMetricsServerConfig
return nil
}
}
func WithTelemetry(serverURL string) Option {
return func(c *config) error {
c.telemetryServerURL = serverURL
return nil
}
}
func WithPushNotificationServerConfig(pushNotificationServerConfig *pushnotificationserver.Config) Option {
return func(c *config) error {
c.pushNotificationServerConfig = pushNotificationServerConfig
return nil
}
}
func WithPushNotificationClientConfig(pushNotificationClientConfig *pushnotificationclient.Config) Option {
return func(c *config) error {
c.pushNotificationClientConfig = pushNotificationClientConfig
return nil
}
}
func WithDatasync() func(c *config) error {
return func(c *config) error {
c.featureFlags.Datasync = true
return nil
}
}
func WithPushNotifications() func(c *config) error {
return func(c *config) error {
c.featureFlags.PushNotifications = true
return nil
}
}
func WithCheckingForBackupDisabled() func(c *config) error {
return func(c *config) error {
c.featureFlags.DisableCheckingForBackup = true
return nil
}
}
func WithAutoMessageDisabled() func(c *config) error {
return func(c *config) error {
c.featureFlags.DisableAutoMessageLoop = true
return nil
}
}
func WithEnvelopesMonitorConfig(emc *transport.EnvelopesMonitorConfig) Option {
return func(c *config) error {
c.envelopesMonitorConfig = emc
return nil
}
}
func WithSignalsHandler(h MessengerSignalsHandler) Option {
return func(c *config) error {
c.messengerSignalsHandler = h
return nil
}
}
func WithENSVerificationConfig(url, address string) Option {
return func(c *config) error {
c.verifyENSURL = url
c.verifyENSContractAddress = address
return nil
}
}
func WithClusterConfig(cc params.ClusterConfig) Option {
return func(c *config) error {
c.clusterConfig = cc
return nil
}
}
func WithTorrentConfig(tc *params.TorrentConfig) Option {
return func(c *config) error {
c.torrentConfig = tc
return nil
}
}
func WithHTTPServer(s *server.MediaServer) Option {
return func(c *config) error {
c.httpServer = s
return nil
}
}
func WithRPCClient(r *rpc.Client) Option {
return func(c *config) error {
c.rpcClient = r
return nil
}
}
func WithWalletConfig(wc *params.WalletConfig) Option {
return func(c *config) error {
c.walletConfig = wc
return nil
}
}
func WithMessageCSV(enabled bool) Option {
return func(c *config) error {
c.outputMessagesCSV = enabled
return nil
}
}
func WithWalletService(s *wallet.Service) Option {
return func(c *config) error {
c.walletService = s
return nil
}
}
func WithCommunityTokensService(s communitytokens.ServiceInterface) Option {
return func(c *config) error {
c.communityTokensService = s
return nil
}
}
func WithWakuService(s *wakuv2.Waku) Option {
return func(c *config) error {
c.wakuService = s
return nil
}
}
func WithTokenManager(tokenManager communities.TokenManager) Option {
return func(c *config) error {
c.tokenManager = tokenManager
return nil
}
}
func WithAccountManager(accountManager account.Manager) Option {
return func(c *config) error {
c.accountsManager = accountManager
return nil
}
}
func WithAutoRequestHistoricMessages(enabled bool) Option {
return func(c *config) error {
c.featureFlags.AutoRequestHistoricMessages = enabled
return nil
}
}