mirror of
https://github.com/jech/galene.git
synced 2024-11-22 16:45:58 +01:00
Add id to chat messages.
This commit is contained in:
parent
4fb0b3334a
commit
eb72069c9b
5 changed files with 34 additions and 22 deletions
|
@ -74,11 +74,12 @@ func (err ProtocolError) Error() string {
|
||||||
}
|
}
|
||||||
|
|
||||||
type ChatHistoryEntry struct {
|
type ChatHistoryEntry struct {
|
||||||
Id string
|
Id string
|
||||||
User *string
|
Source string
|
||||||
Time time.Time
|
User *string
|
||||||
Kind string
|
Time time.Time
|
||||||
Value interface{}
|
Kind string
|
||||||
|
Value interface{}
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -804,7 +805,7 @@ func (g *Group) ClearChatHistory() {
|
||||||
g.history = nil
|
g.history = nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *Group) AddToChatHistory(id string, user *string, time time.Time, kind string, value interface{}) {
|
func (g *Group) AddToChatHistory(id, source string, user *string, time time.Time, kind string, value interface{}) {
|
||||||
g.mu.Lock()
|
g.mu.Lock()
|
||||||
defer g.mu.Unlock()
|
defer g.mu.Unlock()
|
||||||
|
|
||||||
|
@ -813,7 +814,7 @@ func (g *Group) AddToChatHistory(id string, user *string, time time.Time, kind s
|
||||||
g.history = g.history[:len(g.history)-1]
|
g.history = g.history[:len(g.history)-1]
|
||||||
}
|
}
|
||||||
g.history = append(g.history,
|
g.history = append(g.history,
|
||||||
ChatHistoryEntry{Id: id, User: user, Time: time, Kind: kind, Value: value},
|
ChatHistoryEntry{Id: id, Source: source, User: user, Time: time, Kind: kind, Value: value},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -54,7 +54,7 @@ func TestChatHistory(t *testing.T) {
|
||||||
}
|
}
|
||||||
user := "user"
|
user := "user"
|
||||||
for i := 0; i < 2*maxChatHistory; i++ {
|
for i := 0; i < 2*maxChatHistory; i++ {
|
||||||
g.AddToChatHistory("id", &user, time.Now(), "",
|
g.AddToChatHistory("id", "source", &user, time.Now(), "",
|
||||||
fmt.Sprintf("%v", i),
|
fmt.Sprintf("%v", i),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1197,7 +1197,8 @@ func handleAction(c *webClient, a any) error {
|
||||||
for _, m := range h {
|
for _, m := range h {
|
||||||
err := c.write(clientMessage{
|
err := c.write(clientMessage{
|
||||||
Type: "chathistory",
|
Type: "chathistory",
|
||||||
Source: m.Id,
|
Id: m.Id,
|
||||||
|
Source: m.Source,
|
||||||
Username: m.User,
|
Username: m.User,
|
||||||
Time: m.Time.Format(time.RFC3339),
|
Time: m.Time.Format(time.RFC3339),
|
||||||
Value: m.Value,
|
Value: m.Value,
|
||||||
|
@ -1575,17 +1576,25 @@ func handleClientMessage(c *webClient, m clientMessage) error {
|
||||||
return c.error(group.UserError("not authorised"))
|
return c.error(group.UserError("not authorised"))
|
||||||
}
|
}
|
||||||
|
|
||||||
now := time.Now()
|
id := m.Id
|
||||||
|
if m.Type == "chat" && m.Dest == "" && id == "" {
|
||||||
|
buf := make([]byte, 8)
|
||||||
|
crand.Read(buf)
|
||||||
|
id = base64.RawURLEncoding.EncodeToString(buf)
|
||||||
|
}
|
||||||
|
|
||||||
|
now := time.Now()
|
||||||
if m.Type == "chat" {
|
if m.Type == "chat" {
|
||||||
if m.Dest == "" {
|
if m.Dest == "" {
|
||||||
g.AddToChatHistory(
|
g.AddToChatHistory(
|
||||||
m.Source, m.Username, now, m.Kind, m.Value,
|
id, m.Source, m.Username,
|
||||||
|
now, m.Kind, m.Value,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
mm := clientMessage{
|
mm := clientMessage{
|
||||||
Type: m.Type,
|
Type: m.Type,
|
||||||
|
Id: id,
|
||||||
Source: m.Source,
|
Source: m.Source,
|
||||||
Dest: m.Dest,
|
Dest: m.Dest,
|
||||||
Username: m.Username,
|
Username: m.Username,
|
||||||
|
@ -1891,15 +1900,15 @@ func handleClientMessage(c *webClient, m clientMessage) error {
|
||||||
}
|
}
|
||||||
w, ok := d.(warner)
|
w, ok := d.(warner)
|
||||||
if ok {
|
if ok {
|
||||||
w.Warn(false, "Your IP address has been " +
|
w.Warn(false, "Your IP address has been "+
|
||||||
"communicated to user " +
|
"communicated to user "+
|
||||||
c.Username() + ".")
|
c.Username()+".")
|
||||||
}
|
}
|
||||||
c.write(clientMessage{
|
c.write(clientMessage{
|
||||||
Type: "usermessage",
|
Type: "usermessage",
|
||||||
Kind: "userinfo",
|
Kind: "userinfo",
|
||||||
Privileged: true,
|
Privileged: true,
|
||||||
Value: value,
|
Value: value,
|
||||||
})
|
})
|
||||||
case "kick":
|
case "kick":
|
||||||
if !member("op", c.permissions) {
|
if !member("op", c.permissions) {
|
||||||
|
|
|
@ -2958,7 +2958,7 @@ let lastMessage = {};
|
||||||
* @param {string} kind
|
* @param {string} kind
|
||||||
* @param {string|HTMLElement} message
|
* @param {string|HTMLElement} message
|
||||||
*/
|
*/
|
||||||
function addToChatbox(peerId, dest, nick, time, privileged, history, kind, message) {
|
function addToChatbox(id, peerId, dest, nick, time, privileged, history, kind, message) {
|
||||||
let row = document.createElement('div');
|
let row = document.createElement('div');
|
||||||
row.classList.add('message-row');
|
row.classList.add('message-row');
|
||||||
let container = document.createElement('div');
|
let container = document.createElement('div');
|
||||||
|
@ -2973,6 +2973,8 @@ function addToChatbox(peerId, dest, nick, time, privileged, history, kind, messa
|
||||||
if(dest)
|
if(dest)
|
||||||
container.classList.add('message-private');
|
container.classList.add('message-private');
|
||||||
|
|
||||||
|
if(id)
|
||||||
|
container.dataset.id = id;
|
||||||
if(peerId) {
|
if(peerId) {
|
||||||
container.dataset.peerId = peerId;
|
container.dataset.peerId = peerId;
|
||||||
container.dataset.username = nick;
|
container.dataset.username = nick;
|
||||||
|
@ -3093,7 +3095,7 @@ function chatMessageMenu(elt) {
|
||||||
* @param {string|HTMLElement} message
|
* @param {string|HTMLElement} message
|
||||||
*/
|
*/
|
||||||
function localMessage(message) {
|
function localMessage(message) {
|
||||||
return addToChatbox(null, null, null, new Date(), false, false, '', message);
|
return addToChatbox(null, null, null, null, new Date(), false, false, '', message);
|
||||||
}
|
}
|
||||||
|
|
||||||
function clearChat() {
|
function clearChat() {
|
||||||
|
@ -3473,7 +3475,7 @@ commands.msg = {
|
||||||
if(!id)
|
if(!id)
|
||||||
throw new Error(`Unknown user ${p[0]}`);
|
throw new Error(`Unknown user ${p[0]}`);
|
||||||
serverConnection.chat('', id, p[1]);
|
serverConnection.chat('', id, p[1]);
|
||||||
addToChatbox(serverConnection.id, id, serverConnection.username,
|
addToChatbox(serverConnection.id, null, id, serverConnection.username,
|
||||||
new Date(), false, false, '', p[1]);
|
new Date(), false, false, '', p[1]);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -212,7 +212,7 @@ function ServerConnection() {
|
||||||
/**
|
/**
|
||||||
* onchat is called whenever a new chat message is received.
|
* onchat is called whenever a new chat message is received.
|
||||||
*
|
*
|
||||||
* @type {(this: ServerConnection, id: string, dest: string, username: string, time: Date, privileged: boolean, history: boolean, kind: string, message: string) => void}
|
* @type {(this: ServerConnection, id: string, source: string, dest: string, username: string, time: Date, privileged: boolean, history: boolean, kind: string, message: string) => void}
|
||||||
*/
|
*/
|
||||||
this.onchat = null;
|
this.onchat = null;
|
||||||
/**
|
/**
|
||||||
|
@ -497,7 +497,7 @@ ServerConnection.prototype.connect = function(url) {
|
||||||
case 'chathistory':
|
case 'chathistory':
|
||||||
if(sc.onchat)
|
if(sc.onchat)
|
||||||
sc.onchat.call(
|
sc.onchat.call(
|
||||||
sc, m.source, m.dest, m.username, parseTime(m.time),
|
sc, m.id, m.source, m.dest, m.username, parseTime(m.time),
|
||||||
m.privileged, m.type === 'chathistory', m.kind,
|
m.privileged, m.type === 'chathistory', m.kind,
|
||||||
'' + m.value,
|
'' + m.value,
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in a new issue