瀏覽代碼

fix #1409

Record INVITE in DM history for the benefit of offline always-on clients
tags/v2.5.0-rc1
Shivaram Lingamneni 3 年之前
父節點
當前提交
32bbde49a8
共有 4 個檔案被更改,包括 60 行新增32 行删除
  1. 15
    6
      irc/channel.go
  2. 36
    1
      irc/client.go
  3. 8
    25
      irc/handlers.go
  4. 1
    0
      irc/history/history.go

+ 15
- 6
irc/channel.go 查看文件

@@ -1507,24 +1507,33 @@ func (channel *Channel) Invite(invitee *Client, inviter *Client, rb *ResponseBuf
1507 1507
 		invitee.Invite(chcfname, createdAt)
1508 1508
 	}
1509 1509
 
1510
+	details := inviter.Details()
1511
+	tDetails := invitee.Details()
1512
+	tnick := invitee.Nick()
1513
+	message := utils.MakeMessage("")
1514
+	item := history.Item{
1515
+		Type:    history.Invite,
1516
+		Message: message,
1517
+		Params:  [1]string{chname},
1518
+	}
1519
+
1510 1520
 	for _, member := range channel.Members() {
1511 1521
 		if member == inviter || member == invitee || !channel.ClientIsAtLeast(member, modes.Halfop) {
1512 1522
 			continue
1513 1523
 		}
1514 1524
 		for _, session := range member.Sessions() {
1515 1525
 			if session.capabilities.Has(caps.InviteNotify) {
1516
-				session.Send(nil, inviter.NickMaskString(), "INVITE", invitee.Nick(), chname)
1526
+				session.sendFromClientInternal(false, message.Time, message.Msgid, details.nickMask, details.accountName, nil, "INVITE", tnick, chname)
1517 1527
 			}
1518 1528
 		}
1519 1529
 	}
1520 1530
 
1521
-	cnick := inviter.Nick()
1522
-	tnick := invitee.Nick()
1523
-	rb.Add(nil, inviter.server.name, RPL_INVITING, cnick, tnick, chname)
1524
-	invitee.Send(nil, inviter.NickMaskString(), "INVITE", tnick, chname)
1531
+	rb.Add(nil, inviter.server.name, RPL_INVITING, details.nick, tnick, chname)
1532
+	invitee.sendFromClientInternal(false, message.Time, message.Msgid, details.nickMask, details.accountName, nil, "INVITE", tnick, chname)
1525 1533
 	if away, awayMessage := invitee.Away(); away {
1526
-		rb.Add(nil, inviter.server.name, RPL_AWAY, cnick, tnick, awayMessage)
1534
+		rb.Add(nil, inviter.server.name, RPL_AWAY, details.nick, tnick, awayMessage)
1527 1535
 	}
1536
+	inviter.addHistoryItem(invitee, item, &details, &tDetails, channel.server.Config())
1528 1537
 }
1529 1538
 
1530 1539
 // Uninvite rescinds a channel invitation, if the inviter can do so.

+ 36
- 1
irc/client.go 查看文件

@@ -1055,6 +1055,13 @@ func (client *Client) replayPrivmsgHistory(rb *ResponseBuffer, items []history.I
1055 1055
 	for _, item := range items {
1056 1056
 		var command string
1057 1057
 		switch item.Type {
1058
+		case history.Invite:
1059
+			if hasEventPlayback {
1060
+				rb.AddFromClient(item.Message.Time, item.Message.Msgid, item.Nick, item.AccountName, nil, "INVITE", item.Params[0])
1061
+			} else {
1062
+				rb.AddFromClient(item.Message.Time, utils.MungeSecretToken(item.Message.Msgid), histservService.prefix, "*", nil, "PRIVMSG", fmt.Sprintf(client.t("%[1]s invited you to channel %[2]s"), stripMaskFromNick(item.Nick), item.Params[0]))
1063
+			}
1064
+			continue
1058 1065
 		case history.Privmsg:
1059 1066
 			command = "PRIVMSG"
1060 1067
 		case history.Notice:
@@ -1088,7 +1095,7 @@ func (client *Client) replayPrivmsgHistory(rb *ResponseBuffer, items []history.I
1088 1095
 
1089 1096
 	rb.EndNestedBatch(batchID)
1090 1097
 	if !complete {
1091
-		rb.Add(nil, "HistServ", "NOTICE", nick, client.t("Some additional message history may have been lost"))
1098
+		rb.Add(nil, histservService.prefix, "NOTICE", nick, client.t("Some additional message history may have been lost"))
1092 1099
 	}
1093 1100
 }
1094 1101
 
@@ -1862,6 +1869,34 @@ func (client *Client) historyStatus(config *Config) (status HistoryStatus, targe
1862 1869
 	return
1863 1870
 }
1864 1871
 
1872
+func (client *Client) addHistoryItem(target *Client, item history.Item, details, tDetails *ClientDetails, config *Config) (err error) {
1873
+	if !itemIsStorable(&item, config) {
1874
+		return
1875
+	}
1876
+
1877
+	item.Nick = details.nickMask
1878
+	item.AccountName = details.accountName
1879
+	targetedItem := item
1880
+	targetedItem.Params[0] = tDetails.nick
1881
+
1882
+	cStatus, _ := client.historyStatus(config)
1883
+	tStatus, _ := target.historyStatus(config)
1884
+	// add to ephemeral history
1885
+	if cStatus == HistoryEphemeral {
1886
+		targetedItem.CfCorrespondent = tDetails.nickCasefolded
1887
+		client.history.Add(targetedItem)
1888
+	}
1889
+	if tStatus == HistoryEphemeral && client != target {
1890
+		item.CfCorrespondent = details.nickCasefolded
1891
+		target.history.Add(item)
1892
+	}
1893
+	if cStatus == HistoryPersistent || tStatus == HistoryPersistent {
1894
+		targetedItem.CfCorrespondent = ""
1895
+		client.server.historyDB.AddDirectMessage(details.nickCasefolded, details.account, tDetails.nickCasefolded, tDetails.account, targetedItem)
1896
+	}
1897
+	return nil
1898
+}
1899
+
1865 1900
 func (client *Client) handleRegisterTimeout() {
1866 1901
 	client.Quit(fmt.Sprintf("Registration timeout: %v", RegisterTimeout), nil)
1867 1902
 	client.destroy(nil)

+ 8
- 25
irc/handlers.go 查看文件

@@ -2138,37 +2138,20 @@ func dispatchMessageToTarget(client *Client, tags map[string]string, histType hi
2138 2138
 			}
2139 2139
 		}
2140 2140
 
2141
+		if !allowedPlusR {
2142
+			return
2143
+		}
2144
+
2141 2145
 		config := server.Config()
2142 2146
 		if !config.History.Enabled {
2143 2147
 			return
2144 2148
 		}
2145 2149
 		item := history.Item{
2146
-			Type:        histType,
2147
-			Message:     message,
2148
-			Nick:        nickMaskString,
2149
-			AccountName: accountName,
2150
-			Tags:        tags,
2151
-		}
2152
-		if !itemIsStorable(&item, config) || !allowedPlusR {
2153
-			return
2154
-		}
2155
-		targetedItem := item
2156
-		targetedItem.Params[0] = tnick
2157
-		cStatus, _ := client.historyStatus(config)
2158
-		tStatus, _ := user.historyStatus(config)
2159
-		// add to ephemeral history
2160
-		if cStatus == HistoryEphemeral {
2161
-			targetedItem.CfCorrespondent = tDetails.nickCasefolded
2162
-			client.history.Add(targetedItem)
2163
-		}
2164
-		if tStatus == HistoryEphemeral && client != user {
2165
-			item.CfCorrespondent = details.nickCasefolded
2166
-			user.history.Add(item)
2167
-		}
2168
-		if cStatus == HistoryPersistent || tStatus == HistoryPersistent {
2169
-			targetedItem.CfCorrespondent = ""
2170
-			server.historyDB.AddDirectMessage(details.nickCasefolded, details.account, tDetails.nickCasefolded, tDetails.account, targetedItem)
2150
+			Type:    histType,
2151
+			Message: message,
2152
+			Tags:    tags,
2171 2153
 		}
2154
+		client.addHistoryItem(user, item, &details, &tDetails, config)
2172 2155
 	}
2173 2156
 }
2174 2157
 

+ 1
- 0
irc/history/history.go 查看文件

@@ -23,6 +23,7 @@ const (
23 23
 	Tagmsg
24 24
 	Nick
25 25
 	Topic
26
+	Invite
26 27
 )
27 28
 
28 29
 const (

Loading…
取消
儲存