github.com/status-im/status-go@v1.1.0/multiaccounts/settings/sync_protobuf_factories.go (about) 1 package settings 2 3 import ( 4 "bytes" 5 "encoding/json" 6 "reflect" 7 8 "github.com/golang/protobuf/proto" 9 "github.com/pkg/errors" 10 11 "github.com/status-im/status-go/protocol/common" 12 "github.com/status-im/status-go/protocol/protobuf" 13 "github.com/status-im/status-go/sqlite" 14 ) 15 16 var ( 17 ErrTypeAssertionFailed = errors.New("type assertion of interface value failed") 18 ) 19 20 func buildRawSyncSettingMessage(msg *protobuf.SyncSetting, chatID string) (*common.RawMessage, error) { 21 encodedMessage, err := proto.Marshal(msg) 22 if err != nil { 23 return nil, err 24 } 25 26 return &common.RawMessage{ 27 LocalChatID: chatID, 28 Payload: encodedMessage, 29 MessageType: protobuf.ApplicationMetadataMessage_SYNC_SETTING, 30 ResendType: common.ResendTypeDataSync, 31 }, nil 32 } 33 34 // Currency 35 36 func buildRawCurrencySyncMessage(v string, clock uint64, chatID string) (*common.RawMessage, *protobuf.SyncSetting, error) { 37 pb := &protobuf.SyncSetting{ 38 Type: protobuf.SyncSetting_CURRENCY, 39 Value: &protobuf.SyncSetting_ValueString{ValueString: v}, 40 Clock: clock, 41 } 42 rm, err := buildRawSyncSettingMessage(pb, chatID) 43 return rm, pb, err 44 } 45 46 func currencyProtobufFactory(value interface{}, clock uint64, chatID string) (*common.RawMessage, *protobuf.SyncSetting, error) { 47 v, err := assertString(value) 48 if err != nil { 49 return nil, nil, err 50 } 51 52 return buildRawCurrencySyncMessage(v, clock, chatID) 53 } 54 55 func currencyProtobufFactoryStruct(s Settings, clock uint64, chatID string) (*common.RawMessage, *protobuf.SyncSetting, error) { 56 return buildRawCurrencySyncMessage(s.Currency, clock, chatID) 57 } 58 59 // GifFavorites 60 61 func buildRawGifFavoritesSyncMessage(v []byte, clock uint64, chatID string) (*common.RawMessage, *protobuf.SyncSetting, error) { 62 pb := &protobuf.SyncSetting{ 63 Type: protobuf.SyncSetting_GIF_FAVOURITES, 64 Value: &protobuf.SyncSetting_ValueBytes{ValueBytes: v}, 65 Clock: clock, 66 } 67 rm, err := buildRawSyncSettingMessage(pb, chatID) 68 return rm, pb, err 69 } 70 71 func gifFavouritesProtobufFactory(value interface{}, clock uint64, chatID string) (*common.RawMessage, *protobuf.SyncSetting, error) { 72 v, err := assertBytes(value) 73 if err != nil { 74 return nil, nil, err 75 } 76 77 return buildRawGifFavoritesSyncMessage(v, clock, chatID) 78 } 79 80 func gifFavouritesProtobufFactoryStruct(s Settings, clock uint64, chatID string) (*common.RawMessage, *protobuf.SyncSetting, error) { 81 gf := extractJSONRawMessage(s.GifFavorites) 82 return buildRawGifFavoritesSyncMessage(gf, clock, chatID) 83 } 84 85 // GifRecents 86 87 func buildRawGifRecentsSyncMessage(v []byte, clock uint64, chatID string) (*common.RawMessage, *protobuf.SyncSetting, error) { 88 pb := &protobuf.SyncSetting{ 89 Type: protobuf.SyncSetting_GIF_RECENTS, 90 Value: &protobuf.SyncSetting_ValueBytes{ValueBytes: v}, 91 Clock: clock, 92 } 93 rm, err := buildRawSyncSettingMessage(pb, chatID) 94 return rm, pb, err 95 } 96 97 func gifRecentsProtobufFactory(value interface{}, clock uint64, chatID string) (*common.RawMessage, *protobuf.SyncSetting, error) { 98 v, err := assertBytes(value) 99 if err != nil { 100 return nil, nil, err 101 } 102 103 return buildRawGifRecentsSyncMessage(v, clock, chatID) 104 } 105 106 func gifRecentsProtobufFactoryStruct(s Settings, clock uint64, chatID string) (*common.RawMessage, *protobuf.SyncSetting, error) { 107 gr := extractJSONRawMessage(s.GifRecents) 108 return buildRawGifRecentsSyncMessage(gr, clock, chatID) 109 } 110 111 // MessagesFromContactsOnly 112 113 func buildRawMessagesFromContactsOnlySyncMessage(v bool, clock uint64, chatID string) (*common.RawMessage, *protobuf.SyncSetting, error) { 114 pb := &protobuf.SyncSetting{ 115 Type: protobuf.SyncSetting_MESSAGES_FROM_CONTACTS_ONLY, 116 Value: &protobuf.SyncSetting_ValueBool{ValueBool: v}, 117 Clock: clock, 118 } 119 rm, err := buildRawSyncSettingMessage(pb, chatID) 120 return rm, pb, err 121 } 122 123 func messagesFromContactsOnlyProtobufFactory(value interface{}, clock uint64, chatID string) (*common.RawMessage, *protobuf.SyncSetting, error) { 124 v, err := assertBool(value) 125 if err != nil { 126 return nil, nil, err 127 } 128 129 return buildRawMessagesFromContactsOnlySyncMessage(v, clock, chatID) 130 } 131 132 func messagesFromContactsOnlyProtobufFactoryStruct(s Settings, clock uint64, chatID string) (*common.RawMessage, *protobuf.SyncSetting, error) { 133 return buildRawMessagesFromContactsOnlySyncMessage(s.MessagesFromContactsOnly, clock, chatID) 134 } 135 136 // PreferredName 137 138 func buildRawPreferredNameSyncMessage(v string, clock uint64, chatID string) (*common.RawMessage, *protobuf.SyncSetting, error) { 139 pb := &protobuf.SyncSetting{ 140 Type: protobuf.SyncSetting_PREFERRED_NAME, 141 Value: &protobuf.SyncSetting_ValueString{ValueString: v}, 142 Clock: clock, 143 } 144 rm, err := buildRawSyncSettingMessage(pb, chatID) 145 return rm, pb, err 146 } 147 148 func preferredNameProtobufFactory(value interface{}, clock uint64, chatID string) (*common.RawMessage, *protobuf.SyncSetting, error) { 149 v, err := assertString(value) 150 if err != nil { 151 return nil, nil, err 152 } 153 154 return buildRawPreferredNameSyncMessage(v, clock, chatID) 155 } 156 157 func preferredNameProtobufFactoryStruct(s Settings, clock uint64, chatID string) (*common.RawMessage, *protobuf.SyncSetting, error) { 158 var pn string 159 if s.PreferredName != nil { 160 pn = *s.PreferredName 161 } 162 163 return buildRawPreferredNameSyncMessage(pn, clock, chatID) 164 } 165 166 // PreviewPrivacy 167 168 func buildRawPreviewPrivacySyncMessage(v bool, clock uint64, chatID string) (*common.RawMessage, *protobuf.SyncSetting, error) { 169 pb := &protobuf.SyncSetting{ 170 Type: protobuf.SyncSetting_PREVIEW_PRIVACY, 171 Value: &protobuf.SyncSetting_ValueBool{ValueBool: v}, 172 Clock: clock, 173 } 174 rm, err := buildRawSyncSettingMessage(pb, chatID) 175 return rm, pb, err 176 } 177 178 func previewPrivacyProtobufFactory(value interface{}, clock uint64, chatID string) (*common.RawMessage, *protobuf.SyncSetting, error) { 179 v, err := assertBool(value) 180 if err != nil { 181 return nil, nil, err 182 } 183 184 return buildRawPreviewPrivacySyncMessage(v, clock, chatID) 185 } 186 187 func previewPrivacyProtobufFactoryStruct(s Settings, clock uint64, chatID string) (*common.RawMessage, *protobuf.SyncSetting, error) { 188 return buildRawPreviewPrivacySyncMessage(s.PreviewPrivacy, clock, chatID) 189 } 190 191 // ProfilePicturesShowTo 192 193 func buildRawProfilePicturesShowToSyncMessage(v int64, clock uint64, chatID string) (*common.RawMessage, *protobuf.SyncSetting, error) { 194 pb := &protobuf.SyncSetting{ 195 Type: protobuf.SyncSetting_PROFILE_PICTURES_SHOW_TO, 196 Value: &protobuf.SyncSetting_ValueInt64{ValueInt64: v}, 197 Clock: clock, 198 } 199 rm, err := buildRawSyncSettingMessage(pb, chatID) 200 return rm, pb, err 201 } 202 203 func profilePicturesShowToProtobufFactory(value interface{}, clock uint64, chatID string) (*common.RawMessage, *protobuf.SyncSetting, error) { 204 v, err := parseNumberToInt64(value) 205 if err != nil { 206 return nil, nil, err 207 } 208 209 return buildRawProfilePicturesShowToSyncMessage(v, clock, chatID) 210 } 211 212 func profilePicturesShowToProtobufFactoryStruct(s Settings, clock uint64, chatID string) (*common.RawMessage, *protobuf.SyncSetting, error) { 213 return buildRawProfilePicturesShowToSyncMessage(int64(s.ProfilePicturesShowTo), clock, chatID) 214 } 215 216 // ProfilePicturesVisibility 217 218 func buildRawProfilePicturesVisibilitySyncMessage(v int64, clock uint64, chatID string) (*common.RawMessage, *protobuf.SyncSetting, error) { 219 pb := &protobuf.SyncSetting{ 220 Type: protobuf.SyncSetting_PROFILE_PICTURES_VISIBILITY, 221 Value: &protobuf.SyncSetting_ValueInt64{ValueInt64: v}, 222 Clock: clock, 223 } 224 rm, err := buildRawSyncSettingMessage(pb, chatID) 225 return rm, pb, err 226 } 227 228 func profilePicturesVisibilityProtobufFactory(value interface{}, clock uint64, chatID string) (*common.RawMessage, *protobuf.SyncSetting, error) { 229 v, err := parseNumberToInt64(value) 230 if err != nil { 231 return nil, nil, err 232 } 233 234 return buildRawProfilePicturesVisibilitySyncMessage(v, clock, chatID) 235 } 236 237 func profilePicturesVisibilityProtobufFactoryStruct(s Settings, clock uint64, chatID string) (*common.RawMessage, *protobuf.SyncSetting, error) { 238 return buildRawProfilePicturesVisibilitySyncMessage(int64(s.ProfilePicturesVisibility), clock, chatID) 239 } 240 241 // SendStatusUpdates 242 243 func buildRawSendStatusUpdatesSyncMessage(v bool, clock uint64, chatID string) (*common.RawMessage, *protobuf.SyncSetting, error) { 244 pb := &protobuf.SyncSetting{ 245 Type: protobuf.SyncSetting_SEND_STATUS_UPDATES, 246 Value: &protobuf.SyncSetting_ValueBool{ValueBool: v}, 247 Clock: clock, 248 } 249 rm, err := buildRawSyncSettingMessage(pb, chatID) 250 return rm, pb, err 251 } 252 253 func sendStatusUpdatesProtobufFactory(value interface{}, clock uint64, chatID string) (*common.RawMessage, *protobuf.SyncSetting, error) { 254 v, err := assertBool(value) 255 if err != nil { 256 return nil, nil, err 257 } 258 259 return buildRawSendStatusUpdatesSyncMessage(v, clock, chatID) 260 } 261 262 func sendStatusUpdatesProtobufFactoryStruct(s Settings, clock uint64, chatID string) (*common.RawMessage, *protobuf.SyncSetting, error) { 263 return buildRawSendStatusUpdatesSyncMessage(s.SendStatusUpdates, clock, chatID) 264 } 265 266 // StickerPacksInstalled 267 268 func buildRawStickerPacksInstalledSyncMessage(v []byte, clock uint64, chatID string) (*common.RawMessage, *protobuf.SyncSetting, error) { 269 pb := &protobuf.SyncSetting{ 270 Type: protobuf.SyncSetting_STICKERS_PACKS_INSTALLED, 271 Value: &protobuf.SyncSetting_ValueBytes{ValueBytes: v}, 272 Clock: clock, 273 } 274 rm, err := buildRawSyncSettingMessage(pb, chatID) 275 return rm, pb, err 276 } 277 278 func stickersPacksInstalledProtobufFactory(value interface{}, clock uint64, chatID string) (*common.RawMessage, *protobuf.SyncSetting, error) { 279 v, err := parseJSONBlobData(value) 280 if err != nil { 281 return nil, nil, err 282 } 283 284 return buildRawStickerPacksInstalledSyncMessage(v, clock, chatID) 285 } 286 287 func stickersPacksInstalledProtobufFactoryStruct(s Settings, clock uint64, chatID string) (*common.RawMessage, *protobuf.SyncSetting, error) { 288 spi := extractJSONRawMessage(s.StickerPacksInstalled) 289 return buildRawStickerPacksInstalledSyncMessage(spi, clock, chatID) 290 } 291 292 // StickerPacksPending 293 294 func buildRawStickerPacksPendingSyncMessage(v []byte, clock uint64, chatID string) (*common.RawMessage, *protobuf.SyncSetting, error) { 295 pb := &protobuf.SyncSetting{ 296 Type: protobuf.SyncSetting_STICKERS_PACKS_PENDING, 297 Value: &protobuf.SyncSetting_ValueBytes{ValueBytes: v}, 298 Clock: clock, 299 } 300 rm, err := buildRawSyncSettingMessage(pb, chatID) 301 return rm, pb, err 302 } 303 304 func stickersPacksPendingProtobufFactory(value interface{}, clock uint64, chatID string) (*common.RawMessage, *protobuf.SyncSetting, error) { 305 v, err := parseJSONBlobData(value) 306 if err != nil { 307 return nil, nil, err 308 } 309 310 return buildRawStickerPacksPendingSyncMessage(v, clock, chatID) 311 } 312 313 func stickersPacksPendingProtobufFactoryStruct(s Settings, clock uint64, chatID string) (*common.RawMessage, *protobuf.SyncSetting, error) { 314 spp := extractJSONRawMessage(s.StickerPacksPending) 315 return buildRawStickerPacksPendingSyncMessage(spp, clock, chatID) 316 } 317 318 // StickersRecentStickers 319 320 func buildRawStickersRecentStickersSyncMessage(v []byte, clock uint64, chatID string) (*common.RawMessage, *protobuf.SyncSetting, error) { 321 pb := &protobuf.SyncSetting{ 322 Type: protobuf.SyncSetting_STICKERS_RECENT_STICKERS, 323 Value: &protobuf.SyncSetting_ValueBytes{ValueBytes: v}, 324 Clock: clock, 325 } 326 rm, err := buildRawSyncSettingMessage(pb, chatID) 327 return rm, pb, err 328 } 329 330 func stickersRecentStickersProtobufFactory(value interface{}, clock uint64, chatID string) (*common.RawMessage, *protobuf.SyncSetting, error) { 331 v, err := parseJSONBlobData(value) 332 if err != nil { 333 return nil, nil, err 334 } 335 336 return buildRawStickersRecentStickersSyncMessage(v, clock, chatID) 337 } 338 339 func stickersRecentStickersProtobufFactoryStruct(s Settings, clock uint64, chatID string) (*common.RawMessage, *protobuf.SyncSetting, error) { 340 srs := extractJSONRawMessage(s.StickersRecentStickers) 341 return buildRawStickersRecentStickersSyncMessage(srs, clock, chatID) 342 } 343 344 // Helpers 345 346 func assertBytes(value interface{}) ([]byte, error) { 347 v, ok := value.([]byte) 348 if !ok { 349 return nil, errors.Wrapf(ErrTypeAssertionFailed, "expected '[]byte', received %T", value) 350 } 351 return v, nil 352 } 353 354 func assertBool(value interface{}) (bool, error) { 355 v, ok := value.(bool) 356 if !ok { 357 return false, errors.Wrapf(ErrTypeAssertionFailed, "expected 'bool', received %T", value) 358 } 359 return v, nil 360 } 361 362 func assertString(value interface{}) (string, error) { 363 rv := reflect.ValueOf(value) 364 if rv.Kind() == reflect.Ptr { 365 value = *value.(*string) 366 } 367 v, ok := value.(string) 368 if !ok { 369 return "", errors.Wrapf(ErrTypeAssertionFailed, "expected 'string', received %T", value) 370 } 371 return v, nil 372 } 373 374 func parseJSONBlobData(value interface{}) ([]byte, error) { 375 switch v := value.(type) { 376 case []byte: 377 return v, nil 378 case *sqlite.JSONBlob: 379 return extractJSONBlob(v) 380 default: 381 return nil, errors.Wrapf(ErrTypeAssertionFailed, "expected []byte or *sqlite.JSONBlob, received %T", value) 382 } 383 } 384 385 func parseNumberToInt64(value interface{}) (int64, error) { 386 switch v := value.(type) { 387 case float32: 388 return int64(v), nil 389 case float64: 390 return int64(v), nil 391 case int: 392 return int64(v), nil 393 case int8: 394 return int64(v), nil 395 case int16: 396 return int64(v), nil 397 case int32: 398 return int64(v), nil 399 case int64: 400 return v, nil 401 case uint: 402 return int64(v), nil 403 case uint8: 404 return int64(v), nil 405 case uint16: 406 return int64(v), nil 407 case uint32: 408 return int64(v), nil 409 case uint64: 410 return int64(v), nil 411 case ProfilePicturesShowToType: 412 return int64(v), nil 413 case ProfilePicturesVisibilityType: 414 return int64(v), nil 415 case URLUnfurlingModeType: 416 return int64(v), nil 417 default: 418 return 0, errors.Wrapf(ErrTypeAssertionFailed, "expected a numeric type, received %T", value) 419 } 420 } 421 422 func extractJSONBlob(jb *sqlite.JSONBlob) ([]byte, error) { 423 value, err := jb.Value() 424 if err != nil { 425 return nil, err 426 } 427 428 if value == nil { 429 return nil, nil 430 } 431 432 return value.([]byte), nil 433 } 434 435 func extractJSONRawMessage(jrm *json.RawMessage) []byte { 436 if jrm == nil { 437 return nil 438 } 439 out, _ := jrm.MarshalJSON() // Don't need to parse error because it is always nil 440 if len(out) == 0 || bytes.Equal(out, []byte("null")) { 441 return nil 442 } 443 return out 444 } 445 446 // DisplayName 447 448 func buildRawDisplayNameSyncMessage(v string, clock uint64, chatID string) (*common.RawMessage, *protobuf.SyncSetting, error) { 449 pb := &protobuf.SyncSetting{ 450 Type: protobuf.SyncSetting_DISPLAY_NAME, 451 Value: &protobuf.SyncSetting_ValueString{ValueString: v}, 452 Clock: clock, 453 } 454 rm, err := buildRawSyncSettingMessage(pb, chatID) 455 return rm, pb, err 456 } 457 458 func displayNameProtobufFactory(value interface{}, clock uint64, chatID string) (*common.RawMessage, *protobuf.SyncSetting, error) { 459 v, err := assertString(value) 460 if err != nil { 461 return nil, nil, err 462 } 463 464 return buildRawDisplayNameSyncMessage(v, clock, chatID) 465 } 466 467 func displayNameProtobufFactoryStruct(s Settings, clock uint64, chatID string) (*common.RawMessage, *protobuf.SyncSetting, error) { 468 469 return buildRawDisplayNameSyncMessage(s.DisplayName, clock, chatID) 470 } 471 472 // Bio 473 474 func buildRawBioSyncMessage(v string, clock uint64, chatID string) (*common.RawMessage, *protobuf.SyncSetting, error) { 475 pb := &protobuf.SyncSetting{ 476 Type: protobuf.SyncSetting_BIO, 477 Value: &protobuf.SyncSetting_ValueString{ValueString: v}, 478 Clock: clock, 479 } 480 rm, err := buildRawSyncSettingMessage(pb, chatID) 481 return rm, pb, err 482 } 483 484 func bioProtobufFactory(value interface{}, clock uint64, chatID string) (*common.RawMessage, *protobuf.SyncSetting, error) { 485 v, err := assertString(value) 486 if err != nil { 487 return nil, nil, err 488 } 489 490 return buildRawBioSyncMessage(v, clock, chatID) 491 } 492 493 func bioProtobufFactoryStruct(s Settings, clock uint64, chatID string) (*common.RawMessage, *protobuf.SyncSetting, error) { 494 return buildRawBioSyncMessage(s.Bio, clock, chatID) 495 } 496 497 // MnemonicRemoved 498 499 func buildRawMnemonicRemovedSyncMessage(v bool, clock uint64, chatID string) (*common.RawMessage, *protobuf.SyncSetting, error) { 500 pb := &protobuf.SyncSetting{ 501 Type: protobuf.SyncSetting_MNEMONIC_REMOVED, 502 Value: &protobuf.SyncSetting_ValueBool{ValueBool: v}, 503 Clock: clock, 504 } 505 rm, err := buildRawSyncSettingMessage(pb, chatID) 506 return rm, pb, err 507 } 508 509 func mnemonicRemovedProtobufFactory(value interface{}, clock uint64, chatID string) (*common.RawMessage, *protobuf.SyncSetting, error) { 510 v, err := assertBool(value) 511 if err != nil { 512 return nil, nil, err 513 } 514 515 return buildRawMnemonicRemovedSyncMessage(v, clock, chatID) 516 } 517 518 func mnemonicRemovedProtobufFactoryStruct(s Settings, clock uint64, chatID string) (*common.RawMessage, *protobuf.SyncSetting, error) { 519 return buildRawMnemonicRemovedSyncMessage(s.MnemonicRemoved, clock, chatID) 520 } 521 522 // UrlUnfurlingMode 523 524 func buildRawURLUnfurlingModeSyncMessage(v int64, clock uint64, chatID string) (*common.RawMessage, *protobuf.SyncSetting, error) { 525 pb := &protobuf.SyncSetting{ 526 Type: protobuf.SyncSetting_URL_UNFURLING_MODE, 527 Value: &protobuf.SyncSetting_ValueInt64{ValueInt64: v}, 528 Clock: clock, 529 } 530 rm, err := buildRawSyncSettingMessage(pb, chatID) 531 return rm, pb, err 532 } 533 534 func urlUnfurlingModeProtobufFactory(value any, clock uint64, chatID string) (*common.RawMessage, *protobuf.SyncSetting, error) { 535 v, err := parseNumberToInt64(value) 536 if err != nil { 537 return nil, nil, err 538 } 539 540 return buildRawURLUnfurlingModeSyncMessage(v, clock, chatID) 541 } 542 543 func urlUnfurlingModeProtobufFactoryStruct(s Settings, clock uint64, chatID string) (*common.RawMessage, *protobuf.SyncSetting, error) { 544 return buildRawURLUnfurlingModeSyncMessage(int64(s.URLUnfurlingMode), clock, chatID) 545 } 546 547 // ShowCommunityAssetWhenSendingTokens 548 549 func buildRawShowCommunityAssetWhenSendingTokensSyncMessage(v bool, clock uint64, chatID string) (*common.RawMessage, *protobuf.SyncSetting, error) { 550 pb := &protobuf.SyncSetting{ 551 Type: protobuf.SyncSetting_SHOW_COMMUNITY_ASSET_WHEN_SENDING_TOKENS, 552 Value: &protobuf.SyncSetting_ValueBool{ValueBool: v}, 553 Clock: clock, 554 } 555 rm, err := buildRawSyncSettingMessage(pb, chatID) 556 return rm, pb, err 557 } 558 559 func showCommunityAssetWhenSendingTokensProtobufFactory(value interface{}, clock uint64, chatID string) (*common.RawMessage, *protobuf.SyncSetting, error) { 560 v, err := assertBool(value) 561 if err != nil { 562 return nil, nil, err 563 } 564 565 return buildRawShowCommunityAssetWhenSendingTokensSyncMessage(v, clock, chatID) 566 } 567 568 func showCommunityAssetWhenSendingTokensProtobufFactoryStruct(s Settings, clock uint64, chatID string) (*common.RawMessage, *protobuf.SyncSetting, error) { 569 return buildRawShowCommunityAssetWhenSendingTokensSyncMessage(s.ShowCommunityAssetWhenSendingTokens, clock, chatID) 570 } 571 572 // DisplayAssetsBelowBalance 573 574 func buildRawDisplayAssetsBelowBalanceSyncMessage(v bool, clock uint64, chatID string) (*common.RawMessage, *protobuf.SyncSetting, error) { 575 pb := &protobuf.SyncSetting{ 576 Type: protobuf.SyncSetting_DISPLAY_ASSETS_BELOW_BALANCE, 577 Value: &protobuf.SyncSetting_ValueBool{ValueBool: v}, 578 Clock: clock, 579 } 580 rm, err := buildRawSyncSettingMessage(pb, chatID) 581 return rm, pb, err 582 } 583 584 func displayAssetsBelowBalanceProtobufFactory(value interface{}, clock uint64, chatID string) (*common.RawMessage, *protobuf.SyncSetting, error) { 585 v, err := assertBool(value) 586 if err != nil { 587 return nil, nil, err 588 } 589 590 return buildRawDisplayAssetsBelowBalanceSyncMessage(v, clock, chatID) 591 } 592 593 func displayAssetsBelowBalanceProtobufFactoryStruct(s Settings, clock uint64, chatID string) (*common.RawMessage, *protobuf.SyncSetting, error) { 594 return buildRawDisplayAssetsBelowBalanceSyncMessage(s.DisplayAssetsBelowBalance, clock, chatID) 595 } 596 597 // DisplayAssetsBelowBalanceThreshold 598 599 func buildRawDisplayAssetsBelowBalanceThresholdSyncMessage(v int64, clock uint64, chatID string) (*common.RawMessage, *protobuf.SyncSetting, error) { 600 pb := &protobuf.SyncSetting{ 601 Type: protobuf.SyncSetting_DISPLAY_ASSETS_BELOW_BALANCE_THRESHOLD, 602 Value: &protobuf.SyncSetting_ValueInt64{ValueInt64: v}, 603 Clock: clock, 604 } 605 rm, err := buildRawSyncSettingMessage(pb, chatID) 606 return rm, pb, err 607 } 608 609 func displayAssetsBelowBalanceThresholdProtobufFactory(value any, clock uint64, chatID string) (*common.RawMessage, *protobuf.SyncSetting, error) { 610 v, err := parseNumberToInt64(value) 611 if err != nil { 612 return nil, nil, err 613 } 614 615 return buildRawDisplayAssetsBelowBalanceThresholdSyncMessage(v, clock, chatID) 616 } 617 618 func displayAssetsBelowBalanceThresholdProtobufFactoryStruct(s Settings, clock uint64, chatID string) (*common.RawMessage, *protobuf.SyncSetting, error) { 619 return buildRawDisplayAssetsBelowBalanceThresholdSyncMessage(s.DisplayAssetsBelowBalanceThreshold, clock, chatID) 620 }