Add command to join groups with invite link

This commit is contained in:
Tulir Asokan
2020-06-25 23:29:16 +03:00
parent 67864d8475
commit 3a571b2c7a
2 changed files with 67 additions and 2 deletions

View File

@ -45,6 +45,7 @@ const (
ChatActionAnnounce ChatActionType = "announce"
ChatActionPromote ChatActionType = "promote"
ChatActionDemote ChatActionType = "demote"
ChatActionIntroduce ChatActionType = "introduce"
)
type ChatUpdateData struct {
@ -61,12 +62,20 @@ type ChatUpdateData struct {
Topic string `json:"desc"`
ID string `json:"descId"`
SetAt int64 `json:"descTime"`
SetBy string `json:"descOwner"`
}
RemoveTopic struct {
ID string `json:"descId"`
}
Introduce struct {
CreationTime int64 `json:"creation"`
Admins []string `json:"admins"`
SuperAdmins []string `json:"superadmins"`
Regulars []string `json:"regulars"`
}
Restrict bool
Announce bool
@ -98,6 +107,16 @@ func (cud *ChatUpdateData) UnmarshalJSON(data []byte) error {
var unmarshalTo interface{}
switch cud.Action {
case ChatActionIntroduce:
err = json.Unmarshal(arr[2], &cud.NameChange)
if err != nil {
return err
}
err = json.Unmarshal(arr[2], &cud.AddTopic)
if err != nil {
return err
}
unmarshalTo = &cud.Introduce
case ChatActionNameChange:
unmarshalTo = &cud.NameChange
case ChatActionAddTopic:
@ -121,6 +140,15 @@ func (cud *ChatUpdateData) UnmarshalJSON(data []byte) error {
for index, jid := range cud.PermissionChange.JIDs {
cud.PermissionChange.JIDs[index] = strings.Replace(jid, OldUserSuffix, NewUserSuffix, 1)
}
for index, jid := range cud.Introduce.SuperAdmins {
cud.Introduce.SuperAdmins[index] = strings.Replace(jid, OldUserSuffix, NewUserSuffix, 1)
}
for index, jid := range cud.Introduce.Admins {
cud.Introduce.Admins[index] = strings.Replace(jid, OldUserSuffix, NewUserSuffix, 1)
}
for index, jid := range cud.Introduce.Regulars {
cud.Introduce.Regulars[index] = strings.Replace(jid, OldUserSuffix, NewUserSuffix, 1)
}
return nil
}