Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MM-55060 - Calls: Add PushTypeCalls for calls-specific push notifications #110

Merged
merged 7 commits into from
Nov 15, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ GO=go

# Set version variables for LDFLAGS
GIT_VERSION ?= $(shell git describe --tags --always --dirty)
GIT_HASH ?= $(shell git rev-parse HEAD)
BUILD_HASH = $(shell git rev-parse --short HEAD)
BUILD_TAG_LATEST = $(shell git describe --tags --match 'v*' --abbrev=0)
BUILD_TAG_CURRENT = $(shell git tag --points-at HEAD)
DATE_FMT = +'%Y-%m-%dT%H:%M:%SZ'
SOURCE_DATE_EPOCH ?= $(shell git log -1 --pretty=%ct)
ifdef SOURCE_DATE_EPOCH
Expand All @@ -23,7 +25,7 @@ ifeq ($(DIFF), 1)
endif

PP_PKG=github.com/mattermost/mattermost-push-proxy/internal/version
LDFLAGS="-X $(PP_PKG).gitVersion=$(GIT_VERSION) -X $(PP_PKG).gitCommit=$(GIT_HASH) -X $(PP_PKG).gitTreeState=$(GIT_TREESTATE) -X $(PP_PKG).buildDate=$(BUILD_DATE)"
LDFLAGS="-X $(PP_PKG).gitVersion=$(GIT_VERSION) -X $(PP_PKG).buildHash=$(BUILD_HASH) -X $(PP_PKG).buildTagLatest=$(BUILD_TAG_LATEST) -X $(PP_PKG).buildTagCurrent=$(BUILD_TAG_CURRENT) -X $(PP_PKG).gitTreeState=$(GIT_TREESTATE) -X $(PP_PKG).buildDate=$(BUILD_DATE)"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Heads up that there are some changes to the Makefile here: #109.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, merged and updated the Makefile.


DIST_ROOT=dist
DIST_PATH=$(DIST_ROOT)/mattermost-push-proxy
Expand Down Expand Up @@ -161,7 +163,7 @@ clean:

run:
@echo Starting go web server
$(GO) run $(GOFLAGS) -ldflags '$(LDFLAGS)' main.go
$(GO) run $(GOFLAGS) -ldflags $(LDFLAGS) main.go

build-swagger:
npm run validate
Expand Down
33 changes: 28 additions & 5 deletions internal/version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,12 @@ var (
// Output of "git describe". The prerequisite is that the branch should be
// tagged using the correct versioning strategy.
gitVersion string = "devel"
// SHA1 from git, output of $(git rev-parse HEAD)
gitCommit = "unknown"
// short SHA1 from git, output of $(git rev-parse --short HEAD)
buildHash = "unknown"
// the most recent v* tag in the current branch (or its ancestors)
buildTagLatest = "unknown"
// the current commit's v* tag
buildTagCurrent = "unknown"
// State of git tree, either "clean" or "dirty"
gitTreeState = "unknown"
// Build date in ISO8601 format, output of $(date -u +'%Y-%m-%dT%H:%M:%SZ')
Expand All @@ -33,7 +37,8 @@ func GetVersion() error {

type Info struct {
GitVersion string
GitCommit string
cpoile marked this conversation as resolved.
Show resolved Hide resolved
BuildHash string
BuildVersion string
GitTreeState string
BuildDate string
GoVersion string
Expand All @@ -44,9 +49,26 @@ type Info struct {
func VersionInfo() Info {
// These variables typically come from -ldflags settings and in
// their absence fallback to the global defaults set above.

// Create the semver version based on the state of the current commit or its branch.
// Use the first version we find.
var version string
tags := strings.Fields(buildTagCurrent)
for _, t := range tags {
if strings.HasPrefix(t, "v") {
version = t
break
}
}
if version == "" {
version = buildTagLatest + "+" + buildHash
}
version = strings.TrimPrefix(version, "v")

return Info{
GitVersion: gitVersion,
GitCommit: gitCommit,
BuildHash: buildHash,
BuildVersion: version,
GitTreeState: gitTreeState,
BuildDate: buildDate,
GoVersion: runtime.Version(),
Expand All @@ -61,7 +83,8 @@ func (i *Info) String() string {
w := tabwriter.NewWriter(&b, 0, 0, 2, ' ', 0)

fmt.Fprintf(w, "GitVersion:\t%s\n", i.GitVersion)
fmt.Fprintf(w, "GitCommit:\t%s\n", i.GitCommit)
fmt.Fprintf(w, "BuildHash:\t%s\n", i.BuildHash)
fmt.Fprintf(w, "BuildVersion:\t%s\n", i.BuildVersion)
fmt.Fprintf(w, "GitTreeState:\t%s\n", i.GitTreeState)
fmt.Fprintf(w, "BuildDate:\t%s\n", i.BuildDate)
fmt.Fprintf(w, "GoVersion:\t%s\n", i.GoVersion)
Expand Down
4 changes: 2 additions & 2 deletions server/android_notification_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ func (me *AndroidNotificationServer) SendNotification(msg *PushNotification) Pus
data["sender_id"] = msg.SenderID
data["sender_name"] = "Someone"
data["team_id"] = msg.TeamID
} else if pushType == PushTypeMessage || pushType == PushTypeSession {
} else if pushType == PushTypeMessage || pushType == PushTypeSession || pushType == PushTypeCalls {
data["team_id"] = msg.TeamID
data["sender_id"] = msg.SenderID
data["sender_name"] = msg.SenderName
Expand All @@ -162,7 +162,7 @@ func (me *AndroidNotificationServer) SendNotification(msg *PushNotification) Pus
ctx, cancel := context.WithTimeout(context.Background(), me.sendTimeout)
defer cancel()

me.logger.Infof("Sending android push notification for device=%v type=%v ackId=%v", me.AndroidPushSettings.Type, msg.Type, msg.AckID)
me.logger.Infof("Sending android push notification for device=%v type=%v ackId=%v", me.AndroidPushSettings.Type, pushType, msg.AckID)

start := time.Now()
_, err := me.client.Send(ctx, fcmMsg)
Expand Down
4 changes: 2 additions & 2 deletions server/apple_notification_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,12 +138,12 @@ func (me *AppleNotificationServer) SendNotification(msg *PushNotification) PushR
data.ContentAvailable()
} else {
switch msg.Type {
case PushTypeMessage, PushTypeSession:
case PushTypeMessage, PushTypeSession, PushTypeCalls:
data.Category(msg.Category)
data.Sound("default")
data.Custom("version", msg.Version)
data.MutableContent()
if msg.Type == PushTypeMessage {
if msg.Type == PushTypeMessage || msg.Type == PushTypeCalls {
data.ContentAvailable()
}

Expand Down
1 change: 1 addition & 0 deletions server/push_notification.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const (
PushTypeUpdateBadge = "update_badge"
PushTypeSession = "session"
PushTypeTest = "test"
PushTypeCalls = "calls"

PushMessageV2 = "v2"

Expand Down
17 changes: 17 additions & 0 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ func (s *Server) Start() {
handler := th.Throttle(router)

router.HandleFunc("/", root).Methods("GET")
router.HandleFunc("/version", s.version).Methods("GET")

metricCompatibleSendNotificationHandler := s.handleSendNotification
metricCompatibleAckNotificationHandler := s.handleAckNotification
Expand Down Expand Up @@ -150,6 +151,22 @@ func root(w http.ResponseWriter, r *http.Request) {
_, _ = w.Write([]byte("<html><body>Mattermost Push Proxy</body></html>"))
}

func (s *Server) version(w http.ResponseWriter, _ *http.Request) {
agnivade marked this conversation as resolved.
Show resolved Hide resolved
info := version.VersionInfo()
ret := map[string]interface{}{
"version": info.BuildVersion,
"hash": info.BuildHash,
}

w.Header().Set("Content-Type", "application/json")
if err := json.NewEncoder(w).Encode(ret); err != nil {
cpoile marked this conversation as resolved.
Show resolved Hide resolved
s.logger.Errorf("Failed to write response: %v", err)
if s.metrics != nil {
s.metrics.incrementBadRequest()
}
}
}

func (s *Server) responseTimeMiddleware(f func(w http.ResponseWriter, r *http.Request)) func(w http.ResponseWriter, r *http.Request) {
return func(w http.ResponseWriter, r *http.Request) {
start := time.Now()
Expand Down
Loading