From eb6745f4905ac5485df5e9c9ca893be20c9aa7e9 Mon Sep 17 00:00:00 2001 From: pibragimov Date: Thu, 2 May 2024 19:59:16 +0300 Subject: [PATCH] auto: autocommit --- README.md | 10 ------ VERSION | 2 +- .../mongo_repository/member_methods.go | 35 ++++++++++++++++++- core/service/analitics/service.go | 4 +-- docker-compose.yaml | 2 +- 5 files changed, 38 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index db37635..c570587 100644 --- a/README.md +++ b/README.md @@ -2,13 +2,3 @@ Telegram client utils for making telegram more fun! -### TODO -- [ ] Clickhouse -- [ ] Full ru localization -- [ ] Refactor mongo repository -- [ ] Save kandinsky images -- [ ] Precommit hooks -- [ ] Better golint -- [ ] Docker-build from github actions -- [ ] Revork errors to go-fast-errors -- [ ] Add https://github.com/dominikbraun/graph \ No newline at end of file diff --git a/VERSION b/VERSION index a82e15b..ce6360b 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -v1.11.58 +v1.11.59 diff --git a/core/repository/mongo_repository/member_methods.go b/core/repository/mongo_repository/member_methods.go index ff83bcb..5770585 100644 --- a/core/repository/mongo_repository/member_methods.go +++ b/core/repository/mongo_repository/member_methods.go @@ -49,7 +49,40 @@ func (r *Repository) GetUsersInChat(ctx context.Context, chatId int64) (UsersInC "tg_username": "$user.tg_username", "tg_name": "$user.tg_name", "is_bot": "$user.is_bot", - // "tg_chat_id": 1, + }, + }, + ) + if err != nil { + return nil, errors.WithStack(err) + } + + return usersInChat, nil +} + +func (r *Repository) GetUsersInChatOnlyActive( + ctx context.Context, + chatId int64, +) (UsersInChat, error) { + usersInChat := make(UsersInChat, 0, 100) + + err := r.memberCollection.SimpleAggregateWithCtx( + ctx, + &usersInChat, + builder.Lookup(r.userCollection.Name(), "tg_user_id", "tg_id", "user"), + bson.M{operator.Match: bson.M{"tg_chat_id": chatId}}, + bson.M{operator.Unwind: "$user"}, + bson.M{ + operator.Project: bson.M{ + "status": 1, + "tg_id": "$user.tg_id", + "tg_username": "$user.tg_username", + "tg_name": "$user.tg_name", + "is_bot": "$user.is_bot", + }, + }, + bson.M{ + operator.Match: bson.M{ + "status": bson.M{operator.In: []MemberStatus{Plain, Creator, Admin}}, }, }, ) diff --git a/core/service/analitics/service.go b/core/service/analitics/service.go index 258c9ca..e41a08a 100644 --- a/core/service/analitics/service.go +++ b/core/service/analitics/service.go @@ -183,7 +183,7 @@ func (r *Service) analiseUserChat( return AnaliseReport{}, nil } - usersInChat, err := r.mongoRepository.GetUsersInChat(ctx, input.TgChatId) + usersInChat, err := r.mongoRepository.GetUsersInChatOnlyActive(ctx, input.TgChatId) if err != nil { return AnaliseReport{}, errors.Wrap( err, @@ -236,7 +236,7 @@ func (r *Service) analiseWholeChat( ctx context.Context, input *AnaliseChatInput, ) (AnaliseReport, error) { - usersInChat, err := r.mongoRepository.GetUsersInChat(ctx, input.TgChatId) + usersInChat, err := r.mongoRepository.GetUsersInChatOnlyActive(ctx, input.TgChatId) if err != nil { return AnaliseReport{}, errors.Wrap( err, diff --git a/docker-compose.yaml b/docker-compose.yaml index 19562b3..42e714f 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -9,7 +9,7 @@ services: fun_storage__mongo_db_url: "mongodb://mongodb:27017" fun_storage__clickhouse_url: "clickhouse:9000" fun_ds_supplier_url: "http://ds:8000" - image: ghcr.io/teadove/fun-telegram:v1.11.58 + image: ghcr.io/teadove/fun-telegram:v1.11.59 volumes: - ".mtproto:/.mtproto" - ".env:/.env"