Merge branch 'asdfasjkfdlas/alkdjf' into sdkjfls-final
This commit is contained in:
parent
f99cede432
commit
f1b0526977
11
matrix.go
11
matrix.go
@ -17,6 +17,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
@ -149,7 +150,15 @@ func (c *MatrixContainer) Start() {
|
||||
|
||||
func (c *MatrixContainer) HandleMessage(evt *gomatrix.Event) {
|
||||
message, _ := evt.Content["body"].(string)
|
||||
c.ui.MainView().Append(evt.RoomID, evt.Sender, message)
|
||||
|
||||
timestampNumber, _ := evt.Content["origin_server_ts"].(json.Number)
|
||||
timestampInt64, _ := timestampNumber.Int64()
|
||||
timestamp := time.Now()
|
||||
if timestampInt64 != 0 {
|
||||
timestamp = time.Unix(timestampInt64 / 1000, timestampInt64 % 1000 * 1000)
|
||||
}
|
||||
|
||||
c.ui.MainView().AddMessage(evt.RoomID, evt.Sender, message, timestamp)
|
||||
}
|
||||
|
||||
func (c *MatrixContainer) HandleTyping(evt *gomatrix.Event) {
|
||||
|
15
room-view.go
15
room-view.go
@ -22,6 +22,7 @@ import (
|
||||
"regexp"
|
||||
"sort"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/gdamore/tcell"
|
||||
"maunium.net/go/tview"
|
||||
@ -60,6 +61,7 @@ func NewRoomView(topic string) *RoomView {
|
||||
SetText(strings.Replace(topic, "\n", " ", -1)).
|
||||
SetBackgroundColor(tcell.ColorDarkGreen)
|
||||
view.status.SetBackgroundColor(tcell.ColorDimGray)
|
||||
view.userList.SetDynamicColors(true)
|
||||
view.content.SetDynamicColors(true)
|
||||
return view
|
||||
}
|
||||
@ -108,15 +110,20 @@ func escapeColor(s string) string {
|
||||
return colorPattern.ReplaceAllString(s, "[$1[]")
|
||||
}
|
||||
|
||||
func (view *RoomView) AddMessage(sender, message string) {
|
||||
fmt.Fprintf(view.content, "%s: %s\n",
|
||||
color(sender), escapeColor(message))
|
||||
func (view *RoomView) AddMessage(sender, message string, timestamp time.Time) {
|
||||
fmt.Fprintf(view.content, "[%s] %s: %s\n",
|
||||
timestamp.Format("15:04:05"), color(sender), escapeColor(message))
|
||||
}
|
||||
|
||||
func (view *RoomView) SetUsers(users []string) {
|
||||
view.users = sort.StringSlice(users)
|
||||
view.users.Sort()
|
||||
view.userList.SetText(strings.Join(view.users, "\n"))
|
||||
var buf strings.Builder
|
||||
for _, user := range view.users {
|
||||
buf.WriteString(color(user))
|
||||
buf.WriteRune('\n')
|
||||
}
|
||||
view.userList.SetText(buf.String())
|
||||
}
|
||||
|
||||
func (view *RoomView) RemoveUser(user string) {
|
||||
|
@ -18,6 +18,7 @@ package main
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/gdamore/tcell"
|
||||
"maunium.net/go/gomatrix"
|
||||
@ -123,7 +124,7 @@ func (view *MainView) HandleCommand(room, command string, args []string) {
|
||||
view.matrix.client.LeaveRoom(room)
|
||||
case "/join":
|
||||
if len(args) == 0 {
|
||||
view.Append(room, "*", "Usage: /join <room>")
|
||||
view.AddMessage(room, "*", "Usage: /join <room>", time.Now())
|
||||
break
|
||||
}
|
||||
mxid := args[0]
|
||||
@ -206,10 +207,10 @@ func (view *MainView) SetTyping(room string, users []string) {
|
||||
}
|
||||
}
|
||||
|
||||
func (view *MainView) Append(room, sender, message string) {
|
||||
func (view *MainView) AddMessage(room, sender, message string, timestamp time.Time) {
|
||||
roomView, ok := view.rooms[room]
|
||||
if ok {
|
||||
roomView.AddMessage(sender, message)
|
||||
roomView.AddMessage(sender, message, timestamp)
|
||||
view.parent.Render()
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user