File size: 1,319 Bytes
1e92f2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package mockslack

import (
	"context"
	"net/http"
)

// ConversationsInfo returns information about a conversation.
func (st *API) ConversationsInfo(ctx context.Context, id string) (*Channel, error) {
	err := checkPermission(ctx, "bot", "channels:read", "groups:read", "im:read", "mpim:read")
	if err != nil {
		return nil, err
	}

	st.mx.Lock()
	defer st.mx.Unlock()

	ch := st.channels[id]
	if ch == nil {
		return nil, &response{Err: "channel_not_found"}
	}

	if hasScope(ctx, "bot") {
		return &ch.Channel, nil
	}

	if ch.IsGroup {
		err = checkPermission(ctx, "groups:read")
	} else {
		err = checkPermission(ctx, "channels:read")
	}
	if err != nil {
		return nil, err
	}

	if ch.IsGroup && !contains(ch.Users, userID(ctx)) {
		// user is not a member of the group
		return nil, &response{Err: "channel_not_found"}
	}

	return &ch.Channel, nil
}

// ServeConversationsInfo serves a request to the `conversations.info` API call.
//
// https://api.slack.com/methods/conversations.info
func (s *Server) ServeConversationsInfo(w http.ResponseWriter, req *http.Request) {
	ch, err := s.API().ConversationsInfo(req.Context(), req.FormValue("channel"))
	if respondErr(w, err) {
		return
	}

	var resp struct {
		response
		Channel *Channel `json:"channel"`
	}
	resp.OK = true
	resp.Channel = ch

	respondWith(w, resp)
}