aboutsummaryrefslogtreecommitdiff
path: root/matrix
diff options
context:
space:
mode:
Diffstat (limited to 'matrix')
-rw-r--r--matrix/matrix.go5
-rw-r--r--matrix/pushrules/ruleset.go9
-rw-r--r--matrix/rooms/member.go1
-rw-r--r--matrix/rooms/room.go13
-rw-r--r--matrix/sync.go2
5 files changed, 24 insertions, 6 deletions
diff --git a/matrix/matrix.go b/matrix/matrix.go
index b062057..8199449 100644
--- a/matrix/matrix.go
+++ b/matrix/matrix.go
@@ -263,9 +263,10 @@ func (c *Container) processOwnMembershipChange(evt *gomatrix.Event) {
if membership == prevMembership {
return
}
- if membership == "join" {
+ switch membership {
+ case "join":
c.ui.MainView().AddRoom(evt.RoomID)
- } else if membership == "leave" {
+ case "leave":
c.ui.MainView().RemoveRoom(evt.RoomID)
}
}
diff --git a/matrix/pushrules/ruleset.go b/matrix/pushrules/ruleset.go
index b533f94..f3026c8 100644
--- a/matrix/pushrules/ruleset.go
+++ b/matrix/pushrules/ruleset.go
@@ -39,6 +39,14 @@ type rawPushRuleset struct {
Underride PushRuleArray `json:"underride"`
}
+// UnmarshalJSON parses JSON into this PushRuleset.
+//
+// For override, sender and underride push rule arrays, the type is added
+// to each PushRule and the array is used as-is.
+//
+// For room and sender push rule arrays, the type is added to each PushRule
+// and the array is converted to a map with the rule ID as the key and the
+// PushRule as the value.
func (rs *PushRuleset) UnmarshalJSON(raw []byte) (err error) {
data := rawPushRuleset{}
err = json.Unmarshal(raw, &data)
@@ -54,6 +62,7 @@ func (rs *PushRuleset) UnmarshalJSON(raw []byte) (err error) {
return
}
+// MarshalJSON is the reverse of UnmarshalJSON()
func (rs *PushRuleset) MarshalJSON() ([]byte, error) {
data := rawPushRuleset{
Override: rs.Override,
diff --git a/matrix/rooms/member.go b/matrix/rooms/member.go
index 20c994b..8fd84e9 100644
--- a/matrix/rooms/member.go
+++ b/matrix/rooms/member.go
@@ -20,6 +20,7 @@ import (
"maunium.net/go/gomatrix"
)
+// Membership is an enum specifying the membership state of a room member.
type Membership string
// The allowed membership states as specified in spec section 10.5.5.
diff --git a/matrix/rooms/room.go b/matrix/rooms/room.go
index 56614de..c24b6db 100644
--- a/matrix/rooms/room.go
+++ b/matrix/rooms/room.go
@@ -34,17 +34,22 @@ type Room struct {
SessionUserID string
// MXID -> Member cache calculated from membership events.
memberCache map[string]*Member
- // The first non-SessionUserID member in the room. Calculated at the same time as memberCache.
+ // The first non-SessionUserID member in the room. Calculated at
+ // the same time as memberCache.
firstMemberCache string
- // The name of the room. Calculated from the state event name, canonical_alias or alias or the member cache.
+ // The name of the room. Calculated from the state event name,
+ // canonical_alias or alias or the member cache.
nameCache string
// The topic of the room. Directly fetched from the m.room.topic state event.
topicCache string
- // fetchHistoryLock is used to make sure multiple goroutines don't fetch history for this room at the same time.
+ // fetchHistoryLock is used to make sure multiple goroutines don't fetch
+ // history for this room at the same time.
fetchHistoryLock *sync.Mutex
}
+// LockHistory locks the history fetching mutex.
+// If the mutex is nil, it will be created.
func (room *Room) LockHistory() {
if room.fetchHistoryLock == nil {
room.fetchHistoryLock = &sync.Mutex{}
@@ -52,6 +57,8 @@ func (room *Room) LockHistory() {
room.fetchHistoryLock.Lock()
}
+// UnlockHistory unlocks the history fetching mutex.
+// If the mutex is nil, this does nothing.
func (room *Room) UnlockHistory() {
if room.fetchHistoryLock != nil {
room.fetchHistoryLock.Unlock()
diff --git a/matrix/sync.go b/matrix/sync.go
index a5f3b91..f78359c 100644
--- a/matrix/sync.go
+++ b/matrix/sync.go
@@ -49,7 +49,7 @@ func (s *GomuksSyncer) ProcessResponse(res *gomatrix.RespSync, since string) (er
if len(since) == 0 {
return
}
- // gdebug.Print("Processing sync response", since, res)
+ // debug.Print("Processing sync response", since, res)
defer func() {
if r := recover(); r != nil {