move gotd fork into repo. (#111)
- update to latest telegram layer - remove some references to fields in tg.Entities that don't exist in the schema - originally added here: https://github.com/beeper/td/commit/820929062a2ba0104397bc01235ab58a9cff780e - referenced here - https://github.com/mautrix/telegramgo/commit/124f0967ed195b5a380c9bd02e170ada9710dde3 - https://github.com/mautrix/telegramgo/commit/4205047aab2e0639217148b5d125bfaab668bd8e
This commit is contained in:
@@ -0,0 +1,72 @@
|
||||
{{ define "updates_classifier" }}
|
||||
{{ $pkg := $.Package }}
|
||||
{{ template "header" $ }}
|
||||
|
||||
func IsPtsUpdate(u UpdateClass) (pts, ptsCount int, ok bool) {
|
||||
switch u := u.(type) {
|
||||
{{- range $s := $.Structs }}{{ if and (eq $s.Interface "UpdateClass")
|
||||
(hasField $s.Fields "Pts" "int")
|
||||
(not (contains $s.Name "Channel")) }}
|
||||
{{- $ptsCount := or (and (hasField $s.Fields "PtsCount" "int") "u.PtsCount") "0" }}
|
||||
case *{{ $s.Name }}:
|
||||
return u.Pts, {{ $ptsCount }}, true
|
||||
{{- end }}{{ end }}
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func IsQtsUpdate(u UpdateClass) (qts int, ok bool) {
|
||||
switch u := u.(type) {
|
||||
{{- range $s := $.Structs }}{{ if and (eq $s.Interface "UpdateClass") (hasField $s.Fields "Qts" "int") }}
|
||||
case *{{ $s.Name }}:
|
||||
return u.Qts, true
|
||||
{{- end }}{{ end }}
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func IsChannelPtsUpdate(u UpdateClass) (channelID int64, pts, ptsCount int, ok bool, err error) {
|
||||
switch u := u.(type) {
|
||||
{{- range $s := $.Structs }}{{ if and (eq $s.Interface "UpdateClass")
|
||||
(hasField $s.Fields "Pts" "int")
|
||||
(contains $s.Name "Channel") }}
|
||||
{{- $ptsCount := or (and (hasField $s.Fields "PtsCount" "int") "u.PtsCount") "0" }}
|
||||
case *{{ $s.Name }}:
|
||||
{{- if (hasField $s.Fields "ChannelID" "int64") }}
|
||||
return u.ChannelID, u.Pts, {{ $ptsCount }}, true, nil
|
||||
{{- else }}
|
||||
channelID, err = extractChannelID(u.Message)
|
||||
return channelID, u.Pts, {{ $ptsCount }}, true, err
|
||||
{{- end }}{{ end }}{{ end }}
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func extractChannelID(msg MessageClass) (int64, error) {
|
||||
switch msg := msg.(type) {
|
||||
{{- range $s := $.Structs }}{{ if eq $s.Interface "MessageClass" }}
|
||||
case *{{ $s.Name }}:
|
||||
{{- range $field := $s.Fields }}{{ if eq $field.Name "PeerID" }}
|
||||
{{- if (optionalField $s $field) }}
|
||||
peer, ok := msg.GetPeerID()
|
||||
if !ok {
|
||||
return 0, errors.New("{{ $s.Name }} have no peerID field")
|
||||
}
|
||||
{{- else }}
|
||||
peer := msg.PeerID
|
||||
{{ end }}{{ end }}{{ end }}
|
||||
if c, ok := peer.(*PeerChannel); ok {
|
||||
return c.ChannelID, nil
|
||||
}
|
||||
|
||||
return 0, errors.New("unexpected peer type")
|
||||
{{- end }}{{ end }}
|
||||
default:
|
||||
return 0, errors.New("unexpected MessageClass type")
|
||||
}
|
||||
}
|
||||
|
||||
{{ end }}
|
||||
Reference in New Issue
Block a user