Upload files before sending message

This commit is contained in:
Tulir Asokan
2023-01-28 15:43:16 +02:00
parent 9cf9d7c446
commit e9249d6ff9
5 changed files with 62 additions and 10 deletions

11
user.go
View File

@@ -3,11 +3,14 @@ package main
import (
"errors"
"fmt"
"math/rand"
"net/http"
"os"
"runtime"
"strconv"
"strings"
"sync"
"sync/atomic"
"time"
"github.com/gorilla/websocket"
@@ -55,6 +58,8 @@ type User struct {
markedOpened map[string]time.Time
markedOpenedLock sync.Mutex
nextDiscordUploadID atomic.Int32
}
func (user *User) GetRemoteID() string {
@@ -193,6 +198,7 @@ func (br *DiscordBridge) NewUser(dbUser *database.User) *User {
markedOpened: make(map[string]time.Time),
PermissionLevel: br.Config.Bridge.Permissions.Get(dbUser.MXID),
}
user.nextDiscordUploadID.Store(rand.Int31n(100))
user.BridgeState = br.NewBridgeStateQueue(user, user.log)
return user
}
@@ -433,6 +439,11 @@ func (user *User) syncChatDoublePuppetDetails(portal *Portal, justCreated bool)
}
}
func (user *User) NextDiscordUploadID() string {
val := user.nextDiscordUploadID.Add(2)
return strconv.Itoa(int(val))
}
func (user *User) Login(token string) error {
user.bridgeStateLock.Lock()
user.wasLoggedOut = false