Skip to content

Commit

Permalink
Merge branch 'master' into 7842-multi-reminds
Browse files Browse the repository at this point in the history
  • Loading branch information
malekvictor committed Dec 7, 2020
2 parents ff37bb3 + 23876f0 commit 4cc8ac9
Show file tree
Hide file tree
Showing 43 changed files with 1,859 additions and 164 deletions.
3 changes: 3 additions & 0 deletions call_event.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ type CallOnliner struct {
// Contact name
DisplayName string `json:"display_name"`

// Contact role
Role string `json:"role"`

// Contact icon
Icon string `json:"icon"`

Expand Down
2 changes: 1 addition & 1 deletion chat.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ type Chat struct {
Gentime int64 `json:"gentime"`

// Creation date, iso datetime
Created string `json:"created"`
Created ISODateTimeString `json:"created"`

// Title
DisplayName string `json:"display_name"`
Expand Down
12 changes: 9 additions & 3 deletions chat_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,18 @@ import (
"log"
)

// Chat type
type ChatType string

const (
DirectChatType = ChatType("direct")
GroupChatType = ChatType("group")
TaskChatType = ChatType("task")
// Direct chat
DirectChatType ChatType = "direct"

// Group chat
GroupChatType ChatType = "group"

// Task
TaskChatType ChatType = "task"
)

func (ct ChatType) JidPrefix() string {
Expand Down
5 changes: 2 additions & 3 deletions client_call_leave.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ type ClientCallLeave struct {
func (p ClientCallLeave) GetName() string { return "client.call.leave" }

type clientCallLeaveParams struct {
Jid JID `json:"jid"`
Reason string `json:"reason"`
LeaveWithoutClosing bool `json:"test_not_in_room,omitempty"`
Jid JID `json:"jid"`
Reason string `json:"reason"`
}
122 changes: 122 additions & 0 deletions codegen/dart/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
package main

import (
"errors"
"log"
"os"
"path/filepath"
"text/template"

"github.com/tada-team/tdproto/codegen"
)

func main() {
if err := do(); err != nil {
log.Println(err)
}
}

var dartFile = template.Must(template.New("").Parse(`import 'package:freezed_annotation/freezed_annotation.dart';
{{ if $.Struct.IsEnum -}}
/// {{.Struct.Help}}
enum {{.Struct.Name}} {
{{ range $v := $.Struct.EnumValues }}
// {{$v.Help}}
@JsonValue({{ $v.DartValue }})
{{ $v.DartName }},
{{ end }}
}
{{- else -}}
import 'package:tdproto_dart/tdproto_dart.dart';
part '{{.Struct.SnakeName}}.freezed.dart';
part '{{.Struct.SnakeName}}.g.dart';
/// {{.Struct.Help}}
@freezed
abstract class {{.Struct.Name}} with _${{.Struct.Name}} {
const factory {{.Struct.Name}}({
{{ range $f := .Struct.Fields }}
/// {{$f.Help}}.{{if $f.Readonly}} Readonly.{{end}}
@JsonKey(name: '{{$f.Json}}')
{{- if eq $f.DartType "DateTime" }} @DateTimeConverter(){{ end -}}
{{- if $f.DartRequired }} @required{{ end -}}
{{- if $f.List }} List<{{ $f.DartType }}>{{ else }} {{ $f.DartType }}{{ end }} {{ $f.DartName }},
{{ end }}
}) = _{{.Struct.Name}};
factory {{.Struct.Name}}.fromJson(Map<String, dynamic> json) => _${{.Struct.Name}}FromJson(json);
}
{{- end -}}
`))

type tplContext struct {
Struct *codegen.Struct
}

func do() error {
if len(os.Args) != 2 {
return errors.New("path required")
}

path := os.Args[1]
if _, err := os.Stat(path); os.IsNotExist(err) {
return err
}

structs, err := codegen.Parse()
if err != nil {
return err
}

for _, s := range structs {
switch s.Name {
case "UploadPreview", "PdfVersion", "Upload", "MarkupEntity", "MarkupType",
"ChatType", "TeamStatus", "GroupStatus",
"Country":
log.Println("export:", s.Name)
if err := save(path, s); err != nil {
return err
}
default:
log.Println("skip:", s.Name)
}
}

return nil
}

func save(path string, s *codegen.Struct) error {
dist := filepath.Join(path, s.SnakeName())
if _, err := os.Stat(dist); os.IsNotExist(err) {
log.Println("mkdir:", dist)
if err := os.MkdirAll(dist, os.ModePerm); err != nil {
return err
}
} else if err != nil {
return err
}

fname := filepath.Join(dist, s.SnakeName()+".dart")
log.Println("save:", fname)

f, err := os.Create(fname)
if err != nil {
return err
}
defer f.Close()

if err := dartFile.Execute(f, tplContext{Struct: s}); err != nil {
return err
}

//cmd := exec.Command("dart", "fmt", fname)
//if err := cmd.Run(); err != nil {
// return err
//}

return nil
}
2 changes: 1 addition & 1 deletion inspect/debug.go → codegen/debug.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package inspect
package codegen

import (
"bytes"
Expand Down
Loading

0 comments on commit 4cc8ac9

Please sign in to comment.