Change DMChatRoom#Participants to a map instead of a slice

This commit is contained in:
Alessio 2023-06-22 18:01:27 -03:00
parent 3f1fcf6bcd
commit 1538605e23
2 changed files with 5 additions and 5 deletions

View File

@ -74,7 +74,7 @@ func TestParseAPIDMConversation(t *testing.T) {
assert.Len(chat_room.Participants, 2) assert.Len(chat_room.Participants, 2)
p1 := chat_room.Participants[0] p1 := chat_room.Participants[1458284524761075714]
assert.Equal(UserID(1458284524761075714), p1.UserID) assert.Equal(UserID(1458284524761075714), p1.UserID)
assert.Equal(DMMessageID(1665936253483614212), p1.LastReadEventID) assert.Equal(DMMessageID(1665936253483614212), p1.LastReadEventID)
assert.True(p1.IsChatSettingsValid) assert.True(p1.IsChatSettingsValid)
@ -84,7 +84,7 @@ func TestParseAPIDMConversation(t *testing.T) {
assert.False(p1.IsMuted) assert.False(p1.IsMuted)
assert.Equal("AT_END", p1.Status) assert.Equal("AT_END", p1.Status)
p2 := chat_room.Participants[1] p2 := chat_room.Participants[1488963321701171204]
assert.Equal(UserID(1488963321701171204), p2.UserID) assert.Equal(UserID(1488963321701171204), p2.UserID)
assert.Equal(DMMessageID(1663623062195957773), p2.LastReadEventID) assert.Equal(DMMessageID(1663623062195957773), p2.LastReadEventID)
assert.False(p2.IsChatSettingsValid) assert.False(p2.IsChatSettingsValid)

View File

@ -22,7 +22,7 @@ type DMChatRoom struct {
LastMessagedAt Timestamp `db:"last_messaged_at"` LastMessagedAt Timestamp `db:"last_messaged_at"`
IsNSFW bool `db:"is_nsfw"` IsNSFW bool `db:"is_nsfw"`
Participants []DMChatParticipant Participants map[UserID]DMChatParticipant
} }
func ParseAPIDMChatRoom(api_room APIDMConversation) DMChatRoom { func ParseAPIDMChatRoom(api_room APIDMConversation) DMChatRoom {
@ -32,7 +32,7 @@ func ParseAPIDMChatRoom(api_room APIDMConversation) DMChatRoom {
ret.LastMessagedAt = TimestampFromUnix(int64(api_room.SortTimestamp)) ret.LastMessagedAt = TimestampFromUnix(int64(api_room.SortTimestamp))
ret.IsNSFW = api_room.NSFW ret.IsNSFW = api_room.NSFW
ret.Participants = []DMChatParticipant{} ret.Participants = make(map[UserID]DMChatParticipant)
for _, api_participant := range api_room.Participants { for _, api_participant := range api_room.Participants {
participant := DMChatParticipant{} participant := DMChatParticipant{}
participant.UserID = UserID(api_participant.UserID) participant.UserID = UserID(api_participant.UserID)
@ -48,7 +48,7 @@ func ParseAPIDMChatRoom(api_room APIDMConversation) DMChatRoom {
participant.Status = api_room.Status participant.Status = api_room.Status
participant.IsChatSettingsValid = true participant.IsChatSettingsValid = true
} }
ret.Participants = append(ret.Participants, participant) ret.Participants[participant.UserID] = participant
} }
return ret return ret
} }