<commit_before>package types

import (
	"encoding/json"
	"strconv"
	"time"
)

const (
	EventTypeCreate      = "m.room.create"
	EventTypeName        = "m.room.name"
	EventTypeTopic       = "m.room.topic"
	EventTypeAliases     = "m.room.aliases"
	EventTypeJoinRules   = "m.room.join_rules"
	EventTypeMembership  = "m.room.member"
	EventTypePowerLevels = "m.room.power_levels"
)

type TypedContent interface {
	EventType() string
}

type Content interface{}

type Timestamp struct {
	time.Time
}

type Event interface {
	GetContent() interface{}
	GetEventType() string
	GetEventId() *EventId
	GetRoomId() *RoomId
}

type BaseEvent struct {
	EventType string `json:"type"`
}

func (e *BaseEvent) GetEventType() string {
	return e.EventType
}

type Message struct {
	BaseEvent
	Content   Content   `json:"content"`
	EventId   EventId   `json:"event_id"`
	RoomId    RoomId    `json:"room_id"`
	UserId    UserId    `json:"user_id"`
	Timestamp Timestamp `json:"origin_server_ts"`
}

func (e *Message) GetContent() interface{} {
	return e.Content
}

func (e *Message) GetEventId() *EventId {
	return &e.EventId
}

func (e *Message) GetRoomId() *RoomId {
	return &e.RoomId
}

type PresenceEvent struct {
	BaseEvent
	Content User `json:"content"`
}

func (e *PresenceEvent) GetContent() interface{} {
	return e.Content
}

func (e *PresenceEvent) GetEventId() *EventId {
	return nil
}

func (e *PresenceEvent) GetRoomId() *RoomId {
	return nil
}

type TypingEventContent struct {
	UserIds []UserId `json:"user_ids"`
}

type TypingEvent struct {
	BaseEvent
	Content TypingEventContent `json:"content"`
	RoomId  RoomId             `json:"room_id"`
}

func (e *TypingEvent) GetContent() interface{} {
	return e.Content
}

func (e *TypingEvent) GetEventId() *EventId {
	return nil
}

func (e *TypingEvent) GetRoomId() *RoomId {
	return &e.RoomId
}

type OldState State

type State struct {
	Message
	StateKey string    `json:"state_key"`
	OldState *OldState `json:"prev_content"`
}

func (e *OldState) MarshalJSON() ([]byte, error) {
	if e == nil {
		return []byte("null"), nil
	}
	return json.Marshal(e.Content)
}

func (ts Timestamp) MarshalJSON() ([]byte, error) {
	ms := ts.UnixNano() / int64(time.Millisecond)
	return []byte(strconv.FormatInt(ms, 10)), nil<commit_msg>types/events: added GetUserId to Event interface<commit_after>package types

import (
	"encoding/json"
	"strconv"
	"time"
)

const (
	EventTypeCreate      = "m.room.create"
	EventTypeName        = "m.room.name"
	EventTypeTopic       = "m.room.topic"
	EventTypeAliases     = "m.room.aliases"
	EventTypeJoinRules   = "m.room.join_rules"
	EventTypeMembership  = "m.room.member"
	EventTypePowerLevels = "m.room.power_levels"
)

type TypedContent interface {
	EventType() string
}

type Content interface{}

type Timestamp struct {
	time.Time
}

type Event interface {
	GetContent() interface{}
	GetEventType() string
	GetEventId() *EventId
	GetRoomId() *RoomId
	GetUserId() *UserId
}

type BaseEvent struct {
	EventType string `json:"type"`
}

func (e *BaseEvent) GetEventType() string {
	return e.EventType
}

type Message struct {
	BaseEvent
	Content   Content   `json:"content"`
	EventId   EventId   `json:"event_id"`
	RoomId    RoomId    `json:"room_id"`
	UserId    UserId    `json:"user_id"`
	Timestamp Timestamp `json:"origin_server_ts"`
}

func (e *Message) GetContent() interface{} {
	return e.Content
}

func (e *Message) GetEventId() *EventId {
	return &e.EventId
}

func (e *Message) GetRoomId() *RoomId {
	return &e.RoomId
}

func (e *Message) GetUserId() *UserId {
	return &e.UserId
}

type PresenceEvent struct {
	BaseEvent
	Content User `json:"content"`
}

func (e *PresenceEvent) GetContent() interface{} {
	return e.Content
}

func (e *PresenceEvent) GetEventId() *EventId {
	return nil
}

func (e *PresenceEvent) GetRoomId() *RoomId {
	return nil
}

func (e *PresenceEvent) GetUserId() *UserId {
	return &e.Content.UserId
}

type TypingEventContent struct {
	UserIds []UserId `json:"user_ids"`
}

type TypingEvent struct {
	BaseEvent
	Content TypingEventContent `json:"content"`
	RoomId  RoomId             `json:"room_id"`
}

func (e *TypingEvent) GetContent() interface{} {
	return e.Content
}

func (e *TypingEvent) GetEventId() *EventId {
	return nil
}

func (e *TypingEvent) GetRoomId() *RoomId {
	return &e.RoomId
}

func (e *TypingEvent) GetUserId() *UserId {
	return nil
}

type OldState State

type State struct {
	Message
	StateKey string    `json:"state_key"`
	OldState *OldState `json:"prev_content"`
}

func (e *OldState) MarshalJSON() ([]byte, error) {
	if e == nil {
		return []byte("null"), nil
	}
	return json.Marshal(e.Content)
}

func (ts Timestamp) MarshalJSON() ([]byte, error) {
	ms := ts.UnixNano() / int64(time.Millisecond)
	return []byte(strconv.FormatInt(ms, 10)), nil
{'fraction_non_alphanumeric': 0.13053515215110179, 'fraction_numerical': 0.0016789087093389296, 'mean_word_length': 4.355056179775281, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6294875', 'n_tokens_mistral': 1715, 'n_tokens_neox': 1717, 'n_words': 431}