Skip to content

Commit

Permalink
Adds User Status event type
Browse files Browse the repository at this point in the history
  • Loading branch information
wakumaku committed Feb 8, 2025
1 parent fbd8a95 commit 49cc54e
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ Check [/examples](examples) folder.
* UpdateMessageFlags: add, remove
* UserGroup: add, addmembers, addsubgroups, remove, removemembers, removesubgroups, update
* UserSettings: update
* UserStatus
* [x] UserStatus
* UserTopic
* WebReloadClient

Expand Down
30 changes: 30 additions & 0 deletions realtime/events/user_status.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package events

const UserStatusType EventType = "user_status"

type UserStatus struct {
ID int `json:"id"`
Type EventType `json:"type"`
UserStatusData
}

type UserStatusData struct {
Away bool `json:"away"`
EmojiCode string `json:"emoji_code"`
EmojiName string `json:"emoji_name"`
ReactionType string `json:"reaction_type"`
StatusText string `json:"status_text"`
UserID int `json:"user_id"`
}

func (e *UserStatus) EventID() int {
return e.ID
}

func (e *UserStatus) EventType() EventType {
return e.Type
}

func (e *UserStatus) EventOp() string {
return string(UserStatusType)
}
36 changes: 36 additions & 0 deletions realtime/events/user_status_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package events_test

import (
"encoding/json"
"testing"

"github.com/stretchr/testify/assert"
"github.com/wakumaku/go-zulip/realtime/events"
)

func TestUserStatus(t *testing.T) {
eventExample := `{
"away": true,
"emoji_code": "1f697",
"emoji_name": "car",
"id": 0,
"reaction_type": "unicode_emoji",
"status_text": "out to lunch",
"type": "user_status",
"user_id": 10
}`

v := events.UserStatus{}
err := json.Unmarshal([]byte(eventExample), &v)
assert.NoError(t, err)

assert.Equal(t, 0, v.EventID())
assert.Equal(t, events.UserStatusType, v.EventType())

assert.Equal(t, true, v.UserStatusData.Away)
assert.Equal(t, "1f697", v.UserStatusData.EmojiCode)
assert.Equal(t, "car", v.UserStatusData.EmojiName)
assert.Equal(t, "unicode_emoji", v.UserStatusData.ReactionType)
assert.Equal(t, "out to lunch", v.UserStatusData.StatusText)
assert.Equal(t, 10, v.UserStatusData.UserID)
}

0 comments on commit 49cc54e

Please sign in to comment.