Skip to content

Commit

Permalink
refactor: update GetChatJoinRequests to use JoinRequest struct and im…
Browse files Browse the repository at this point in the history
…prove type handling, release v1.4.2
  • Loading branch information
AmarnathCJD committed Nov 22, 2024
1 parent 3acc088 commit c7b4527
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 11 deletions.
31 changes: 24 additions & 7 deletions telegram/channels.go
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,16 @@ func (c *Client) DeleteChannel(channelID any) (*Updates, error) {
return &u, nil
}

func (c *Client) GetChatJoinRequests(channelID any, lim int, query ...string) ([]*UserObj, error) {
type JoinRequest struct {
User *UserObj
Date int32
ApprovedBy int64
Requested bool
About string
ViaChatlist bool
}

func (c *Client) GetChatJoinRequests(channelID any, lim int, query ...string) ([]*JoinRequest, error) {
var currentOffsetUser InputUser = &InputUserEmpty{}
currentOffsetDate := 0

Expand All @@ -609,7 +618,7 @@ func (c *Client) GetChatJoinRequests(channelID any, lim int, query ...string) ([
return nil, err
}

var allUsers []*UserObj
var allUsers []*JoinRequest

// Loop until lim is reached
for {
Expand All @@ -630,12 +639,20 @@ func (c *Client) GetChatJoinRequests(channelID any, lim int, query ...string) ([
break
}

c.Cache.UpdatePeersToCache(chatInviteImporters.Users, []Chat{})
// Add all UserObj objects to allUsers slice
for _, user := range chatInviteImporters.Users {
u, ok := user.(*UserObj)
if !ok {
c.Logger.Debug("user is not a UserObj")
continue
for _, user := range chatInviteImporters.Importers {
userObj, err := c.GetUser(user.UserID)
if err != nil {
userObj = &UserObj{ID: user.UserID}
}
u := &JoinRequest{
User: userObj,
Date: user.Date,
ApprovedBy: user.ApprovedBy,
Requested: user.Requested,
About: user.About,
ViaChatlist: user.ViaChatlist,
}
allUsers = append(allUsers, u)
current++
Expand Down
2 changes: 1 addition & 1 deletion telegram/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import "regexp"

const (
ApiVersion = 194
Version = "v1.4.1"
Version = "v1.4.2"

LogDebug = "debug"
LogInfo = "info"
Expand Down
8 changes: 5 additions & 3 deletions telegram/media.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func (wp *WorkerPool) FreeWorker(s *Sender) {
}

type Source struct {
Source any
Source interface{}
}

func (s *Source) GetSizeAndName() (int64, string) {
Expand Down Expand Up @@ -119,7 +119,7 @@ func (s *Source) GetReader() io.Reader {
return nil
}

func (c *Client) UploadFile(src any, Opts ...*UploadOptions) (InputFile, error) {
func (c *Client) UploadFile(src interface{}, Opts ...*UploadOptions) (InputFile, error) {
opts := getVariadic(Opts, &UploadOptions{})
if src == nil {
return nil, errors.New("file can not be nil")
Expand Down Expand Up @@ -413,7 +413,7 @@ func (mb *Destination) Close() error {
return nil
}

func (c *Client) DownloadMedia(file any, Opts ...*DownloadOptions) (string, error) {
func (c *Client) DownloadMedia(file interface{}, Opts ...*DownloadOptions) (string, error) {
opts := getVariadic(Opts, &DownloadOptions{})
location, dc, size, fileName, err := GetFileLocation(file)
if err != nil {
Expand Down Expand Up @@ -485,6 +485,7 @@ func (c *Client) DownloadMedia(file any, Opts ...*DownloadOptions) (string, erro
case <-progressTicker:
return
case <-ticker.C:
fmt.Println(opts.ProgressManager.GetStats(doneBytes.Load()))
opts.ProgressManager.editFunc(size, doneBytes.Load())
}
}
Expand Down Expand Up @@ -694,6 +695,7 @@ func NewProgressManager(editInterval int) *ProgressManager {
}
}

// a: total size, b: current size
func (pm *ProgressManager) Edit(editFunc func(a, b int64)) {
pm.editFunc = editFunc
}
Expand Down

0 comments on commit c7b4527

Please sign in to comment.