Skip to content

Commit

Permalink
feat: replace nebula.chat to teamgram.net
Browse files Browse the repository at this point in the history
  • Loading branch information
wubenqi committed Nov 2, 2022
1 parent 4fa57ad commit cba95cc
Show file tree
Hide file tree
Showing 9 changed files with 157 additions and 25 deletions.
18 changes: 10 additions & 8 deletions app/bff/authorization/internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,14 @@ import (

type Config struct {
zrpc.RpcServerConf
KV kv.KvConf
Code *conf.SmsVerifyCodeConfig
UserClient zrpc.RpcClientConf
AuthsessionClient zrpc.RpcClientConf
ChatClient zrpc.RpcClientConf
StatusClient zrpc.RpcClientConf
SyncClient *kafka.KafkaProducerConf
MsgClient zrpc.RpcClientConf
KV kv.KvConf
Code *conf.SmsVerifyCodeConfig
UserClient zrpc.RpcClientConf
AuthsessionClient zrpc.RpcClientConf
ChatClient zrpc.RpcClientConf
StatusClient zrpc.RpcClientConf
SyncClient *kafka.KafkaProducerConf
MsgClient zrpc.RpcClientConf
SignInServiceNotification []conf.MessageEntityConfig `json:",optional"`
SignInMessage []conf.MessageEntityConfig `json:",optional"`
}
35 changes: 34 additions & 1 deletion app/bff/authorization/internal/core/auth.signIn_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,17 @@
package core

import (
"fmt"
"time"

"github.com/teamgram/proto/mtproto"
"github.com/teamgram/proto/mtproto/crypto"
"github.com/teamgram/teamgram-server/app/bff/authorization/internal/logic"
"github.com/teamgram/teamgram-server/app/bff/authorization/internal/model"
"github.com/teamgram/teamgram-server/app/messenger/sync/sync"
"github.com/teamgram/teamgram-server/app/service/authsession/authsession"
userpb "github.com/teamgram/teamgram-server/app/service/biz/user/user"
"github.com/teamgram/teamgram-server/pkg/code/conf"
"github.com/teamgram/teamgram-server/pkg/env2"
"github.com/teamgram/teamgram-server/pkg/phonenumber"
)
Expand Down Expand Up @@ -237,7 +241,36 @@ func (c *AuthorizationCore) AuthSignIn(in *mtproto.TLAuthSignIn) (*mtproto.Auth_

c.svcCtx.AuthLogic.DeletePhoneCode(c.ctx, c.MD.AuthId, in.PhoneNumber, phoneCodeHash)
region, _ := c.svcCtx.Dao.GetCountryAndRegionByIp(c.MD.ClientAddr)
signInN := mtproto.MakeSignInServiceNotification(selfUser, c.MD.AuthId, c.MD.Client, region, c.MD.ClientAddr)

var (
now = time.Now()
signInN *mtproto.Update
)

if len(c.svcCtx.Config.SignInServiceNotification) == 0 {
signInN = mtproto.MakeSignInServiceNotification(selfUser, c.MD.AuthId, c.MD.Client, region, c.MD.ClientAddr)
} else {
signInN = mtproto.MakeTLUpdateServiceNotification(&mtproto.Update{
Popup: false,
InboxDate: mtproto.MakeFlagsInt32(int32(now.Unix())),
Type: fmt.Sprintf("auth%d_%d", c.MD.AuthId, now.Unix()),
Message_STRING: "",
Media: mtproto.MakeTLMessageMediaEmpty(nil).To_MessageMedia(),
Entities: nil,
}).To_Update()

builder := conf.ToMessageBuildHelper(
c.svcCtx.Config.SignInServiceNotification,
map[string]interface{}{
"name": mtproto.GetUserName(selfUser),
"now": now.UTC(),
"client": c.MD.Client,
"region": region,
"clientIp": c.MD.ClientAddr,
})
signInN.Message_STRING, signInN.Entities = mtproto.MakeTextAndMessageEntities(builder)
}

c.svcCtx.Dao.SyncClient.SyncUpdatesNotMe(
c.ctx,
&sync.TLSyncUpdatesNotMe{
Expand Down
15 changes: 14 additions & 1 deletion app/bff/authorization/internal/core/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"github.com/teamgram/proto/mtproto/rpc/metadata"
"github.com/teamgram/teamgram-server/app/bff/authorization/internal/svc"
msgpb "github.com/teamgram/teamgram-server/app/messenger/msg/msg/msg"
"github.com/teamgram/teamgram-server/pkg/code/conf"
"github.com/teamgram/teamgram-server/pkg/env2"
"github.com/teamgram/teamgram-server/pkg/phonenumber"

Expand Down Expand Up @@ -78,11 +79,13 @@ func checkPhoneNumberInvalid(phone string) (string, error) {
return pNumber.GetNormalizeDigits(), nil
}

const signInMessageTpl = `Login code: %s. Do not give this code to anyone, even if they say they are from %s!
const (
signInMessageTpl = `Login code: %s. Do not give this code to anyone, even if they say they are from %s!
This code can be used to log in to your %s account. We never ask it for anything else.
If you didn't request this code by trying to log in on another device, simply ignore this message.`
)

func (c *AuthorizationCore) pushSignInMessage(ctx context.Context, signInUserId int64, code string) {
time.AfterFunc(2*time.Second, func() {
Expand All @@ -104,6 +107,16 @@ func (c *AuthorizationCore) pushSignInMessage(ctx context.Context, signInUserId
},
}).To_Message()

if len(c.svcCtx.Config.SignInMessage) > 0 {
builder := conf.ToMessageBuildHelper(
c.svcCtx.Config.SignInMessage,
map[string]interface{}{
"code": code,
"app_name": env2.MyAppName,
})
message.Message, message.Entities = mtproto.MakeTextAndMessageEntities(builder)
}

_ = ctx
c.svcCtx.Dao.MsgClient.MsgPushUserMessage(
context.Background(),
Expand Down
12 changes: 0 additions & 12 deletions app/interface/session/internal/service/auth_sessions.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,6 @@ import (
"github.com/zeromicro/go-zero/core/logx"
)

// import "container/list"

const (
clientUnknown = 0
clientAndroid = 1
clientiOS = 2
clientTdesktop = 3
clientMacSwift = 4
clientWebogram = 5
clientReact = 6
)

type rpcApiMessage struct {
sessionId int64
clientIp string
Expand Down
19 changes: 19 additions & 0 deletions app/interface/session/internal/service/vars.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright 2022 Teamgram Authors
// All rights reserved.
//
// Author: Benqi (wubenqi@gmail.com)
//

package service

const (
clientUnknown = 0
clientAndroid = 1
clientiOS = 2
clientTdesktop = 3
clientMacSwift = 4
clientWebogram = 5
clientReact = 6
clientWebZ = 7
clientWebK = 8
)
2 changes: 1 addition & 1 deletion app/messenger/sync/internal/core/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ package core

import (
"context"
"github.com/teamgram/teamgram-server/app/messenger/sync/sync"

"github.com/teamgram/proto/mtproto"
"github.com/teamgram/proto/mtproto/rpc/metadata"
"github.com/teamgram/teamgram-server/app/interface/session/session"
"github.com/teamgram/teamgram-server/app/messenger/sync/internal/svc"
"github.com/teamgram/teamgram-server/app/messenger/sync/sync"
"github.com/teamgram/teamgram-server/app/service/status/status"

"github.com/zeromicro/go-zero/core/logx"
Expand Down
76 changes: 76 additions & 0 deletions pkg/code/conf/message_entity_config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
// Copyright 2022 Teamgram Authors
// All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// Author: teamgramio (teamgram.io@gmail.com)
//

package conf

import (
"fmt"

"github.com/teamgram/proto/mtproto"
)

type MessageEntityConfig struct {
TextFormat string `json:",optional"`
TextA []string `json:",optional"`
Param string `json:",optional"`
EntityType string `json:",optional"`
EntityUrl string `json:",optional"`
EntityUserId int64 `json:",optional"`
EntityLanguage string `json:",optional"`
}

func (c *MessageEntityConfig) ToMessageBuildEntry(params map[string]interface{}) mtproto.MessageBuildEntry {
aList := make([]interface{}, 0, len(c.TextA))
for _, v := range c.TextA {
var (
a interface{} = v
)
if len(v) > 0 {
if v[0] == '#' {
a = params[v[1:]]
}
}
aList = append(aList, a)
}

param := c.Param
if len(c.Param) > 0 {
if param[0] == '#' {
param = fmt.Sprintf("%v", params[c.Param[1:]])
}
}

return mtproto.MessageBuildEntry{
Text: fmt.Sprintf(c.TextFormat, aList...),
Param: param,
EntityType: c.EntityType,
EntityUrl: c.EntityUrl,
EntityUserId: c.EntityUserId,
EntityLanguage: c.EntityLanguage,
}
}

func ToMessageBuildHelper(c []MessageEntityConfig, params map[string]interface{}) mtproto.MessageBuildHelper {
var (
m = make([]mtproto.MessageBuildEntry, 0, len(c))
)
for _, v := range c {
m = append(m, v.ToMessageBuildEntry(params))
}
return m
}
4 changes: 2 additions & 2 deletions pkg/env2/env2.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import "flag"
var (
SmsCodeName = ""
MyAppName = "Teamgram"
MyWebSite = "nebula.chat"
MyWebSite = "teamgram.net"
TDotMe = "t.me"
PredefinedUser = false

Expand All @@ -25,7 +25,7 @@ var (
func init() {
flag.StringVar(&SmsCodeName, "code", "", "code")
flag.StringVar(&MyAppName, "app_name", "Teamgram", "app_name")
flag.StringVar(&MyWebSite, "site_name", "nebula.chat", "site_name")
flag.StringVar(&MyWebSite, "site_name", "teamgram.net", "site_name")
flag.StringVar(&TDotMe, "t.me", "t.me", "t.me")
flag.BoolVar(&PredefinedUser, "predefined", false, "predefined")
flag.BoolVar(&PredefinedUser2, "predefined2", false, "predefined2")
Expand Down
1 change: 1 addition & 0 deletions teamgramd/sql/migrate-20221101.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TABLE `auth_users` ADD `state` INT NOT NULL DEFAULT '0' AFTER `region`;

0 comments on commit cba95cc

Please sign in to comment.